generate: Add comments to protocol data structures, tests

This commit is contained in:
2025-10-13 14:15:59 -04:00
parent 5a3d0e19ea
commit e991b5af67
5 changed files with 50 additions and 18 deletions

View File

@@ -112,8 +112,11 @@ func (this *Generator) Generate(protocol *Protocol) (n int, err error) {
return n, nil
}
func (this *Generator) generateTypedef(name string, typ Type) (n int, err error) {
func (this *Generator) generateTypedef(name string, typedef Typedef) (n int, err error) {
typ := typedef.Type
// type definition
// TODO doc
nn, err := this.iprintf(
"\n// %s represents the protocol data type %s.\n",
name, name)
@@ -208,6 +211,7 @@ func (this *Generator) generateTypedef(name string, typ Type) (n int, err error)
// generateMessage generates the structure, as well as encoding decoding
// functions for the given message.
func (this *Generator) generateMessage(method uint16, message Message) (n int, err error) {
// TODO doc
nn, err := this.iprintf(
"\n// %s represents the protocol message M%04X %s.\n",
message.Name, method, message.Name)
@@ -1090,6 +1094,7 @@ func (this *Generator) generateTypeTableDefined(typ TypeTableDefined) (n int, er
for _, key := range slices.Sorted(maps.Keys(typ.Fields)) {
field := typ.Fields[key]
// TODO doc
nn, err := this.iprintf("%s ", field.Name)
n += nn; if err != nil { return n, err }
nn, err = this.generateType(field.Type)
@@ -1180,12 +1185,12 @@ func (this *Generator) resolveMessageName(message string) string {
}
func (this *Generator) resolveTypeName(name string) (Type, error) {
if typ, ok := this.protocol.Types[name]; ok {
if typ, ok := typ.(TypeNamed); ok {
if typedef, ok := this.protocol.Types[name]; ok {
if typ, ok := typedef.Type.(TypeNamed); ok {
return this.resolveTypeName(typ.Name)
}
return typ, nil
return typedef.Type, nil
}
return nil, fmt.Errorf("no type exists called %s", name)
}