summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-11-15 12:33:28 +0100
committerOndrej Fabry <ofabry@cisco.com>2019-11-15 12:33:28 +0100
commite45d8802fd8de3602db630d75b370ff804000da9 (patch)
tree8803fe98338b4ed196d4c8881624c7ba869b9e53 /api
parent2f75863ba9bff2d2f3488b70e441b5eefc91dfd2 (diff)
Improve compatibility checking
- added CompatibilityError to api package to represent error with list of incompatible messages - added UnknownMsgError to adapter package to represent error for unknown message - added list of registered message types Change-Id: I2623b45135521d52612ba91e4605fc064a7fc76e Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'api')
-rw-r--r--api/binapi.go36
1 files changed, 30 insertions, 6 deletions
diff --git a/api/binapi.go b/api/binapi.go
index 6495d0d..d933612 100644
--- a/api/binapi.go
+++ b/api/binapi.go
@@ -15,6 +15,8 @@
package api
import (
+ "fmt"
+ "reflect"
"time"
)
@@ -115,15 +117,32 @@ type SubscriptionCtx interface {
Unsubscribe() error
}
-var registeredMessages = make(map[string]Message)
+// CompatibilityError is the error type usually returned by CheckCompatibility
+// method of Channel. It describes all of the incompatible messages.
+type CompatibilityError struct {
+ // IncompatibleMessages is the list of all messages
+ // that failed compatibility check.
+ IncompatibleMessages []string
+}
+
+func (c *CompatibilityError) Error() string {
+ return fmt.Sprintf("%d incompatible messages: %v", len(c.IncompatibleMessages), c.IncompatibleMessages)
+}
+
+var (
+ registeredMessageTypes = make(map[reflect.Type]string)
+ registeredMessages = make(map[string]Message)
+)
// RegisterMessage is called from generated code to register message.
func RegisterMessage(x Message, name string) {
- name = x.GetMessageName() + "_" + x.GetCrcString()
- /*if _, ok := registeredMessages[name]; ok {
- panic(fmt.Errorf("govpp: duplicate message registered: %s (%s)", name, x.GetCrcString()))
- }*/
- registeredMessages[name] = x
+ typ := reflect.TypeOf(x)
+ namecrc := x.GetMessageName() + "_" + x.GetCrcString()
+ if _, ok := registeredMessageTypes[typ]; ok {
+ panic(fmt.Errorf("govpp: message type %v already registered as %s (%s)", typ, name, namecrc))
+ }
+ registeredMessages[namecrc] = x
+ registeredMessageTypes[typ] = name
}
// GetRegisteredMessages returns list of all registered messages.
@@ -131,6 +150,11 @@ func GetRegisteredMessages() map[string]Message {
return registeredMessages
}
+// GetRegisteredMessageTypes returns list of all registered message types.
+func GetRegisteredMessageTypes() map[reflect.Type]string {
+ return registeredMessageTypes
+}
+
// GoVppAPIPackageIsVersion1 is referenced from generated binapi files
// to assert that that code is compatible with this version of the GoVPP api package.
const GoVppAPIPackageIsVersion1 = true