MCPcopy Create free account
hub / github.com/catboost/catboost / ParseAnyValue

Method ParseAnyValue

contrib/libs/flatbuffers/src/idl_parser.cpp:1306–1436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1304}
1305
1306CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
1307 size_t parent_fieldn,
1308 const StructDef *parent_struct_def,
1309 size_t count, bool inside_vector) {
1310 switch (val.type.base_type) {
1311 case BASE_TYPE_UNION: {
1312 FLATBUFFERS_ASSERT(field);
1313 std::string constant;
1314 Vector<uint8_t> *vector_of_union_types = nullptr;
1315 // Find corresponding type field we may have already parsed.
1316 for (auto elem = field_stack_.rbegin() + count;
1317 elem != field_stack_.rbegin() + parent_fieldn + count; ++elem) {
1318 auto &type = elem->second->value.type;
1319 if (type.enum_def == val.type.enum_def) {
1320 if (inside_vector) {
1321 if (IsVector(type) && type.element == BASE_TYPE_UTYPE) {
1322 // Vector of union type field.
1323 uoffset_t offset;
1324 ECHECK(atot(elem->first.constant.c_str(), *this, &offset));
1325 vector_of_union_types = reinterpret_cast<Vector<uint8_t> *>(
1326 builder_.GetCurrentBufferPointer() + builder_.GetSize() -
1327 offset);
1328 break;
1329 }
1330 } else {
1331 if (type.base_type == BASE_TYPE_UTYPE) {
1332 // Union type field.
1333 constant = elem->first.constant;
1334 break;
1335 }
1336 }
1337 }
1338 }
1339 if (constant.empty() && !inside_vector) {
1340 // We haven't seen the type field yet. Sadly a lot of JSON writers
1341 // output these in alphabetical order, meaning it comes after this
1342 // value. So we scan past the value to find it, then come back here.
1343 // We currently don't do this for vectors of unions because the
1344 // scanning/serialization logic would get very complicated.
1345 auto type_name = field->name + UnionTypeFieldSuffix();
1346 FLATBUFFERS_ASSERT(parent_struct_def);
1347 auto type_field = parent_struct_def->fields.Lookup(type_name);
1348 FLATBUFFERS_ASSERT(type_field); // Guaranteed by ParseField().
1349 // Remember where we are in the source file, so we can come back here.
1350 auto backup = *static_cast<ParserState *>(this);
1351 ECHECK(SkipAnyJsonValue()); // The table.
1352 ECHECK(ParseComma());
1353 auto next_name = attribute_;
1354 if (Is(kTokenStringConstant)) {
1355 NEXT();
1356 } else {
1357 EXPECT(kTokenIdentifier);
1358 }
1359 if (next_name == type_name) {
1360 EXPECT(':');
1361 ParseDepthGuard depth_guard(this);
1362 ECHECK(depth_guard.Check());
1363 Value type_val = type_field->value;

Callers

nothing calls this directly

Calls 15

atotFunction · 0.85
UnionTypeFieldSuffixFunction · 0.85
ParseTableClass · 0.85
NumToStringFunction · 0.85
ParseArrayFunction · 0.85
NoErrorFunction · 0.85
ReverseLookupMethod · 0.80
ClearOffsetsMethod · 0.80
IsVectorFunction · 0.70
ErrorFunction · 0.70
IsFunction · 0.50

Tested by

no test coverage detected