X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=codec%2Fmsg_codec.go;h=227764d0eb7760dddf748066a022c6d1517b3d23;hb=8d3131f90f71271835e5fed91831565797894614;hp=920366e66721bd99c41e2f46a2e9d3b585f87a82;hpb=ceed73403bdb61387d04be8b47183e9c4a970749;p=govpp.git diff --git a/codec/msg_codec.go b/codec/msg_codec.go index 920366e..227764d 100644 --- a/codec/msg_codec.go +++ b/codec/msg_codec.go @@ -15,6 +15,7 @@ package codec import ( + "encoding/binary" "errors" "fmt" @@ -23,28 +24,14 @@ import ( var DefaultCodec = new(MsgCodec) -// VppRequestHeader struct contains header fields implemented by all VPP requests. -type VppRequestHeader struct { - VlMsgID uint16 - ClientIndex uint32 - Context uint32 +func EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) { + return DefaultCodec.EncodeMsg(msg, msgID) } - -// VppReplyHeader struct contains header fields implemented by all VPP replies. -type VppReplyHeader struct { - VlMsgID uint16 - Context uint32 -} - -// VppEventHeader struct contains header fields implemented by all VPP events. -type VppEventHeader struct { - VlMsgID uint16 - ClientIndex uint32 +func DecodeMsg(data []byte, msg api.Message) (err error) { + return DefaultCodec.DecodeMsg(data, msg) } - -// VppOtherHeader struct contains header fields implemented by other VPP messages (not requests nor replies). -type VppOtherHeader struct { - VlMsgID uint16 +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 @@ -119,16 +106,12 @@ 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 order.Uint32(data[6:10]), nil + return binary.BigEndian.Uint32(data[6:10]), nil case api.ReplyMessage: - return order.Uint32(data[2:6]), nil + return binary.BigEndian.Uint32(data[2:6]), nil } return 0, nil