This gets the field offset for any of the functions below it, or 0 if the field was not present.
| 2678 | // This gets the field offset for any of the functions below it, or 0 |
| 2679 | // if the field was not present. |
| 2680 | voffset_t GetOptionalFieldOffset(voffset_t field) const { |
| 2681 | // The vtable offset is always at the start. |
| 2682 | auto vtable = GetVTable(); |
| 2683 | // The first element is the size of the vtable (fields + type id + itself). |
| 2684 | auto vtsize = ReadScalar<voffset_t>(vtable); |
| 2685 | // If the field we're accessing is outside the vtable, we're reading older |
| 2686 | // data, so it's the same as if the offset was 0 (not present). |
| 2687 | return field < vtsize ? ReadScalar<voffset_t>(vtable + field) : 0; |
| 2688 | } |
| 2689 | |
| 2690 | template<typename T> T GetField(voffset_t field, T defaultval) const { |
| 2691 | auto field_offset = GetOptionalFieldOffset(field); |