summaryrefslogtreecommitdiffstats
path: root/codec
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2018-08-23 22:51:56 +0200
committerOndrej Fabry <ofabry@cisco.com>2018-08-24 12:43:05 +0200
commit6b350c65fe0ec845cecf58bfb41ffc63dc9c04f7 (patch)
tree6255495854f43ec2f2d11f88990369aadb48db3f /codec
parent892683bef86cacc2ccda2b4df2b079171bd92164 (diff)
Simplify subscribing to events and fix events
- there is no need for sending subscription requests through channels, since all the messages are registered and no communication with VPP is needed Change-Id: Ibc29957be02a32e26309f66c369a071559b822a9 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'codec')
-rw-r--r--codec/msg_codec.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/codec/msg_codec.go b/codec/msg_codec.go
index 572e672..9d3f614 100644
--- a/codec/msg_codec.go
+++ b/codec/msg_codec.go
@@ -58,15 +58,19 @@ func (*MsgCodec) EncodeMsg(msg api.Message, msgID uint16) ([]byte, error) {
return nil, errors.New("nil message passed in")
}
- // encode message header
var header interface{}
+
+ // encode message header
switch msg.GetMessageType() {
case api.RequestMessage:
header = &VppRequestHeader{VlMsgID: msgID}
+
case api.ReplyMessage:
header = &VppReplyHeader{VlMsgID: msgID}
+
case api.EventMessage:
header = &VppEventHeader{VlMsgID: msgID}
+
default:
header = &VppOtherHeader{VlMsgID: msgID}
}
@@ -94,15 +98,19 @@ func (*MsgCodec) DecodeMsg(data []byte, msg api.Message) error {
return errors.New("nil message passed in")
}
- // check which header is expected
var header interface{}
+
+ // check which header is expected
switch msg.GetMessageType() {
case api.RequestMessage:
header = new(VppRequestHeader)
+
case api.ReplyMessage:
header = new(VppReplyHeader)
+
case api.EventMessage:
header = new(VppEventHeader)
+
default:
header = new(VppOtherHeader)
}
@@ -127,17 +135,19 @@ func (*MsgCodec) DecodeMsgContext(data []byte, msg api.Message) (uint32, error)
return 0, errors.New("nil message passed in")
}
+ var header interface{}
var getContext func() uint32
// check which header is expected
- var header interface{}
switch msg.GetMessageType() {
case api.RequestMessage:
header = new(VppRequestHeader)
getContext = func() uint32 { return header.(*VppRequestHeader).Context }
+
case api.ReplyMessage:
header = new(VppReplyHeader)
getContext = func() uint32 { return header.(*VppReplyHeader).Context }
+
default:
return 0, nil
}