diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 14:39:23 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-10 16:06:35 +0200 |
commit | f3cc1373423b8bab3e2c364318d7e0857e79098a (patch) | |
tree | 1d5d5dbe070e0a73b17061dcdf5a3d7760784ea9 /xC-gen-proto-go.awk | |
parent | 8c8e06b0157c97ee1771f848ed363c6a0ed398be (diff) | |
download | xK-f3cc1373423b8bab3e2c364318d7e0857e79098a.tar.gz xK-f3cc1373423b8bab3e2c364318d7e0857e79098a.tar.xz xK-f3cc1373423b8bab3e2c364318d7e0857e79098a.zip |
xC-gen-proto: reduce enums to single bytes
That's already way more than we can possibly use.
Diffstat (limited to 'xC-gen-proto-go.awk')
-rw-r--r-- | xC-gen-proto-go.awk | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/xC-gen-proto-go.awk b/xC-gen-proto-go.awk index 1a64eb8..4220ccc 100644 --- a/xC-gen-proto-go.awk +++ b/xC-gen-proto-go.awk @@ -161,7 +161,7 @@ function codegen_begin() { print "\tvar n int64" print "\tif err := json.Unmarshal(data, &n); err != nil {" print "\t\treturn 0, err" - print "\t} else if n > math.MaxInt32 || n < math.MinInt32 {" + print "\t} else if n > math.MaxInt8 || n < math.MinInt8 {" print "\t\treturn 0, errors.New(`integer out of range`)" print "\t} else {" print "\t\treturn n, nil" @@ -191,7 +191,7 @@ function codegen_enum_value(name, subname, value, cg, goname) { function codegen_enum(name, cg, gotype, fields) { gotype = PrefixCamel name - print "type " gotype " int" + print "type " gotype " int8" print "" print "const (" @@ -239,12 +239,10 @@ function codegen_enum(name, cg, gotype, fields) { # XXX: This should also check if it isn't out-of-range for any reason, # but our usage of sprintf() stands in the way a bit. - CodegenSerialize[name] = \ - "\tdata = binary.BigEndian.AppendUint32(data, uint32(%s))\n" + CodegenSerialize[name] = "\tdata = append(data, uint8(%s))\n" CodegenDeserialize[name] = \ - "\tif len(data) >= 4 {\n" \ - "\t\t%s = " gotype "(int32(binary.BigEndian.Uint32(data)))\n" \ - "\t\tdata = data[4:]\n" \ + "\tif len(data) >= 1 {\n" \ + "\t\t%s, data = " gotype "(data[0]), data[1:]\n" \ "\t} else {\n" \ "\t\treturn nil, false\n" \ "\t}\n" |