Skip to content

Commit

Permalink
feat(code-gen/go): const field writer
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Aug 31, 2024
1 parent e2715a3 commit eac3602
Show file tree
Hide file tree
Showing 56 changed files with 183 additions and 367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1240,32 +1240,13 @@ func (m *_${type.name}) SerializeWithWriteBuffer(ctx context.Context, writeBuffe
<#break>
<#case "const">
<#assign constField = field.asConstField().orElseThrow()>
<#assign typedField = field.asTypedField().orElseThrow()>
<#assign namedField = field.asNamedField().orElseThrow()>

<#if constField.type.isEnumTypeReference()>
<#-- TODO: finish me-->
<#if constField.fieldName?has_content>
<#assign enumValueFieldAccessor=type.name+"_"+constField.name?upper_case>
// Const field (${constField.name})
_${constField.name}Err := ${helper.getWriteBufferWriteMethodCall(constField, constField.type.name, helper.getEnumFieldSimpleTypeReference(constField.type, constField.fieldName), enumValueFieldAccessor, constField, "utils.WithAdditionalStringRepresentation(${type.name}_${constField.name?upper_case}.PLC4XEnumName())")}
if _${constField.name}Err != nil {
return errors.Wrap(_${constField.name}Err, "Error serializing '${constField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
<#else>
// Const field (${constField.name})
${constField.name} := Cast${helper.getLanguageTypeNameForField(field)}(${type.name}_${constField.name?upper_case})
_${constField.name}Err := writeBuffer.WriteSerializable(ctx, ${constField.name})
if _${constField.name}Err != nil {
return errors.Wrap(_${constField.name}Err, "Error serializing '${constField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
</#if>
<#else>
// Const Field (${constField.name})
_${constField.name}Err := ${helper.getWriteBufferWriteMethodCall(constField.name, constField.type.asSimpleTypeReference().orElseThrow(), constField.referenceValue, constField)}
if _${constField.name}Err != nil {
return errors.Wrap(_${constField.name}Err, "Error serializing '${constField.name}' field")<@emitImport import="github.com/pkg/errors" />
if err := <#if typedField.type.isEnumTypeReference()>WriteConstField(ctx, "${constField.name}", ${type.name}_${namedField.name?upper_case}.getValue(), ${helper.getDataWriterCall(helper.getEnumBaseTypeReference(typedField.type), namedField.name)}${helper.getFieldOptions(typedField, parserArguments)});<#else>WriteConstField(ctx, "${constField.name}", ${type.name}_${namedField.name?upper_case}, ${helper.getDataWriterCall(typedField.type, namedField.name)}${helper.getFieldOptions(typedField, parserArguments)});</#if>err != nil{
return errors.Wrap(err, "Error serializing '${namedField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
</#if>
<#break>
<#break>
<#case "discriminator">
<#assign discriminatorField = field.asDiscriminatorField().orElseThrow()>

Expand Down
32 changes: 16 additions & 16 deletions plc4go/assets/testing/protocols/df1/ParserSerializerTestsuite.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<test:testsuite xmlns:test="https://plc4x.apache.org/schemas/parser-serializer-testsuite.xsd"
byteOrder="BIG_ENDIAN">
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions plc4go/protocols/ads/readwrite/model/AdsConstants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions plc4go/protocols/ads/readwrite/model/AdsDataTypeTableChildEntry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions plc4go/protocols/ads/readwrite/model/AdsDataTypeTableEntry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions plc4go/protocols/ads/readwrite/model/AdsSymbolTableEntry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 16 additions & 32 deletions plc4go/protocols/ads/readwrite/model/AmsPacket.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eac3602

Please sign in to comment.