Skip to content

Commit

Permalink
feat(plc4go/gen): add support for chan and func fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jun 13, 2023
1 parent 5422176 commit f347cfc
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions plc4go/tools/plc4xgenerator/gen.go
Expand Up @@ -248,7 +248,7 @@ func (g *Generator) generate(typeName string) {
case "error":
g.Printf(errorFieldSerialize, "d."+field.name, fieldNameUntitled)
default:
fmt.Printf("\t no support implemented %v\n", fieldType)
fmt.Printf("\t no support implemented for Ident with type %v\n", fieldType)
g.Printf("_value := fmt.Sprintf(\"%%v\", d.%s)\n", fieldName)
g.Printf(stringFieldSerialize, "_value", fieldNameUntitled)
}
Expand All @@ -270,7 +270,7 @@ func (g *Generator) generate(typeName string) {
case "error":
g.Printf(errorFieldSerialize, "elem", "\"\"")
default:
fmt.Printf("\t no support implemented %v\n", fieldType)
fmt.Printf("\t no support implemented for Ident within ArrayType for %v\n", fieldType)
g.Printf("_value := fmt.Sprintf(\"%%v\", elem)\n")
g.Printf(stringFieldSerialize, "_value", fieldNameUntitled)
}
Expand Down Expand Up @@ -312,17 +312,21 @@ func (g *Generator) generate(typeName string) {
case "error":
g.Printf(errorFieldSerialize, "elem", "name")
default:
fmt.Printf("\t no support implemented %v\n", fieldType)
fmt.Printf("\t no support implemented for Ident within MapType for %v\n", fieldType)
g.Printf("\t\t_value := fmt.Sprintf(\"%%v\", elem)\n")
g.Printf(stringFieldSerialize, "_value", "name")
}
default:
fmt.Printf("\t no support implemented %v\n", fieldType)
fmt.Printf("\t no support implemented within MapType %v\n", fieldType.Value)
g.Printf("\t\t_value := fmt.Sprintf(\"%%v\", elem)\n")
g.Printf(stringFieldSerialize, "_value", "name")
}
g.Printf("\t}\n")
g.Printf("if err := writeBuffer.PopContext(%s, utils.WithRenderAsList(true)); err != nil {\n\t\treturn err\n\t}\n", fieldNameUntitled)
case *ast.ChanType:
g.Printf(chanFieldSerialize, "d."+field.name, fieldNameUntitled, field.name)
case *ast.FuncType:
g.Printf(funcFieldSerialize, "d."+field.name, fieldNameUntitled)
default:
fmt.Printf("no support implemented %#v\n", fieldType)
}
Expand Down Expand Up @@ -508,6 +512,19 @@ var errorFieldSerialize = `
}
`

var chanFieldSerialize = `
_%[3]s_plx4gen_description := fmt.Sprintf("%%d element(s)", len(%[1]s))
if err := writeBuffer.WriteString(%[2]s, uint32(len(_%[3]s_plx4gen_description)*8), "UTF-8", _%[3]s_plx4gen_description); err != nil {
return err
}
`

var funcFieldSerialize = `
if err := writeBuffer.WriteBit(%[2]s, %[1]s != nil); err != nil {
return err
}
`

func unTitle(value string) string {
return strings.ToLower(string(value[0])) + value[1:]
}

0 comments on commit f347cfc

Please sign in to comment.