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/01 10:53:19 UTC
(plc4x) 04/07: feat(code-gen/go): padding field writer
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 efacfe66ab6ca2b86b541977f978467bc32b074a
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sun Sep 1 11:56:40 2024 +0200
feat(code-gen/go): padding field writer
---
.../templates/go/complex-type-template.go.ftlh | 29 +++++++++-------------
.../s7/readwrite/model/S7VarPayloadDataItem.go | 18 ++------------
2 files changed, 14 insertions(+), 33 deletions(-)
diff --git a/code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh b/code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh
index 56fb90a49b..9b7266cf82 100644
--- a/code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh
+++ b/code-generation/language-go/src/main/resources/templates/go/complex-type-template.go.ftlh
@@ -1432,24 +1432,19 @@ func (m *_${type.name}) SerializeWithWriteBuffer(ctx context.Context, writeBuffe
<#break>
<#case "padding">
<#assign paddingField = field.asPaddingField().orElseThrow()>
- <#assign simpleTypeReference = paddingField.type.asSimpleTypeReference().orElseThrow()>
+ <#assign typedField = field.asTypedField().orElseThrow()>
- // Padding Field (padding)
- {
- if pushErr := writeBuffer.PushContext("padding", utils.WithRenderAsList(true)); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for padding")<@emitImport import="github.com/pkg/errors" />
- }
- _timesPadding := uint8(${helper.toSerializationExpression(paddingField, helper.intTypeReference, paddingField.paddingCondition, parserArguments)})
- for ;_timesPadding > 0; _timesPadding-- {
- _paddingValue := ${helper.getLanguageTypeNameForField(field)}(${helper.toSerializationExpression(paddingField, paddingField.type, paddingField.paddingValue, parserArguments)})
- _paddingErr := ${helper.getWriteBufferWriteMethodCall("", simpleTypeReference, "(_paddingValue)", paddingField)}
- if _paddingErr != nil {
- return errors.Wrap(_paddingErr, "Error serializing 'padding' field")<@emitImport import="github.com/pkg/errors" />
- }
- }
- if popErr := writeBuffer.PopContext("padding", utils.WithRenderAsList(true)); popErr != nil {
- return errors.Wrap(popErr, "Error popping for padding")<@emitImport import="github.com/pkg/errors" />
- }
+ <@compress single_line=true>
+ if err := WritePaddingField[${helper.getLanguageTypeNameForField(paddingField)}](
+ ctx,
+ "padding",
+ int(${helper.toSerializationExpression(paddingField, helper.intTypeReference, paddingField.paddingCondition, parserArguments)}),
+ ${helper.getLanguageTypeNameForField(field)}(${helper.toSerializationExpression(paddingField, paddingField.type, paddingField.paddingValue, parserArguments)}),
+ ${helper.getDataWriterCall(typedField.type, "padding")}${helper.getFieldOptions(typedField, parserArguments)}
+ ); err != nil {
+ </...@compress>
+
+ return errors.Wrap(err, "Error serializing 'padding' field")<@emitImport import="github.com/pkg/errors" />
}
<#break>
<#case "reserved">
diff --git a/plc4go/protocols/s7/readwrite/model/S7VarPayloadDataItem.go b/plc4go/protocols/s7/readwrite/model/S7VarPayloadDataItem.go
index ec2ae350eb..4e5353dcf9 100644
--- a/plc4go/protocols/s7/readwrite/model/S7VarPayloadDataItem.go
+++ b/plc4go/protocols/s7/readwrite/model/S7VarPayloadDataItem.go
@@ -240,22 +240,8 @@ func (m *_S7VarPayloadDataItem) SerializeWithWriteBuffer(ctx context.Context, wr
return errors.Wrap(err, "Error serializing 'data' field")
}
- // Padding Field (padding)
- {
- if pushErr := writeBuffer.PushContext("padding", utils.WithRenderAsList(true)); pushErr != nil {
- return errors.Wrap(pushErr, "Error pushing for padding")
- }
- _timesPadding := uint8(utils.InlineIf((!(utils.GetLastItemFromContext(ctx))), func() any { return int32((int32(int32(len(m.GetData()))) % int32(int32(2)))) }, func() any { return int32(int32(0)) }).(int32))
- for ; _timesPadding > 0; _timesPadding-- {
- _paddingValue := uint8(0x00)
- _paddingErr := /*TODO: migrate me*/ writeBuffer.WriteUint8("", 8, uint8((_paddingValue)))
- if _paddingErr != nil {
- return errors.Wrap(_paddingErr, "Error serializing 'padding' field")
- }
- }
- if popErr := writeBuffer.PopContext("padding", utils.WithRenderAsList(true)); popErr != nil {
- return errors.Wrap(popErr, "Error popping for padding")
- }
+ if err := WritePaddingField[uint8](ctx, "padding", int(utils.InlineIf((!(utils.GetLastItemFromContext(ctx))), func() any { return int32((int32(int32(len(m.GetData()))) % int32(int32(2)))) }, func() any { return int32(int32(0)) }).(int32)), uint8(0x00), WriteUnsignedByte(writeBuffer, 8)); err != nil {
+ return errors.Wrap(err, "Error serializing 'padding' field")
}
if popErr := writeBuffer.PopContext("S7VarPayloadDataItem"); popErr != nil {