mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 22:44:12 +00:00
Support size-prefixed buffers and add tests for size-prefixed messages (#6232)
This commit is contained in:
12
go/lib.go
12
go/lib.go
@@ -11,3 +11,15 @@ func GetRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) {
|
||||
n := GetUOffsetT(buf[offset:])
|
||||
fb.Init(buf, n+offset)
|
||||
}
|
||||
|
||||
// GetSizePrefixedRootAs is a generic helper to initialize a FlatBuffer with the provided size-prefixed buffer
|
||||
// bytes and its data offset
|
||||
func GetSizePrefixedRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) {
|
||||
n := GetUOffsetT(buf[offset+sizePrefixLength:])
|
||||
fb.Init(buf, n+offset+sizePrefixLength)
|
||||
}
|
||||
|
||||
// GetSizePrefix reads the size from a size-prefixed flatbuffer
|
||||
func GetSizePrefix(buf []byte, offset UOffsetT) uint32 {
|
||||
return GetUint32(buf[offset:])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user