mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix struct field default value support (#14304)
This commit is contained in:
@ -71,6 +71,11 @@ fn decode_i64(root &C.cJSON) i64 {
|
||||
return i64(root.valuedouble) // i64 is double in C
|
||||
}
|
||||
|
||||
// TODO: remove when `byte` is removed
|
||||
fn decode_byte(root &C.cJSON) byte {
|
||||
return byte(decode_u8(root))
|
||||
}
|
||||
|
||||
fn decode_u8(root &C.cJSON) u8 {
|
||||
if isnil(root) {
|
||||
return u8(0)
|
||||
@ -132,8 +137,6 @@ fn decode_string(root &C.cJSON) string {
|
||||
if isnil(root.valuestring) {
|
||||
return ''
|
||||
}
|
||||
// println('decode string valuestring="$root.valuestring"')
|
||||
// return tos(root.valuestring, _strlen(root.valuestring))
|
||||
return unsafe { tos_clone(&u8(root.valuestring)) } // , _strlen(root.valuestring))
|
||||
}
|
||||
|
||||
@ -145,6 +148,7 @@ fn decode_bool(root &C.cJSON) bool {
|
||||
}
|
||||
|
||||
// ///////////////////
|
||||
|
||||
fn encode_int(val int) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
@ -161,6 +165,11 @@ fn encode_i64(val i64) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
// TODO: remove when `byte` is removed
|
||||
fn encode_byte(root byte) &C.cJSON {
|
||||
return encode_u8(u8(root))
|
||||
}
|
||||
|
||||
fn encode_u8(val u8) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
Reference in New Issue
Block a user