blob: 9a333ff04d8b8bcfc56c59be2d58f8be9cceb08a [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001package 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}
Austin Schuh272c6132020-11-14 16:37:52 -080014
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}