|
|
@ -3119,6 +3119,7 @@ static upb_MessageValue jsondec_bool(jsondec* d, const upb_FieldDef* f) { |
|
|
|
/* Composite types (array/message/map) ****************************************/ |
|
|
|
/* Composite types (array/message/map) ****************************************/ |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; |
|
|
|
upb_Array* arr = upb_Message_Mutable(msg, f, d->arena).array; |
|
|
|
|
|
|
|
|
|
|
|
jsondec_arrstart(d); |
|
|
|
jsondec_arrstart(d); |
|
|
@ -3132,6 +3133,7 @@ static void jsondec_array(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; |
|
|
|
upb_Map* map = upb_Message_Mutable(msg, f, d->arena).map; |
|
|
|
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); |
|
|
|
const upb_MessageDef* entry = upb_FieldDef_MessageSubDef(f); |
|
|
|
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); |
|
|
|
const upb_FieldDef* key_f = upb_MessageDef_FindFieldByNumber(entry, 1); |
|
|
@ -3153,6 +3155,7 @@ static void jsondec_map(jsondec* d, upb_Message* msg, const upb_FieldDef* f) { |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_tomsg(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_tomsg(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { |
|
|
|
if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { |
|
|
|
jsondec_object(d, msg, m); |
|
|
|
jsondec_object(d, msg, m); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -3173,6 +3176,7 @@ static upb_MessageValue jsondec_msg(jsondec* d, const upb_FieldDef* f) { |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_field(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_field(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_StringView name; |
|
|
|
upb_StringView name; |
|
|
|
const upb_FieldDef* f; |
|
|
|
const upb_FieldDef* f; |
|
|
|
const upb_FieldDef* preserved; |
|
|
|
const upb_FieldDef* preserved; |
|
|
@ -3238,6 +3242,7 @@ static void jsondec_field(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_object(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_object(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
jsondec_objstart(d); |
|
|
|
jsondec_objstart(d); |
|
|
|
while (jsondec_objnext(d)) { |
|
|
|
while (jsondec_objnext(d)) { |
|
|
|
jsondec_field(d, msg, m); |
|
|
|
jsondec_field(d, msg, m); |
|
|
@ -3338,6 +3343,7 @@ static int64_t jsondec_unixtime(int y, int m, int d, int h, int min, int s) { |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_timestamp(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_timestamp(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_MessageValue seconds; |
|
|
|
upb_MessageValue seconds; |
|
|
|
upb_MessageValue nanos; |
|
|
|
upb_MessageValue nanos; |
|
|
|
upb_StringView str = jsondec_string(d); |
|
|
|
upb_StringView str = jsondec_string(d); |
|
|
@ -3403,6 +3409,7 @@ malformed: |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_duration(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_duration(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_MessageValue seconds; |
|
|
|
upb_MessageValue seconds; |
|
|
|
upb_MessageValue nanos; |
|
|
|
upb_MessageValue nanos; |
|
|
|
upb_StringView str = jsondec_string(d); |
|
|
|
upb_StringView str = jsondec_string(d); |
|
|
@ -3435,6 +3442,7 @@ static void jsondec_duration(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_listvalue(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_listvalue(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_FieldDef* values_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); |
|
|
|
const upb_MessageDef* value_m = upb_FieldDef_MessageSubDef(values_f); |
|
|
|
const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); |
|
|
|
const upb_MiniTable* value_layout = upb_MessageDef_MiniTable(value_m); |
|
|
@ -3453,6 +3461,7 @@ static void jsondec_listvalue(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_struct(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_struct(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_FieldDef* fields_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); |
|
|
|
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(fields_f); |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(entry_m, 2); |
|
|
@ -3475,6 +3484,7 @@ static void jsondec_struct(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_wellknownvalue(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
upb_MessageValue val; |
|
|
|
upb_MessageValue val; |
|
|
|
const upb_FieldDef* f; |
|
|
|
const upb_FieldDef* f; |
|
|
|
upb_Message* submsg; |
|
|
|
upb_Message* submsg; |
|
|
@ -3563,6 +3573,7 @@ static upb_StringView jsondec_mask(jsondec* d, const char* buf, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_fieldmask(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_fieldmask(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
/* repeated string paths = 1; */ |
|
|
|
/* repeated string paths = 1; */ |
|
|
|
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_FieldDef* paths_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; |
|
|
|
upb_Array* arr = upb_Message_Mutable(msg, paths_f, d->arena).array; |
|
|
@ -3586,6 +3597,7 @@ static void jsondec_fieldmask(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_anyfield(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_anyfield(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { |
|
|
|
if (upb_MessageDef_WellKnownType(m) == kUpb_WellKnown_Unspecified) { |
|
|
|
/* For regular types: {"@type": "[user type]", "f1": <V1>, "f2": <V2>}
|
|
|
|
/* For regular types: {"@type": "[user type]", "f1": <V1>, "f2": <V2>}
|
|
|
|
* where f1, f2, etc. are the normal fields of this type. */ |
|
|
|
* where f1, f2, etc. are the normal fields of this type. */ |
|
|
@ -3604,6 +3616,7 @@ static void jsondec_anyfield(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, |
|
|
|
static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_FieldDef* type_url_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_MessageDef* type_m; |
|
|
|
const upb_MessageDef* type_m; |
|
|
|
upb_StringView type_url = jsondec_string(d); |
|
|
|
upb_StringView type_url = jsondec_string(d); |
|
|
@ -3633,6 +3646,7 @@ static const upb_MessageDef* jsondec_typeurl(jsondec* d, upb_Message* msg, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { |
|
|
|
static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
/* string type_url = 1;
|
|
|
|
/* string type_url = 1;
|
|
|
|
* bytes value = 2; */ |
|
|
|
* bytes value = 2; */ |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 2); |
|
|
@ -3701,6 +3715,7 @@ static void jsondec_any(jsondec* d, upb_Message* msg, const upb_MessageDef* m) { |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_wrapper(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_wrapper(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
const upb_FieldDef* value_f = upb_MessageDef_FindFieldByNumber(m, 1); |
|
|
|
upb_JsonMessageValue val = jsondec_value(d, value_f); |
|
|
|
upb_JsonMessageValue val = jsondec_value(d, value_f); |
|
|
|
UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum.
|
|
|
|
UPB_ASSUME(val.ignore == false); // Wrapper cannot be an enum.
|
|
|
@ -3709,6 +3724,7 @@ static void jsondec_wrapper(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static void jsondec_wellknown(jsondec* d, upb_Message* msg, |
|
|
|
static void jsondec_wellknown(jsondec* d, upb_Message* msg, |
|
|
|
const upb_MessageDef* m) { |
|
|
|
const upb_MessageDef* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
switch (upb_MessageDef_WellKnownType(m)) { |
|
|
|
switch (upb_MessageDef_WellKnownType(m)) { |
|
|
|
case kUpb_WellKnown_Any: |
|
|
|
case kUpb_WellKnown_Any: |
|
|
|
jsondec_any(d, msg, m); |
|
|
|
jsondec_any(d, msg, m); |
|
|
@ -3749,6 +3765,7 @@ static void jsondec_wellknown(jsondec* d, upb_Message* msg, |
|
|
|
|
|
|
|
|
|
|
|
static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, |
|
|
|
static bool upb_JsonDecoder_Decode(jsondec* const d, upb_Message* const msg, |
|
|
|
const upb_MessageDef* const m) { |
|
|
|
const upb_MessageDef* const m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(msg)); |
|
|
|
if (UPB_SETJMP(d->err)) return false; |
|
|
|
if (UPB_SETJMP(d->err)) return false; |
|
|
|
|
|
|
|
|
|
|
|
jsondec_tomsg(d, msg, m); |
|
|
|
jsondec_tomsg(d, msg, m); |
|
|
@ -6041,6 +6058,7 @@ static upb_Map* upb_Message_Map_DeepClone(const upb_Map* map, |
|
|
|
const upb_MiniTableField* f, |
|
|
|
const upb_MiniTableField* f, |
|
|
|
upb_Message* clone, |
|
|
|
upb_Message* clone, |
|
|
|
upb_Arena* arena) { |
|
|
|
upb_Arena* arena) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(clone)); |
|
|
|
const upb_MiniTable* map_entry_table = |
|
|
|
const upb_MiniTable* map_entry_table = |
|
|
|
upb_MiniTable_MapEntrySubMessage(mini_table, f); |
|
|
|
upb_MiniTable_MapEntrySubMessage(mini_table, f); |
|
|
|
UPB_ASSERT(map_entry_table); |
|
|
|
UPB_ASSERT(map_entry_table); |
|
|
@ -6084,6 +6102,7 @@ static bool upb_Message_Array_DeepClone(const upb_Array* array, |
|
|
|
const upb_MiniTable* mini_table, |
|
|
|
const upb_MiniTable* mini_table, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
const upb_MiniTableField* field, |
|
|
|
upb_Message* clone, upb_Arena* arena) { |
|
|
|
upb_Message* clone, upb_Arena* arena) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(clone)); |
|
|
|
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); |
|
|
|
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(field); |
|
|
|
upb_Array* cloned_array = upb_Array_DeepClone( |
|
|
|
upb_Array* cloned_array = upb_Array_DeepClone( |
|
|
|
array, upb_MiniTableField_CType(field), |
|
|
|
array, upb_MiniTableField_CType(field), |
|
|
@ -6109,6 +6128,7 @@ static bool upb_Clone_ExtensionValue( |
|
|
|
upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, |
|
|
|
upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, |
|
|
|
const upb_MiniTable* mini_table, |
|
|
|
const upb_MiniTable* mini_table, |
|
|
|
upb_Arena* arena) { |
|
|
|
upb_Arena* arena) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(dst)); |
|
|
|
upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); |
|
|
|
upb_StringView empty_string = upb_StringView_FromDataAndSize(NULL, 0); |
|
|
|
// Only copy message area skipping upb_Message_Internal.
|
|
|
|
// Only copy message area skipping upb_Message_Internal.
|
|
|
|
memcpy(dst + 1, src + 1, mini_table->UPB_PRIVATE(size) - sizeof(upb_Message)); |
|
|
|
memcpy(dst + 1, src + 1, mini_table->UPB_PRIVATE(size) - sizeof(upb_Message)); |
|
|
@ -6215,6 +6235,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src, |
|
|
|
|
|
|
|
|
|
|
|
bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
bool upb_Message_DeepCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
const upb_MiniTable* mini_table, upb_Arena* arena) { |
|
|
|
const upb_MiniTable* mini_table, upb_Arena* arena) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(dst)); |
|
|
|
upb_Message_Clear(dst, mini_table); |
|
|
|
upb_Message_Clear(dst, mini_table); |
|
|
|
return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; |
|
|
|
return _upb_Message_Copy(dst, src, mini_table, arena) != NULL; |
|
|
|
} |
|
|
|
} |
|
|
@ -6231,6 +6252,7 @@ upb_Message* upb_Message_DeepClone(const upb_Message* msg, |
|
|
|
// Performs a shallow copy. TODO: Extend to handle unknown fields.
|
|
|
|
// Performs a shallow copy. TODO: Extend to handle unknown fields.
|
|
|
|
void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
void upb_Message_ShallowCopy(upb_Message* dst, const upb_Message* src, |
|
|
|
const upb_MiniTable* m) { |
|
|
|
const upb_MiniTable* m) { |
|
|
|
|
|
|
|
UPB_ASSERT(!upb_Message_IsFrozen(dst)); |
|
|
|
memcpy(dst, src, m->UPB_PRIVATE(size)); |
|
|
|
memcpy(dst, src, m->UPB_PRIVATE(size)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|