From a763db9d1f035f6995e3444c7239d9cc24304d0a Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Tue, 21 Nov 2017 21:44:39 -0800 Subject: [PATCH] ttrpc: add required codec.go Signed-off-by: Stephen J Day --- codec.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 codec.go diff --git a/codec.go b/codec.go new file mode 100644 index 0000000..7956a72 --- /dev/null +++ b/codec.go @@ -0,0 +1,26 @@ +package ttrpc + +import ( + "github.com/gogo/protobuf/proto" + "github.com/pkg/errors" +) + +type codec struct{} + +func (c codec) Marshal(msg interface{}) ([]byte, error) { + switch v := msg.(type) { + case proto.Message: + return proto.Marshal(v) + default: + return nil, errors.Errorf("ttrpc: cannot marshal unknown type: %T", msg) + } +} + +func (c codec) Unmarshal(p []byte, msg interface{}) error { + switch v := msg.(type) { + case proto.Message: + return proto.Unmarshal(p, v) + default: + return errors.Errorf("ttrpc: cannot unmarshal into unknown type: %T", msg) + } +}