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 2021/12/01 10:11:25 UTC
[plc4x] branch develop updated: fix(plc4go/codegen): avoid opening contexts for manual 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 7d9f7b7 fix(plc4go/codegen): avoid opening contexts for manual fields
7d9f7b7 is described below
commit 7d9f7b772aae69f500f6026acfd5034fc8a49e79
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Dec 1 11:11:17 2021 +0100
fix(plc4go/codegen): avoid opening contexts for manual fields
---
.../resources/templates/go/model-template.go.ftlh | 12 ----
.../model/BACnetComplexTagPropertyIdentifier.go | 12 ----
.../s7/readwrite/model/AssociatedValueType.go | 12 ----
.../plc4go/s7/readwrite/model/DateAndTime.go | 84 ----------------------
4 files changed, 120 deletions(-)
diff --git a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
index 88b3b37..0d48d23 100644
--- a/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
+++ b/code-generation/language-go/src/main/resources/templates/go/model-template.go.ftlh
@@ -813,16 +813,10 @@ func ${type.name}Parse(readBuffer utils.ReadBuffer<#if hasParserArguments>, ${pa
<#assign manualField = field.asManualField().orElseThrow()>
// Manual Field (${manualField.name})
- if pullErr := readBuffer.PullContext("${manualField.name}"); pullErr != nil {
- return nil, pullErr
- }
${manualField.name}, _${manualField.name}Err := ${helper.toParseExpression(manualField, manualField.type, manualField.parseExpression, parserArguments)}
if _${manualField.name}Err != nil {
return nil, errors.Wrap(_${manualField.name}Err, "Error parsing '${manualField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
- if closeErr := readBuffer.CloseContext("${manualField.name}"); closeErr != nil {
- return nil, closeErr
- }
<#break>
<#case "optional">
<#assign optionalField = field.asOptionalField().orElseThrow()>
@@ -1311,13 +1305,7 @@ func (m *${type.name}) Serialize(writeBuffer utils.WriteBuffer) error {
<#assign manualField = field.asManualField().orElseThrow()>
// Manual Field (${manualField.name})
- if pushErr := writeBuffer.PushContext("${manualField.name}"); pushErr != nil {
- return pushErr
- }
_${manualField.name}Err := ${helper.toSerializationExpression(manualField, manualField.type, manualField.serializeExpression, parserArguments)}
- if popErr := writeBuffer.PopContext("${manualField.name}"); popErr != nil {
- return popErr
- }
if _${manualField.name}Err != nil {
return errors.Wrap(_${manualField.name}Err, "Error serializing '${manualField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
diff --git a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetComplexTagPropertyIdentifier.go b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetComplexTagPropertyIdentifier.go
index e2b550b..c9e72a6 100644
--- a/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetComplexTagPropertyIdentifier.go
+++ b/plc4go/internal/plc4go/bacnetip/readwrite/model/BACnetComplexTagPropertyIdentifier.go
@@ -111,16 +111,10 @@ func BACnetComplexTagPropertyIdentifierParse(readBuffer utils.ReadBuffer, tagNum
}
// Manual Field (value)
- if pullErr := readBuffer.PullContext("value"); pullErr != nil {
- return nil, pullErr
- }
value, _valueErr := ReadPropertyIdentifier(readBuffer, actualLength)
if _valueErr != nil {
return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
}
- if closeErr := readBuffer.CloseContext("value"); closeErr != nil {
- return nil, closeErr
- }
if closeErr := readBuffer.CloseContext("BACnetComplexTagPropertyIdentifier"); closeErr != nil {
return nil, closeErr
@@ -142,13 +136,7 @@ func (m *BACnetComplexTagPropertyIdentifier) Serialize(writeBuffer utils.WriteBu
}
// Manual Field (value)
- if pushErr := writeBuffer.PushContext("value"); pushErr != nil {
- return pushErr
- }
_valueErr := WritePropertyIdentifier(writeBuffer, m.Value)
- if popErr := writeBuffer.PopContext("value"); popErr != nil {
- return popErr
- }
if _valueErr != nil {
return errors.Wrap(_valueErr, "Error serializing 'value' field")
}
diff --git a/plc4go/internal/plc4go/s7/readwrite/model/AssociatedValueType.go b/plc4go/internal/plc4go/s7/readwrite/model/AssociatedValueType.go
index e85659a..b9f570d 100644
--- a/plc4go/internal/plc4go/s7/readwrite/model/AssociatedValueType.go
+++ b/plc4go/internal/plc4go/s7/readwrite/model/AssociatedValueType.go
@@ -122,16 +122,10 @@ func AssociatedValueTypeParse(readBuffer utils.ReadBuffer) (*AssociatedValueType
}
// Manual Field (valueLength)
- if pullErr := readBuffer.PullContext("valueLength"); pullErr != nil {
- return nil, pullErr
- }
valueLength, _valueLengthErr := RightShift3(readBuffer)
if _valueLengthErr != nil {
return nil, errors.Wrap(_valueLengthErr, "Error parsing 'valueLength' field")
}
- if closeErr := readBuffer.CloseContext("valueLength"); closeErr != nil {
- return nil, closeErr
- }
// Array field (data)
if pullErr := readBuffer.PullContext("data", utils.WithRenderAsList(true)); pullErr != nil {
@@ -190,13 +184,7 @@ func (m *AssociatedValueType) Serialize(writeBuffer utils.WriteBuffer) error {
}
// Manual Field (valueLength)
- if pushErr := writeBuffer.PushContext("valueLength"); pushErr != nil {
- return pushErr
- }
_valueLengthErr := LeftShift3(writeBuffer, m.ValueLength)
- if popErr := writeBuffer.PopContext("valueLength"); popErr != nil {
- return popErr
- }
if _valueLengthErr != nil {
return errors.Wrap(_valueLengthErr, "Error serializing 'valueLength' field")
}
diff --git a/plc4go/internal/plc4go/s7/readwrite/model/DateAndTime.go b/plc4go/internal/plc4go/s7/readwrite/model/DateAndTime.go
index 9f86323..60482cd 100644
--- a/plc4go/internal/plc4go/s7/readwrite/model/DateAndTime.go
+++ b/plc4go/internal/plc4go/s7/readwrite/model/DateAndTime.go
@@ -110,88 +110,46 @@ func DateAndTimeParse(readBuffer utils.ReadBuffer) (*DateAndTime, error) {
}
// Manual Field (year)
- if pullErr := readBuffer.PullContext("year"); pullErr != nil {
- return nil, pullErr
- }
year, _yearErr := BcdToInt(readBuffer)
if _yearErr != nil {
return nil, errors.Wrap(_yearErr, "Error parsing 'year' field")
}
- if closeErr := readBuffer.CloseContext("year"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (month)
- if pullErr := readBuffer.PullContext("month"); pullErr != nil {
- return nil, pullErr
- }
month, _monthErr := BcdToInt(readBuffer)
if _monthErr != nil {
return nil, errors.Wrap(_monthErr, "Error parsing 'month' field")
}
- if closeErr := readBuffer.CloseContext("month"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (day)
- if pullErr := readBuffer.PullContext("day"); pullErr != nil {
- return nil, pullErr
- }
day, _dayErr := BcdToInt(readBuffer)
if _dayErr != nil {
return nil, errors.Wrap(_dayErr, "Error parsing 'day' field")
}
- if closeErr := readBuffer.CloseContext("day"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (hour)
- if pullErr := readBuffer.PullContext("hour"); pullErr != nil {
- return nil, pullErr
- }
hour, _hourErr := BcdToInt(readBuffer)
if _hourErr != nil {
return nil, errors.Wrap(_hourErr, "Error parsing 'hour' field")
}
- if closeErr := readBuffer.CloseContext("hour"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (minutes)
- if pullErr := readBuffer.PullContext("minutes"); pullErr != nil {
- return nil, pullErr
- }
minutes, _minutesErr := BcdToInt(readBuffer)
if _minutesErr != nil {
return nil, errors.Wrap(_minutesErr, "Error parsing 'minutes' field")
}
- if closeErr := readBuffer.CloseContext("minutes"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (seconds)
- if pullErr := readBuffer.PullContext("seconds"); pullErr != nil {
- return nil, pullErr
- }
seconds, _secondsErr := BcdToInt(readBuffer)
if _secondsErr != nil {
return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
}
- if closeErr := readBuffer.CloseContext("seconds"); closeErr != nil {
- return nil, closeErr
- }
// Manual Field (msec)
- if pullErr := readBuffer.PullContext("msec"); pullErr != nil {
- return nil, pullErr
- }
msec, _msecErr := S7msecToInt(readBuffer)
if _msecErr != nil {
return nil, errors.Wrap(_msecErr, "Error parsing 'msec' field")
}
- if closeErr := readBuffer.CloseContext("msec"); closeErr != nil {
- return nil, closeErr
- }
// Simple Field (dow)
_dow, _dowErr := readBuffer.ReadUint8("dow", 4)
@@ -214,85 +172,43 @@ func (m *DateAndTime) Serialize(writeBuffer utils.WriteBuffer) error {
}
// Manual Field (year)
- if pushErr := writeBuffer.PushContext("year"); pushErr != nil {
- return pushErr
- }
_yearErr := ByteToBcd(writeBuffer, m.Year)
- if popErr := writeBuffer.PopContext("year"); popErr != nil {
- return popErr
- }
if _yearErr != nil {
return errors.Wrap(_yearErr, "Error serializing 'year' field")
}
// Manual Field (month)
- if pushErr := writeBuffer.PushContext("month"); pushErr != nil {
- return pushErr
- }
_monthErr := ByteToBcd(writeBuffer, m.Month)
- if popErr := writeBuffer.PopContext("month"); popErr != nil {
- return popErr
- }
if _monthErr != nil {
return errors.Wrap(_monthErr, "Error serializing 'month' field")
}
// Manual Field (day)
- if pushErr := writeBuffer.PushContext("day"); pushErr != nil {
- return pushErr
- }
_dayErr := ByteToBcd(writeBuffer, m.Day)
- if popErr := writeBuffer.PopContext("day"); popErr != nil {
- return popErr
- }
if _dayErr != nil {
return errors.Wrap(_dayErr, "Error serializing 'day' field")
}
// Manual Field (hour)
- if pushErr := writeBuffer.PushContext("hour"); pushErr != nil {
- return pushErr
- }
_hourErr := ByteToBcd(writeBuffer, m.Hour)
- if popErr := writeBuffer.PopContext("hour"); popErr != nil {
- return popErr
- }
if _hourErr != nil {
return errors.Wrap(_hourErr, "Error serializing 'hour' field")
}
// Manual Field (minutes)
- if pushErr := writeBuffer.PushContext("minutes"); pushErr != nil {
- return pushErr
- }
_minutesErr := ByteToBcd(writeBuffer, m.Minutes)
- if popErr := writeBuffer.PopContext("minutes"); popErr != nil {
- return popErr
- }
if _minutesErr != nil {
return errors.Wrap(_minutesErr, "Error serializing 'minutes' field")
}
// Manual Field (seconds)
- if pushErr := writeBuffer.PushContext("seconds"); pushErr != nil {
- return pushErr
- }
_secondsErr := ByteToBcd(writeBuffer, m.Seconds)
- if popErr := writeBuffer.PopContext("seconds"); popErr != nil {
- return popErr
- }
if _secondsErr != nil {
return errors.Wrap(_secondsErr, "Error serializing 'seconds' field")
}
// Manual Field (msec)
- if pushErr := writeBuffer.PushContext("msec"); pushErr != nil {
- return pushErr
- }
_msecErr := IntToS7msec(writeBuffer, m.Msec)
- if popErr := writeBuffer.PopContext("msec"); popErr != nil {
- return popErr
- }
if _msecErr != nil {
return errors.Wrap(_msecErr, "Error serializing 'msec' field")
}