aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/google/flatbuffers/go/lib.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-05-02 08:12:09 +0200
committerDmitry Vyukov <dvyukov@google.com>2024-05-03 14:25:58 +0000
commite0545e264c6343d00dc5fba031daaa4ed8688713 (patch)
tree9c67a7c2b85445449be348910a6767d42eeddd6d /vendor/github.com/google/flatbuffers/go/lib.go
parenta6197803d4d2b62b3d4cfecbc729fed31aec999d (diff)
go.mod: add github.com/google/flatbuffers
Diffstat (limited to 'vendor/github.com/google/flatbuffers/go/lib.go')
-rw-r--r--vendor/github.com/google/flatbuffers/go/lib.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/vendor/github.com/google/flatbuffers/go/lib.go b/vendor/github.com/google/flatbuffers/go/lib.go
new file mode 100644
index 000000000..a4e99de10
--- /dev/null
+++ b/vendor/github.com/google/flatbuffers/go/lib.go
@@ -0,0 +1,50 @@
+package flatbuffers
+
+// FlatBuffer is the interface that represents a flatbuffer.
+type FlatBuffer interface {
+ Table() Table
+ Init(buf []byte, i UOffsetT)
+}
+
+// GetRootAs is a generic helper to initialize a FlatBuffer with the provided buffer bytes and its data offset.
+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:])
+}
+
+// GetIndirectOffset retrives the relative offset in the provided buffer stored at `offset`.
+func GetIndirectOffset(buf []byte, offset UOffsetT) UOffsetT {
+ return offset + GetUOffsetT(buf[offset:])
+}
+
+// GetBufferIdentifier returns the file identifier as string
+func GetBufferIdentifier(buf []byte) string {
+ return string(buf[SizeUOffsetT:][:fileIdentifierLength])
+}
+
+// GetBufferIdentifier returns the file identifier as string for a size-prefixed buffer
+func GetSizePrefixedBufferIdentifier(buf []byte) string {
+ return string(buf[SizeUOffsetT+sizePrefixLength:][:fileIdentifierLength])
+}
+
+// BufferHasIdentifier checks if the identifier in a buffer has the expected value
+func BufferHasIdentifier(buf []byte, identifier string) bool {
+ return GetBufferIdentifier(buf) == identifier
+}
+
+// BufferHasIdentifier checks if the identifier in a buffer has the expected value for a size-prefixed buffer
+func SizePrefixedBufferHasIdentifier(buf []byte, identifier string) bool {
+ return GetSizePrefixedBufferIdentifier(buf) == identifier
+}