• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package flatbuffers
2
3// Codec implements gRPC-go Codec which is used to encode and decode messages.
4var Codec = "flatbuffers"
5
6// FlatbuffersCodec defines the interface gRPC uses to encode and decode messages.  Note
7// that implementations of this interface must be thread safe; a Codec's
8// methods can be called from concurrent goroutines.
9type FlatbuffersCodec struct{}
10
11// Marshal returns the wire format of v.
12func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
13	return v.(*Builder).FinishedBytes(), nil
14}
15
16// Unmarshal parses the wire format into v.
17func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
18	v.(flatbuffersInit).Init(data, GetUOffsetT(data))
19	return nil
20}
21
22// String  old gRPC Codec interface func
23func (FlatbuffersCodec) String() string {
24	return Codec
25}
26
27// Name returns the name of the Codec implementation. The returned string
28// will be used as part of content type in transmission.  The result must be
29// static; the result cannot change between calls.
30//
31// add Name() for ForceCodec interface
32func (FlatbuffersCodec) Name() string {
33	return Codec
34}
35
36type flatbuffersInit interface {
37	Init(data []byte, i UOffsetT)
38}
39