From 58da9ac6e691a8c660eb8ca838a154e11da0db68 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Wed, 22 Jul 2020 04:40:55 +0200 Subject: Fix binapigen decoding and minor improvements - fixed allocating byte slices before copying decoded data - simplified encoding functions - several minor improvements Change-Id: I6669424b89eb86333805cb1b57e4551169980cc2 Signed-off-by: Ondrej Fabry --- binapigen/gen_helpers.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'binapigen/gen_helpers.go') diff --git a/binapigen/gen_helpers.go b/binapigen/gen_helpers.go index a22f1c6..5eafc76 100644 --- a/binapigen/gen_helpers.go +++ b/binapigen/gen_helpers.go @@ -25,7 +25,7 @@ const ( stringsPkg = GoImportPath("strings") ) -func generateIPConversion(g *GenFile, structName string, ipv int) { +func genIPConversion(g *GenFile, structName string, ipv int) { // ParseIPXAddress method g.P("func Parse", structName, "(s string) (", structName, ", error) {") if ipv == 4 { @@ -77,7 +77,7 @@ func generateIPConversion(g *GenFile, structName string, ipv int) { g.P() } -func generateAddressConversion(g *GenFile, structName string) { +func genAddressConversion(g *GenFile, structName string) { // ParseAddress method g.P("func Parse", structName, "(s string) (", structName, ", error) {") g.P(" ip := ", netPkg.Ident("ParseIP"), "(s)") @@ -132,7 +132,7 @@ func generateAddressConversion(g *GenFile, structName string) { g.P() } -func generateIPPrefixConversion(g *GenFile, structName string, ipv int) { +func genIPPrefixConversion(g *GenFile, structName string, ipv int) { // ParsePrefix method g.P("func Parse", structName, "(s string) (prefix ", structName, ", err error) {") g.P(" hasPrefix := ", stringsPkg.Ident("Contains"), "(s, \"/\")") @@ -211,7 +211,7 @@ func generateIPPrefixConversion(g *GenFile, structName string, ipv int) { g.P() } -func generatePrefixConversion(g *GenFile, structName string) { +func genPrefixConversion(g *GenFile, structName string) { // ParsePrefix method g.P("func Parse", structName, "(ip string) (prefix ", structName, ", err error) {") g.P(" hasPrefix := ", stringsPkg.Ident("Contains"), "(ip, \"/\")") @@ -276,7 +276,7 @@ func generatePrefixConversion(g *GenFile, structName string) { g.P() } -func generateAddressWithPrefixConversion(g *GenFile, structName string) { +func genAddressWithPrefixConversion(g *GenFile, structName string) { // ParseAddressWithPrefix method g.P("func Parse", structName, "(s string) (", structName, ", error) {") g.P(" prefix, err := ParsePrefix(s)") @@ -308,7 +308,7 @@ func generateAddressWithPrefixConversion(g *GenFile, structName string) { g.P() } -func generateMacAddressConversion(g *GenFile, structName string) { +func genMacAddressConversion(g *GenFile, structName string) { // ParseMAC method g.P("func Parse", structName, "(s string) (", structName, ", error) {") g.P(" var macaddr ", structName) -- cgit 1.2.3-korg