diff --git a/xC-gen-proto-go.awk b/xC-gen-proto-go.awk index 48371eb..477a471 100644 --- a/xC-gen-proto-go.awk +++ b/xC-gen-proto-go.awk @@ -17,7 +17,6 @@ function define_sint(size, shortname, gotype) { CodegenAppendJSON[shortname] = \ "\tb = strconv.AppendInt(b, int64(%s), 10)\n" - if (size == 8) { CodegenSerialize[shortname] = "\tdata = append(data, uint8(%s))\n" CodegenDeserialize[shortname] = \ @@ -41,14 +40,14 @@ function define_sint(size, shortname, gotype) { } function define_uint(size, shortname, gotype) { + # Both []byte and []uint8 luckily marshal as base64-encoded JSON strings, + # so there's no need to rename the type as an exception. shortname = "u" size gotype = "uint" size define_internal(shortname, gotype) CodegenAppendJSON[shortname] = \ "\tb = strconv.AppendUint(b, uint64(%s), 10)\n" - - # Both byte and uint8 luckily marshal as base64-encoded JSON strings. if (size == 8) { CodegenSerialize[shortname] = "\tdata = append(data, %s)\n" CodegenDeserialize[shortname] = \ @@ -266,6 +265,7 @@ function codegen_marshal(type, f, marshal) { if (CodegenAppendJSON[type]) return sprintf(CodegenAppendJSON[type], f) + # Complex types are json.Marshalers, there's no need to json.Marshal(&f). if (CodegenIsMarshaler[type]) marshal = f ".MarshalJSON()" else @@ -282,8 +282,6 @@ function codegen_marshal(type, f, marshal) { function codegen_struct_field_marshal(d, cg, camel, f, marshal) { camel = snaketocamel(d["name"]) f = "s." camel - - # Complex types are json.Marshalers, there's no need to json.Marshal(&f). if (!d["isarray"]) { append(cg, "marshal", "\tb = append(b, `,\"" decapitalize(camel) "\":`...)\n" \ @@ -291,6 +289,8 @@ function codegen_struct_field_marshal(d, cg, camel, f, marshal) { return } + # Note that we do not produce `null` for nil slices, unlike encoding/json. + # And arrays never get deserialized as such. if (d["type"] == "u8") { append(cg, "marshal", "\tb = append(b, `,\"" decapitalize(camel) "\":\"`...)\n" \