summaryrefslogtreecommitdiffstats
path: root/cmd/binapi-generator/generate.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-01-31 08:23:02 +0100
committerOndrej Fabry <ofabry@cisco.com>2019-01-31 08:23:02 +0100
commit6476a2b64a2e1ea6c0d695127d726a348cc5c99b (patch)
tree49909ae9800e9eb9af64731141dc899accf5d2d6 /cmd/binapi-generator/generate.go
parent2323d3ffe6e66ea7ffa40be232aa54c1d24c8651 (diff)
Generator improvements
- all objects are now sorted alphabetically for more consistent output - unions now have constructor generated - log level for warnings was changed to debug - GetAllMessages renamed to GetRegisteredMessages Change-Id: I976453004a2fd8b6cb95ca0acfcef56913bf8d38 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd/binapi-generator/generate.go')
-rw-r--r--cmd/binapi-generator/generate.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/cmd/binapi-generator/generate.go b/cmd/binapi-generator/generate.go
index e165c42..48c3a41 100644
--- a/cmd/binapi-generator/generate.go
+++ b/cmd/binapi-generator/generate.go
@@ -93,9 +93,9 @@ func generatePackage(ctx *context, w *bufio.Writer) error {
// generate services
if len(ctx.packageData.Services) > 0 {
generateServices(ctx, w, ctx.packageData.Services)
- }
- // TODO: generate implementation for Services interface
+ // TODO: generate implementation for Services interface
+ }
// generate enums
if len(ctx.packageData.Enums) > 0 {
@@ -140,16 +140,15 @@ func generatePackage(ctx *context, w *bufio.Writer) error {
for _, msg := range ctx.packageData.Messages {
generateMessage(ctx, w, &msg)
}
- }
- // generate message registrations
- fmt.Fprintln(w)
- fmt.Fprintln(w, "func init() {")
- for _, msg := range ctx.packageData.Messages {
- name := camelCaseName(msg.Name)
- fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n", name, ctx.moduleName+"."+name)
+ // generate message registrations
+ fmt.Fprintln(w, "func init() {")
+ for _, msg := range ctx.packageData.Messages {
+ name := camelCaseName(msg.Name)
+ fmt.Fprintf(w, "\tapi.RegisterMessage((*%s)(nil), \"%s\")\n", name, ctx.moduleName+"."+name)
+ }
+ fmt.Fprintln(w, "}")
}
- fmt.Fprintln(w, "}")
// flush the data:
if err := w.Flush(); err != nil {
@@ -181,13 +180,13 @@ func generateHeader(ctx *context, w io.Writer) {
fmt.Fprintf(w, "\t%3d %s\n", num, obj)
}
}
- printObjNum("message", len(ctx.packageData.Messages))
- printObjNum("type", len(ctx.packageData.Types))
- printObjNum("alias", len(ctx.packageData.Aliases))
+
+ printObjNum("service", len(ctx.packageData.Services))
printObjNum("enum", len(ctx.packageData.Enums))
+ printObjNum("alias", len(ctx.packageData.Aliases))
+ printObjNum("type", len(ctx.packageData.Types))
printObjNum("union", len(ctx.packageData.Unions))
- printObjNum("service", len(ctx.packageData.Services))
- fmt.Fprintln(w)
+ printObjNum("message", len(ctx.packageData.Messages))
fmt.Fprintln(w, "*/")
fmt.Fprintf(w, "package %s\n", ctx.packageName)
fmt.Fprintln(w)
@@ -416,6 +415,10 @@ func (u *%[1]s) String() string {
func generateUnionGetterSetter(w io.Writer, structName string, getterField, getterStruct string) {
fmt.Fprintf(w, `
+func %[1]s%[2]s(a %[3]s) (u %[1]s) {
+ u.Set%[2]s(a)
+ return
+}
func (u *%[1]s) Set%[2]s(a %[3]s) {
var b = new(bytes.Buffer)
if err := struc.Pack(b, &a); err != nil {
@@ -530,6 +533,8 @@ func generateMessage(ctx *context, w io.Writer, msg *Message) {
// generate message type getter method
generateMessageTypeGetter(w, name, msgType)
+
+ fmt.Fprintln(w)
}
// generateField writes generated code for the field into w