diff options
author | Vladimir Lavor <vlavor@cisco.com> | 2020-12-03 14:40:09 +0100 |
---|---|---|
committer | Vladimir Lavor <vlavor@cisco.com> | 2020-12-03 14:40:09 +0100 |
commit | 8d3131f90f71271835e5fed91831565797894614 (patch) | |
tree | c646a6353d9bfa4712b43fd279d3380bbc668b65 /codec | |
parent | bcf3fbd21aa22d1546bc85ffb887ae5ba557808e (diff) |
Decode message context using the message type only
In order to prevent potential future issues, the method
returning message based on its ID but ignoring its package
was optimized.
Change-Id: I12aa2b243f32f38cb3dbc7731613c7ed9fc66539
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'codec')
-rw-r--r-- | codec/msg_codec.go | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/codec/msg_codec.go b/codec/msg_codec.go index 6534e7d..227764d 100644 --- a/codec/msg_codec.go +++ b/codec/msg_codec.go @@ -30,8 +30,8 @@ func EncodeMsg(msg api.Message, msgID uint16) (data []byte, err error) { func DecodeMsg(data []byte, msg api.Message) (err error) { return DefaultCodec.DecodeMsg(data, msg) } -func DecodeMsgContext(data []byte, msg api.Message) (context uint32, err error) { - return DefaultCodec.DecodeMsgContext(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 @@ -106,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: |