generate: Use new option type

This commit is contained in:
Sasha Koshka 2025-01-22 17:40:43 -05:00
parent 62e3c7814c
commit 5d5ee9c644

View File

@ -222,6 +222,12 @@ func (this *Protocol) unmarshalMessage(out io.Writer, message Message) error {
fmt.Fprintf(out, fmt.Fprintf(out,
"func (msg *Message%s) UnmarshalBinary(buffer []byte) error {\n", "func (msg *Message%s) UnmarshalBinary(buffer []byte) error {\n",
message.Name) message.Name)
if len(message.Fields) < 1 {
fmt.Fprintf(out, "\t// no fields\n")
fmt.Fprintf(out, "\treturn nil\n")
fmt.Fprintf(out, "}\n\n")
return nil
}
fmt.Fprintf(out, "\tpairs, err := tape.DecodePairs(buffer)\n") fmt.Fprintf(out, "\tpairs, err := tape.DecodePairs(buffer)\n")
fmt.Fprintf(out, "\tif err != nil { return err }\n") fmt.Fprintf(out, "\tif err != nil { return err }\n")
requiredTotal := 0 requiredTotal := 0
@ -243,7 +249,7 @@ func (this *Protocol) unmarshalMessage(out io.Writer, message Message) error {
fmt.Fprintf(out, "\n") fmt.Fprintf(out, "\n")
fmt.Fprintf(out, "\t\t\tif err != nil { return err }\n") fmt.Fprintf(out, "\t\t\tif err != nil { return err }\n")
if field.Optional { if field.Optional {
fmt.Fprintf(out, "\t\t\tmsg.%s.Set(value)\n", field.Name) fmt.Fprintf(out, "\t\t\tmsg.%s = hopp.O(value)\n", field.Name)
} else { } else {
fmt.Fprintf(out, "\t\t\tmsg.%s = value\n", field.Name) fmt.Fprintf(out, "\t\t\tmsg.%s = value\n", field.Name)
if requiredTotal > 0 { if requiredTotal > 0 {