1 // Copyright (c) 2017 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
22 // GoVppAPIPackageIsVersionX is referenced from generated binapi files
23 // to assert that that code is compatible with this version of the GoVPP api package.
25 GoVppAPIPackageIsVersion1 = true
26 GoVppAPIPackageIsVersion2 = true
29 // MessageType represents the type of a VPP message derived from message header fields.
33 // RequestMessage represents a VPP request message
34 RequestMessage MessageType = iota
35 // ReplyMessage represents a VPP reply message
37 // EventMessage represents a VPP event message
39 // OtherMessage represents other VPP message
43 // Message is an interface that is implemented by all VPP Binary API messages generated by the binapigenerator.
44 type Message interface {
45 // GetMessageName returns the original VPP name of the message, as defined in the VPP API.
46 GetMessageName() string
48 // GetCrcString returns the string with CRC checksum of the message definition (the string represents a hexadecimal number).
51 // GetMessageType returns the type of the VPP message.
52 GetMessageType() MessageType
55 // DataType is an interface that is implemented by all VPP Binary API data types by the binapi_generator.
56 type DataType interface {
57 // GetTypeName returns the original VPP name of the data type, as defined in the VPP API.
62 registeredMessages = make(map[string]map[string]Message)
63 registeredMessageTypes = make(map[string]map[reflect.Type]string)
66 // RegisterMessage is called from generated code to register message.
67 func RegisterMessage(x Message, name string) {
68 binapiPath := path.Dir(reflect.TypeOf(x).Elem().PkgPath())
69 if _, ok := registeredMessages[binapiPath]; !ok {
70 registeredMessages[binapiPath] = make(map[string]Message)
71 registeredMessageTypes[binapiPath] = make(map[reflect.Type]string)
73 registeredMessages[binapiPath][x.GetMessageName()+"_"+x.GetCrcString()] = x
74 registeredMessageTypes[binapiPath][reflect.TypeOf(x)] = name
77 // GetRegisteredMessages returns list of all registered messages.
78 func GetRegisteredMessages() map[string]map[string]Message {
79 return registeredMessages
82 // GetRegisteredMessageTypes returns list of all registered message types.
83 func GetRegisteredMessageTypes() map[string]map[reflect.Type]string {
84 return registeredMessageTypes