import (
"errors"
"fmt"
- "reflect"
"sync/atomic"
"time"
return
}
- msg, err := c.getMessageByID(msgID)
+ msgType, name, crc, err := c.getMessageDataByID(msgID)
if err != nil {
log.Warnln(err)
return
// - replies that don't have context as first field (comes as zero)
// - events that don't have context at all (comes as non zero)
//
- context, err := c.codec.DecodeMsgContext(data, msg)
+ context, err := c.codec.DecodeMsgContext(data, msgType)
if err != nil {
log.WithField("msg_id", msgID).Warnf("Unable to decode message context: %v", err)
return
chanID, isMulti, seqNum := unpackRequestContext(context)
if log.Level == logger.DebugLevel { // for performance reasons - logrus does some processing even if debugs are disabled
- msg = reflect.New(reflect.TypeOf(msg).Elem()).Interface().(api.Message)
-
- // decode the message
- if err = c.codec.DecodeMsg(data, msg); err != nil {
- err = fmt.Errorf("decoding message failed: %w", err)
- return
- }
-
log.WithFields(logger.Fields{
"context": context,
"msg_id": msgID,
"channel": chanID,
"is_multi": isMulti,
"seq_num": seqNum,
- "msg_crc": msg.GetCrcString(),
- }).Debugf("<-- govpp RECEIVE: %s %+v", msg.GetMessageName(), msg)
+ "msg_crc": crc,
+ }).Debugf("<-- govpp RECEIVE: %s", name)
}
if context == 0 || c.isNotificationMessage(msgID) {
return 1
}
-// Returns first message from any package where the message ID matches
-// Note: the msg is further used only for its MessageType which is not
-// affected by the message's package
-func (c *Connection) getMessageByID(msgID uint16) (msg api.Message, err error) {
- var ok bool
+// Returns message data based on the message ID not depending on the message path
+func (c *Connection) getMessageDataByID(msgID uint16) (typ api.MessageType, name, crc string, err error) {
for _, msgs := range c.msgMapByPath {
- if msg, ok = msgs[msgID]; ok {
- break
+ if msg, ok := msgs[msgID]; ok {
+ return msg.GetMessageType(), msg.GetMessageName(), msg.GetCrcString(), nil
}
}
- if !ok {
- return nil, fmt.Errorf("unknown message received, ID: %d", msgID)
- }
- return msg, nil
+ return typ, name, crc, fmt.Errorf("unknown message received, ID: %d", msgID)
}