Skip to content

Commit

Permalink
fix(plc4go/tools): fixed issue on plc4xGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Sep 19, 2024
1 parent 96fc493 commit fb2fb4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions plc4go/tools/plc4xGenerator/ExampleStruct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type Example struct {
jField TestStruct1
kField *TestStruct1
lField TestStruct2
mField *time.Time
nField *time.Duration
}

type ExampleDelegate1 struct {
Expand Down
13 changes: 12 additions & 1 deletion plc4go/tools/plc4xGenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit fb2fb4d

Please sign in to comment.