...
1
16
17 package ttrpc
18
19 import (
20 "fmt"
21
22 "google.golang.org/protobuf/proto"
23 )
24
25 type codec struct{}
26
27 func (c codec) Marshal(msg interface{}) ([]byte, error) {
28 switch v := msg.(type) {
29 case proto.Message:
30 return proto.Marshal(v)
31 default:
32 return nil, fmt.Errorf("ttrpc: cannot marshal unknown type: %T", msg)
33 }
34 }
35
36 func (c codec) Unmarshal(p []byte, msg interface{}) error {
37 switch v := msg.(type) {
38 case proto.Message:
39 return proto.Unmarshal(p, v)
40 default:
41 return fmt.Errorf("ttrpc: cannot unmarshal into unknown type: %T", msg)
42 }
43 }
44
View as plain text