summaryrefslogtreecommitdiff
path: root/go/grpc.go
blob: e7dabd3c69a0de213ff26ddcd3f13e5ca4d17453 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package flatbuffers

// Codec implements gRPC-go Codec which is used to encode and decode messages.
var Codec = "flatbuffers"

type FlatbuffersCodec struct{}

func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
	return v.(*Builder).FinishedBytes(), nil
}

func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
	v.(flatbuffersInit).Init(data, GetUOffsetT(data))
	return nil
}

func (FlatbuffersCodec) String() string {
	return Codec
}

type flatbuffersInit interface {
	Init(data []byte, i UOffsetT)
}