X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=codec%2Fmsg_codec.go;h=227764d0eb7760dddf748066a022c6d1517b3d23;hb=8d3131f90f71271835e5fed91831565797894614;hp=68cf3b19607764c013e43cbda3d808cbd031eca4;hpb=d1f24d37bd447b64e402298bb8eb2479681facf9;p=govpp.git diff --git a/codec/msg_codec.go b/codec/msg_codec.go index 68cf3b1..227764d 100644 --- a/codec/msg_codec.go +++ b/codec/msg_codec.go @@ -24,6 +24,16 @@ import ( var DefaultCodec = new(MsgCodec) +func EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) { + return DefaultCodec.EncodeMsg(msg, msgID) +} +func DecodeMsg(data []byte, msg api.Message) (err error) { + return DefaultCodec.DecodeMsg(data, msg) +} +func DecodeMsgContext(data []byte, msgType api.MessageType) (context uint32, err error) { + return DefaultCodec.DecodeMsgContext(data, msgType) +} + // MsgCodec provides encoding and decoding functionality of `api.Message` structs into/from // binary format as accepted by VPP. type MsgCodec struct{} @@ -96,12 +106,8 @@ func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) (err error) { return nil } -func (*MsgCodec) DecodeMsgContext(data []byte, msg api.Message) (context uint32, err error) { - if msg == nil { - return 0, errors.New("nil message passed in") - } - - switch msg.GetMessageType() { +func (*MsgCodec) DecodeMsgContext(data []byte, msgType api.MessageType) (context uint32, err error) { + switch msgType { case api.RequestMessage: return binary.BigEndian.Uint32(data[6:10]), nil case api.ReplyMessage: