You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/06/13 12:48:54 UTC

[plc4x] branch develop updated: feat(plc4go/gen): add support for chan and func fields

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new f347cfc383 feat(plc4go/gen): add support for chan and func fields
f347cfc383 is described below

commit f347cfc3831162ee816152592522fbc95e6ef469
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Jun 13 14:48:46 2023 +0200

    feat(plc4go/gen): add support for chan and func fields
---
 plc4go/tools/plc4xgenerator/gen.go | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/plc4go/tools/plc4xgenerator/gen.go b/plc4go/tools/plc4xgenerator/gen.go
index cd2dbfc2d5..6adad0b554 100644
--- a/plc4go/tools/plc4xgenerator/gen.go
+++ b/plc4go/tools/plc4xgenerator/gen.go
@@ -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)
 			}
@@ -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)
 				}
@@ -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)
 		}
@@ -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:]
 }