Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame^] | 1 | package flatbuffers |
| 2 | |
| 3 | // Codec implements gRPC-go Codec which is used to encode and decode messages. |
| 4 | var Codec = "flatbuffers" |
| 5 | |
| 6 | type FlatbuffersCodec struct{} |
| 7 | |
| 8 | func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) { |
| 9 | return v.(*Builder).FinishedBytes(), nil |
| 10 | } |
| 11 | |
| 12 | func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error { |
| 13 | v.(flatbuffersInit).Init(data, GetUOffsetT(data)) |
| 14 | return nil |
| 15 | } |
| 16 | |
| 17 | func (FlatbuffersCodec) String() string { |
| 18 | return Codec |
| 19 | } |
| 20 | |
| 21 | type flatbuffersInit interface { |
| 22 | Init(data []byte, i UOffsetT) |
| 23 | } |