summaryrefslogtreecommitdiff
path: root/go
diff options
context:
space:
mode:
authorRobert <me@rwinslow.com>2016-12-07 11:17:55 -0800
committerGitHub <noreply@github.com>2016-12-07 11:17:55 -0800
commit92a6ae93faab4d903c06065d245fc139721d6fe5 (patch)
treed6d52da2aaf326a12e5c47473d295ab6d3ca3bd9 /go
parenta31ddd2bb38f719996137c9c35bc702f2abaefa5 (diff)
parent199a49b5b3ec090f229258ac78fedc842ac9f07d (diff)
downloadflatbuffers-92a6ae93faab4d903c06065d245fc139721d6fe5.tar.gz
flatbuffers-92a6ae93faab4d903c06065d245fc139721d6fe5.tar.bz2
flatbuffers-92a6ae93faab4d903c06065d245fc139721d6fe5.zip
Merge pull request #3977 from gonzaloserrano/feature/go-generic-deserialitzation
Add a generic way to deserialize a flatbuffer in Go.
Diffstat (limited to 'go')
-rw-r--r--go/lib.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/go/lib.go b/go/lib.go
new file mode 100644
index 00000000..adfce52e
--- /dev/null
+++ b/go/lib.go
@@ -0,0 +1,13 @@
+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)
+}