diff options
author | 2020-12-01 13:57:29 +0100 | |
---|---|---|
committer | 2020-12-03 10:14:12 +0100 | |
commit | bcf3fbd21aa22d1546bc85ffb887ae5ba557808e (patch) | |
tree | 60668ecb3d0721bf33cfa1b37736a494f675ec4b /api | |
parent | 2b743eede78b6fed115421716888f80088edefdb (diff) |
Fixed incorrect message error in the stream API
The message package is passed to the stream object and
used to evaluate correct reply message type
Change-Id: I2c9844d6447d024af1693205efd5721e2f89f22d
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/binapi.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/api/binapi.go b/api/binapi.go index cb4ab85..1b07a7e 100644 --- a/api/binapi.go +++ b/api/binapi.go @@ -15,7 +15,7 @@ package api import ( - "fmt" + "path" "reflect" ) @@ -59,27 +59,27 @@ type DataType interface { } var ( - registeredMessageTypes = make(map[reflect.Type]string) - registeredMessages = make(map[string]Message) + registeredMessages = make(map[string]map[string]Message) + registeredMessageTypes = make(map[string]map[reflect.Type]string) ) // RegisterMessage is called from generated code to register message. func RegisterMessage(x Message, name string) { - 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)) + binapiPath := path.Dir(reflect.TypeOf(x).Elem().PkgPath()) + if _, ok := registeredMessages[binapiPath]; !ok { + registeredMessages[binapiPath] = make(map[string]Message) + registeredMessageTypes[binapiPath] = make(map[reflect.Type]string) } - registeredMessages[namecrc] = x - registeredMessageTypes[typ] = name + registeredMessages[binapiPath][x.GetMessageName()+"_"+x.GetCrcString()] = x + registeredMessageTypes[binapiPath][reflect.TypeOf(x)] = name } // GetRegisteredMessages returns list of all registered messages. -func GetRegisteredMessages() map[string]Message { +func GetRegisteredMessages() map[string]map[string]Message { return registeredMessages } // GetRegisteredMessageTypes returns list of all registered message types. -func GetRegisteredMessageTypes() map[reflect.Type]string { +func GetRegisteredMessageTypes() map[string]map[reflect.Type]string { return registeredMessageTypes } |