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 2024/09/19 11:05:47 UTC
(plc4x) 01/02: fix(plc4go/tools): fixed issue on plc4xGenerator
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
commit fb2fb4d55834563ac0f648f95408420532e04926
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Sep 18 14:14:17 2024 +0200
fix(plc4go/tools): fixed issue on plc4xGenerator
---
plc4go/tools/plc4xGenerator/ExampleStruct_test.go | 2 ++
plc4go/tools/plc4xGenerator/main.go | 13 ++++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/plc4go/tools/plc4xGenerator/ExampleStruct_test.go b/plc4go/tools/plc4xGenerator/ExampleStruct_test.go
index f0ffefd8ec..22f73cece9 100644
--- a/plc4go/tools/plc4xGenerator/ExampleStruct_test.go
+++ b/plc4go/tools/plc4xGenerator/ExampleStruct_test.go
@@ -42,6 +42,8 @@ type Example struct {
jField TestStruct1
kField *TestStruct1
lField TestStruct2
+ mField *time.Time
+ nField *time.Duration
}
type ExampleDelegate1 struct {
diff --git a/plc4go/tools/plc4xGenerator/main.go b/plc4go/tools/plc4xGenerator/main.go
index 87214eb2a4..cb1b52f847 100644
--- a/plc4go/tools/plc4xGenerator/main.go
+++ b/plc4go/tools/plc4xGenerator/main.go
@@ -387,7 +387,18 @@ func (g *Generator) generate(typeName string) {
}
if xIdent.Name == "time" {
if sel.Name == "Time" || sel.Name == "Duration" {
- g.Printf(stringFieldSerialize, "fmt.Sprintf(\"%s\", d."+field.name+")", fieldNameUntitled)
+ deref := ""
+ indentTimes := 0
+ if needsDereference {
+ deref = "*"
+ indentTimes++
+ g.Printf("if d.%s != nil {", field.name)
+ }
+ g.Printf(indent(indentTimes, stringFieldSerialize), "fmt.Sprintf(\"%s\", "+deref+"d."+field.name+")", fieldNameUntitled)
+
+ if needsDereference {
+ g.Printf("}\n")
+ }
continue
}
}