json: fix #1751; support unsigned integers

pull/1755/head
Robin Martijn 2019-08-26 17:01:23 +02:00 committed by Alexander Medvednikov
parent f34d14d901
commit 5df31c16f7
2 changed files with 47 additions and 1 deletions

View File

@ -124,7 +124,8 @@ string res = tos2("");
fn is_js_prim(typ string) bool {
return typ == 'int' || typ == 'string' ||
typ == 'bool' || typ == 'f32' || typ == 'f64' ||
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64'
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64' ||
typ == 'u8' || typ == 'u16' || typ == 'u32' || typ == 'u64'
}
fn (p mut Parser) decode_array(array_type string) string {

View File

@ -49,6 +49,34 @@ fn jsdecode_i64(root *C.cJSON) i64 {
return i64(root.valuedouble) //i64 is double in C
}
fn jsdecode_u8(root *C.cJSON) u8 {
if isnil(root) {
return u8(0)
}
return u8(root.valueint)
}
fn jsdecode_u16(root *C.cJSON) u16 {
if isnil(root) {
return u16(0)
}
return u16(root.valueint)
}
fn jsdecode_u32(root *C.cJSON) u32 {
if isnil(root) {
return u32(0)
}
return u32(root.valueint)
}
fn jsdecode_u64(root *C.cJSON) u64 {
if isnil(root) {
return u64(0)
}
return u64(root.valueint)
}
fn jsdecode_f32(root *C.cJSON) f32 {
if isnil(root) {
return f32(0)
@ -95,6 +123,7 @@ fn jsencode_i8(val i8) *C.cJSON {
fn jsencode_i16(val i16) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_i32(val i32) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
@ -103,6 +132,22 @@ fn jsencode_i64(val i64) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_u8(val u8) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_u16(val u16) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_u32(val u32) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_u64(val u64) *C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn jsencode_f32(val f32) *C.cJSON {
return C.cJSON_CreateNumber(val)
}