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

Method ParseVector

native/thirdpart/flatbuffers/idl_parser.cpp:1512–1617  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1510}
1511
1512CheckedError Parser::ParseVector(const Type &type, uoffset_t *ovalue,
1513 FieldDef *field, size_t fieldn) {
1514 uoffset_t count = 0;
1515 auto err = ParseVectorDelimiters(count, [&](uoffset_t &) -> CheckedError {
1516 Value val;
1517 val.type = type;
1518 ECHECK(ParseAnyValue(val, field, fieldn, nullptr, count, true));
1519 field_stack_.push_back(std::make_pair(val, nullptr));
1520 return NoError();
1521 });
1522 ECHECK(err);
1523
1524 const size_t len = count * InlineSize(type) / InlineAlignment(type);
1525 const size_t elemsize = InlineAlignment(type);
1526 const auto force_align = field->attributes.Lookup("force_align");
1527 if (force_align) {
1528 size_t align;
1529 ECHECK(ParseAlignAttribute(force_align->constant, 1, &align));
1530 if (align > 1) { builder_.ForceVectorAlignment(len, elemsize, align); }
1531 }
1532
1533 builder_.StartVector(len, elemsize);
1534 for (uoffset_t i = 0; i < count; i++) {
1535 // start at the back, since we're building the data backwards.
1536 auto &val = field_stack_.back().first;
1537 switch (val.type.base_type) {
1538 // clang-format off
1539 #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE,...) \
1540 case BASE_TYPE_ ## ENUM: \
1541 if (IsStruct(val.type)) SerializeStruct(*val.type.struct_def, val); \
1542 else { \
1543 CTYPE elem; \
1544 ECHECK(atot(val.constant.c_str(), *this, &elem)); \
1545 builder_.PushElement(elem); \
1546 } \
1547 break;
1548 FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
1549 #undef FLATBUFFERS_TD
1550 // clang-format on
1551 }
1552 field_stack_.pop_back();
1553 }
1554
1555 builder_.ClearOffsets();
1556 *ovalue = builder_.EndVector(count);
1557
1558 if (type.base_type == BASE_TYPE_STRUCT && type.struct_def->has_key) {
1559 // We should sort this vector. Find the key first.
1560 const FieldDef *key = nullptr;
1561 for (auto it = type.struct_def->fields.vec.begin();
1562 it != type.struct_def->fields.vec.end(); ++it) {
1563 if ((*it)->key) {
1564 key = (*it);
1565 break;
1566 }
1567 }
1568 FLATBUFFERS_ASSERT(key);
1569 // Now sort it.

Callers

nothing calls this directly

Calls 15

NoErrorFunction · 0.85
InlineAlignmentFunction · 0.85
CompareSerializedScalarsFunction · 0.85
CompareTablesByStringKeyFunction · 0.85
CompareTablesByScalarKeyFunction · 0.85
push_backMethod · 0.80
pop_backMethod · 0.80
InlineSizeFunction · 0.70
swapFunction · 0.70
LookupMethod · 0.45
StartVectorMethod · 0.45
EndVectorMethod · 0.45

Tested by

no test coverage detected