aboutsummaryrefslogtreecommitdiffstats
path: root/binapigen/types.go
diff options
context:
space:
mode:
authorVladimir Lavor <vlavor@cisco.com>2020-07-01 12:18:54 +0200
committerVladimir Lavor <vlavor@cisco.com>2020-07-02 15:23:07 +0200
commitc7ae74a95d1bd6fefcbb061f5f045c60c11e32fc (patch)
treef04013af76e1e3c38266cc2606312cd0c9f443d3 /binapigen/types.go
parentdf67791c6ffc96331f75aec7d3addfe2efca7739 (diff)
Binary API generator improvements
* Many aliases removed, aliased types reference original types via import instead * Added various helper methods for simpler conversion between go and vpp types Change-Id: I7999ac8d524cece4da03e6447b13421659765095 Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'binapigen/types.go')
-rw-r--r--binapigen/types.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/binapigen/types.go b/binapigen/types.go
index 0dbbeb1..96ae870 100644
--- a/binapigen/types.go
+++ b/binapigen/types.go
@@ -15,6 +15,7 @@
package binapigen
import (
+ "fmt"
"strings"
"github.com/sirupsen/logrus"
@@ -213,14 +214,23 @@ func getActualType(file *File, typ string) (actual string) {
return typ
}
-// convertToGoType translates the VPP binary API type into Go type
+// convertToGoType translates the VPP binary API type into Go type.
+// Imported types are with import prefix.
func convertToGoType(file *File, binapiType string) (typ string) {
if t, ok := binapiTypes[binapiType]; ok {
// basic types
typ = t
} else if r, ok := file.refmap[binapiType]; ok {
// specific types (enums/types/unions)
+ var prefix string
typ = camelCaseName(r)
+ // look in imports using name and type name eventually
+ if imp, ok := file.imports[typ]; ok {
+ prefix = fmt.Sprintf("%s.", imp)
+ } else if imp, ok := file.imports[fromApiType(binapiType)]; ok {
+ prefix = fmt.Sprintf("%s.", imp)
+ }
+ typ = fmt.Sprintf("%s%s", prefix, typ)
} else {
switch binapiType {
case "bool", "string":