MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / ParseAnyValue

Method ParseAnyValue

native/thirdpart/flatbuffers/idl_parser.cpp:1055–1180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053}
1054
1055CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
1056 size_t parent_fieldn,
1057 const StructDef *parent_struct_def,
1058 uoffset_t count, bool inside_vector) {
1059 switch (val.type.base_type) {
1060 case BASE_TYPE_UNION: {
1061 FLATBUFFERS_ASSERT(field);
1062 std::string constant;
1063 Vector<uint8_t> *vector_of_union_types = nullptr;
1064 // Find corresponding type field we may have already parsed.
1065 for (auto elem = field_stack_.rbegin() + count;
1066 elem != field_stack_.rbegin() + parent_fieldn + count; ++elem) {
1067 auto &type = elem->second->value.type;
1068 if (type.enum_def == val.type.enum_def) {
1069 if (inside_vector) {
1070 if (IsVector(type) && type.element == BASE_TYPE_UTYPE) {
1071 // Vector of union type field.
1072 uoffset_t offset;
1073 ECHECK(atot(elem->first.constant.c_str(), *this, &offset));
1074 vector_of_union_types = reinterpret_cast<Vector<uint8_t> *>(
1075 builder_.GetCurrentBufferPointer() + builder_.GetSize() -
1076 offset);
1077 break;
1078 }
1079 } else {
1080 if (type.base_type == BASE_TYPE_UTYPE) {
1081 // Union type field.
1082 constant = elem->first.constant;
1083 break;
1084 }
1085 }
1086 }
1087 }
1088 if (constant.empty() && !inside_vector) {
1089 // We haven't seen the type field yet. Sadly a lot of JSON writers
1090 // output these in alphabetical order, meaning it comes after this
1091 // value. So we scan past the value to find it, then come back here.
1092 // We currently don't do this for vectors of unions because the
1093 // scanning/serialization logic would get very complicated.
1094 auto type_name = field->name + UnionTypeFieldSuffix();
1095 FLATBUFFERS_ASSERT(parent_struct_def);
1096 auto type_field = parent_struct_def->fields.Lookup(type_name);
1097 FLATBUFFERS_ASSERT(type_field); // Guaranteed by ParseField().
1098 // Remember where we are in the source file, so we can come back here.
1099 auto backup = *static_cast<ParserState *>(this);
1100 ECHECK(SkipAnyJsonValue()); // The table.
1101 ECHECK(ParseComma());
1102 auto next_name = attribute_;
1103 if (Is(kTokenStringConstant)) {
1104 NEXT();
1105 } else {
1106 EXPECT(kTokenIdentifier);
1107 }
1108 if (next_name == type_name) {
1109 EXPECT(':');
1110 ParseDepthGuard depth_guard(this);
1111 ECHECK(depth_guard.Check());
1112 Value type_val = type_field->value;

Callers

nothing calls this directly

Calls 15

IsVectorFunction · 0.85
atotFunction · 0.85
UnionTypeFieldSuffixFunction · 0.85
ErrorFunction · 0.85
NumToStringFunction · 0.85
IsStringFunction · 0.85
NoErrorFunction · 0.85
emptyMethod · 0.80
ReverseLookupMethod · 0.80
VectorTypeMethod · 0.80
rbeginMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected