Add a generic way to deserialize a flatbuffer in Go.

Similar to what protobufs does with its `Message` interface, introduce here such interface and create a generic `GetRootAs` method to deserialize a flatbuffer.
This commit is contained in:
gonzaloserrano
2016-07-07 12:46:39 +02:00
parent b36bd67b39
commit 199a49b5b3
9 changed files with 236 additions and 140 deletions

13
go/lib.go Normal file
View File

@@ -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)
}