| 1381 | } |
| 1382 | |
| 1383 | std::string BinaryAnnotator::BuildUnion(const uint64_t union_offset, |
| 1384 | const uint8_t realized_type, |
| 1385 | const reflection::Field *const field) { |
| 1386 | const reflection::Enum *next_enum = |
| 1387 | schema_->enums()->Get(field->type()->index()); |
| 1388 | |
| 1389 | const reflection::EnumVal *enum_val = next_enum->values()->Get(realized_type); |
| 1390 | |
| 1391 | if (ContainsSection(union_offset)) { return enum_val->name()->c_str(); } |
| 1392 | |
| 1393 | const reflection::Type *union_type = enum_val->union_type(); |
| 1394 | |
| 1395 | if (union_type->base_type() == reflection::BaseType::Obj) { |
| 1396 | const reflection::Object *object = |
| 1397 | schema_->objects()->Get(union_type->index()); |
| 1398 | |
| 1399 | if (object->is_struct()) { |
| 1400 | // Union of vectors point to a new Binary section |
| 1401 | std::vector<BinaryRegion> regions; |
| 1402 | |
| 1403 | BuildStruct(union_offset, regions, field->name()->c_str(), object); |
| 1404 | |
| 1405 | AddSection( |
| 1406 | union_offset, |
| 1407 | MakeBinarySection(std::string(object->name()->c_str()) + "." + |
| 1408 | field->name()->c_str(), |
| 1409 | BinarySectionType::Union, std::move(regions))); |
| 1410 | } else { |
| 1411 | BuildTable(union_offset, BinarySectionType::Table, object); |
| 1412 | } |
| 1413 | } |
| 1414 | // TODO(dbaileychess): handle the other union types. |
| 1415 | |
| 1416 | return enum_val->name()->c_str(); |
| 1417 | } |
| 1418 | |
| 1419 | void BinaryAnnotator::FixMissingRegions() { |
| 1420 | std::vector<BinaryRegion> regions_to_insert; |