vTableGet method

T vTableGet (BufferContext object, int offset, [ int field, [ T defaultValue ])

Read the value of the given field in the given object.

Implementation

T vTableGet(BufferContext object, int offset, int field, [T defaultValue]) {
  int vTableSOffset = object._getInt32(offset);
  int vTableOffset = offset - vTableSOffset;
  int vTableSize = object._getUint16(vTableOffset);
  int vTableFieldOffset = field;
  if (vTableFieldOffset < vTableSize) {
    int fieldOffsetInObject =
        object._getUint16(vTableOffset + vTableFieldOffset);
    if (fieldOffsetInObject != 0) {
      return read(object, offset + fieldOffsetInObject);
    }
  }
  return defaultValue;
}