Fixed incorrect message error in the stream API
[govpp.git] / core / request_handler.go
index fc704cb..f9d972a 100644 (file)
@@ -210,9 +210,9 @@ func (c *Connection) msgCallback(msgID uint16, data []byte) {
                return
        }
 
-       msg, ok := c.msgMap[msgID]
-       if !ok {
-               log.Warnf("Unknown message received, ID: %d", msgID)
+       msg, err := c.getMessageByID(msgID)
+       if err != nil {
+               log.Warnln(err)
                return
        }
 
@@ -419,3 +419,19 @@ func compareSeqNumbers(seqNum1, seqNum2 uint16) int {
        }
        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
+       for _, msgs := range c.msgMapByPath {
+               if msg, ok = msgs[msgID]; ok {
+                       break
+               }
+       }
+       if !ok {
+               return nil, fmt.Errorf("unknown message received, ID: %d", msgID)
+       }
+       return msg, nil
+}