aboutsummaryrefslogtreecommitdiff
path: root/xC-gen-proto-go.awk
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-15 05:11:41 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-15 05:12:07 +0200
commite87cc90b5e20ba90d4f5c9ea349d9cf41b5ae58c (patch)
tree934ac7da2aa356e5ec68b763507f1af969b87bd5 /xC-gen-proto-go.awk
parent98b0a4ef3d06fd4bc46809f0cb0f19f1bd205802 (diff)
downloadxK-e87cc90b5e20ba90d4f5c9ea349d9cf41b5ae58c.tar.gz
xK-e87cc90b5e20ba90d4f5c9ea349d9cf41b5ae58c.tar.xz
xK-e87cc90b5e20ba90d4f5c9ea349d9cf41b5ae58c.zip
xP: improve comments in protocol code generator
Diffstat (limited to 'xC-gen-proto-go.awk')
-rw-r--r--xC-gen-proto-go.awk10
1 files changed, 5 insertions, 5 deletions
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" \