implement Marshal/Unmarshal in codec interface

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-11-19 12:06:08 +03:00
parent 769c2d6a4b
commit ab3ad56df7

View File

@ -13,6 +13,22 @@ type Codec struct {
Conn io.ReadWriteCloser
}
func (c *Codec) Marshal(v interface{}) ([]byte, error) {
m, ok := v.(proto.Message)
if !ok {
return nil, codec.ErrInvalidMessage
}
return proto.Marshal(m)
}
func (c *Codec) Unmarshal(data []byte, v interface{}) error {
m, ok := v.(proto.Message)
if !ok {
return codec.ErrInvalidMessage
}
return proto.Unmarshal(data, m)
}
func (c *Codec) ReadHeader(m *codec.Message, t codec.MessageType) error {
return nil
}