1package flatbuffers 2 3// FlatBuffer is the interface that represents a flatbuffer. 4type FlatBuffer interface { 5 Table() Table 6 Init(buf []byte, i UOffsetT) 7} 8 9// GetRootAs is a generic helper to initialize a FlatBuffer with the provided buffer bytes and its data offset. 10func GetRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) { 11 n := GetUOffsetT(buf[offset:]) 12 fb.Init(buf, n+offset) 13} 14 15// GetSizePrefixedRootAs is a generic helper to initialize a FlatBuffer with the provided size-prefixed buffer 16// bytes and its data offset 17func GetSizePrefixedRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) { 18 n := GetUOffsetT(buf[offset+sizePrefixLength:]) 19 fb.Init(buf, n+offset+sizePrefixLength) 20} 21 22// GetSizePrefix reads the size from a size-prefixed flatbuffer 23func GetSizePrefix(buf []byte, offset UOffsetT) uint32 { 24 return GetUint32(buf[offset:]) 25} 26