Ronak Jain | a31ddd2 | 2016-12-06 02:50:38 +0530 | [diff] [blame] | 1 | package flatbuffers |
| 2 | |
wvo | 9ec9303 | 2016-12-21 21:57:10 +0000 | [diff] [blame] | 3 | // Codec implements gRPC-go Codec which is used to encode and decode messages. |
| 4 | var Codec = "flatbuffers" |
Ronak Jain | a31ddd2 | 2016-12-06 02:50:38 +0530 | [diff] [blame] | 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 | } |