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 1854b555c46239fb6a171521367b851c4a0848c0 Author: Sebastian Rühl <sru...@apache.org> AuthorDate: Sat Aug 31 00:51:18 2024 +0200 feat(code-gen/go): discriminator reader field --- .../language/go/GoLanguageTemplateHelper.java | 4 ++-- .../templates/go/complex-type-template.go.ftlh | 26 ++++++++-------------- .../readwrite/model/CIPEncapsulationPacket.go | 7 +++--- .../abeth/readwrite/model/DF1RequestCommand.go | 9 ++++---- .../abeth/readwrite/model/DF1RequestMessage.go | 9 ++++---- .../abeth/readwrite/model/DF1ResponseMessage.go | 9 ++++---- .../discovery/readwrite/model/AdsDiscoveryBlock.go | 16 +++++-------- plc4go/protocols/ads/readwrite/model/AmsPacket.go | 21 +++++------------ plc4go/protocols/bacnetip/readwrite/model/APDU.go | 16 +++++-------- .../model/BACnetConfirmedServiceRequest.go | 16 +++++-------- .../bacnetip/readwrite/model/BACnetServiceAck.go | 16 +++++-------- .../model/BACnetUnconfirmedServiceRequest.go | 16 +++++-------- plc4go/protocols/bacnetip/readwrite/model/BVLC.go | 7 +++--- plc4go/protocols/bacnetip/readwrite/model/NLM.go | 9 ++++---- plc4go/protocols/df1/readwrite/model/DF1Command.go | 9 ++++---- plc4go/protocols/df1/readwrite/model/DF1Symbol.go | 7 +++--- plc4go/protocols/eip/readwrite/model/CipService.go | 16 ++++++------- .../eip/readwrite/model/CommandSpecificDataItem.go | 9 ++++---- .../eip/readwrite/model/DataSegmentType.go | 9 ++++---- plc4go/protocols/eip/readwrite/model/EipPacket.go | 9 ++++---- .../eip/readwrite/model/LogicalSegmentType.go | 9 ++++---- .../protocols/eip/readwrite/model/PathSegment.go | 9 ++++---- .../eip/readwrite/model/PortSegmentType.go | 9 ++++---- plc4go/protocols/eip/readwrite/model/TypeId.go | 9 ++++---- .../firmata/readwrite/model/FirmataCommand.go | 9 ++++---- .../firmata/readwrite/model/FirmataMessage.go | 10 +++++---- .../firmata/readwrite/model/SysexCommand.go | 9 ++++---- plc4go/protocols/knxnetip/readwrite/model/Apdu.go | 9 ++++---- .../knxnetip/readwrite/model/ApduControl.go | 9 ++++---- .../protocols/knxnetip/readwrite/model/ApduData.go | 9 ++++---- .../knxnetip/readwrite/model/ApduDataExt.go | 9 ++++---- plc4go/protocols/knxnetip/readwrite/model/CEMI.go | 9 ++++---- .../readwrite/model/CEMIAdditionalInformation.go | 9 ++++---- .../model/ConnectionRequestInformation.go | 9 ++++---- .../readwrite/model/ConnectionResponseDataBlock.go | 9 ++++---- .../knxnetip/readwrite/model/KnxNetIpMessage.go | 7 +++--- .../knxnetip/readwrite/model/LDataFrame.go | 16 ++++++------- .../knxnetip/readwrite/model/ServiceId.go | 9 ++++---- .../protocols/modbus/readwrite/model/ModbusPDU.go | 16 ++++++------- .../protocols/opcua/readwrite/model/MessagePDU.go | 9 ++++---- .../opcua/readwrite/model/NodeIdTypeDefinition.go | 16 +++++-------- plc4go/protocols/opcua/readwrite/model/Variant.go | 7 +++--- plc4go/protocols/s7/readwrite/model/COTPPacket.go | 7 +++--- .../protocols/s7/readwrite/model/COTPParameter.go | 9 ++++---- plc4go/protocols/s7/readwrite/model/S7Address.go | 9 ++++---- plc4go/protocols/s7/readwrite/model/S7Message.go | 7 +++--- plc4go/protocols/s7/readwrite/model/S7Parameter.go | 9 ++++---- .../s7/readwrite/model/S7ParameterUserDataItem.go | 9 ++++---- .../readwrite/model/S7VarRequestParameterItem.go | 9 ++++---- plc4go/spi/codegen/io/DataReaderEnumDefault.go | 13 ++++------- plc4go/spi/codegen/io/DataReaderFactory.go | 6 ++--- 51 files changed, 249 insertions(+), 285 deletions(-) diff --git a/code-generation/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java b/code-generation/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java index ad6f6dbb7d..4ac61d1389 100644 --- a/code-generation/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java +++ b/code-generation/language-go/src/main/java/org/apache/plc4x/language/go/GoLanguageTemplateHelper.java @@ -422,7 +422,7 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp public String getDataReaderCall(TypeReference typeReference) { emitDataReaderRequiredImports(); - return getDataReaderCall(typeReference, "enumForValue"); + return getDataReaderCall(typeReference, "ByValue"); } public String getDataReaderCall(TypeReference typeReference, String resolverMethod) { @@ -430,7 +430,7 @@ public class GoLanguageTemplateHelper extends BaseFreemarkerLanguageTemplateHelp if (typeReference.isEnumTypeReference()) { final String languageTypeName = getLanguageTypeNameForTypeReference(typeReference); final SimpleTypeReference enumBaseTypeReference = getEnumBaseTypeReference(typeReference); - return "ReadEnum(" + languageTypeName + "::" + resolverMethod + ", " + getDataReaderCall(enumBaseTypeReference) + ")"; + return "ReadEnum(" + languageTypeName + resolverMethod + ", " + getDataReaderCall(enumBaseTypeReference) + ")"; } else if (typeReference.isArrayTypeReference()) { final ArrayTypeReference arrayTypeReference = typeReference.asArrayTypeReference().orElseThrow(); return getDataReaderCall(arrayTypeReference.getElementTypeReference(), resolverMethod); 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 d909520178..bd060a81ad 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 @@ -864,24 +864,16 @@ func ${type.name}ParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffe <#break> <#case "discriminator"> <#assign discriminatorField = field.asDiscriminatorField().orElseThrow()> + <#assign typedField = field.asTypedField().orElseThrow()> + <#assign namedField = field.asNamedField().orElseThrow()> - // Discriminator Field (${discriminatorField.name}) (Used as input to a switch field) - <#if helper.isEnumField(field)> - <#assign namedField = field.asNamedField().orElseThrow()> - if pullErr := readBuffer.PullContext("${namedField.name}"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for ${namedField.name}")<@emitImport import="github.com/pkg/errors" /> - } - ${helper.getVariableName(field)}_temp, _${discriminatorField.name}Err := ${helper.getLanguageTypeNameForField(discriminatorField)}ParseWithBuffer(ctx, readBuffer) - var ${helper.getVariableName(field)} ${helper.getLanguageTypeNameForField(discriminatorField)} = ${helper.getVariableName(field)}_temp - if closeErr := readBuffer.CloseContext("${namedField.name}"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for ${namedField.name}")<@emitImport import="github.com/pkg/errors" /> - } - <#else> - <#assign simpleTypeReference = discriminatorField.type.asSimpleTypeReference().orElseThrow()> - ${helper.getVariableName(field)}, _${discriminatorField.name}Err := ${helper.getReadBufferReadMethodCall(discriminatorField.name, simpleTypeReference, discriminatorField)} - </#if> - if _${discriminatorField.name}Err != nil { - return nil, errors.Wrap(_${discriminatorField.name}Err, "Error parsing '${discriminatorField.name}' field of ${type.name}")<@emitImport import="github.com/pkg/errors" /> + <#if typedField.type.isEnumTypeReference()> + ${namedField.name},err := ReadDiscriminatorEnumField[${helper.getLanguageTypeNameForField(field)}](ctx, "${namedField.name}", "${typedField.type.asEnumTypeReference().orElseThrow().typeDefinition.name}", ${helper.getDataReaderCall(typedField.type)}${helper.getFieldOptions(typedField, parserArguments)}); + <#else> + ${namedField.name},err := Read${field.typeName?cap_first}Field[${helper.getLanguageTypeNameForField(field)}](ctx, "${namedField.name}", ${helper.getDataReaderCall(typedField.type)}${helper.getFieldOptions(typedField, parserArguments)}); + </#if> + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing '${namedField.name}' field"))<@emitImport import="github.com/pkg/errors" /> } <#break> <#case "enum"> diff --git a/plc4go/protocols/abeth/readwrite/model/CIPEncapsulationPacket.go b/plc4go/protocols/abeth/readwrite/model/CIPEncapsulationPacket.go index 2117bd0458..1241768d90 100644 --- a/plc4go/protocols/abeth/readwrite/model/CIPEncapsulationPacket.go +++ b/plc4go/protocols/abeth/readwrite/model/CIPEncapsulationPacket.go @@ -183,10 +183,9 @@ func CIPEncapsulationPacketParseWithBuffer(ctx context.Context, readBuffer utils currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (commandType) (Used as input to a switch field) - commandType, _commandTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint16("commandType", 16) - if _commandTypeErr != nil { - return nil, errors.Wrap(_commandTypeErr, "Error parsing 'commandType' field of CIPEncapsulationPacket") + commandType, err := ReadDiscriminatorField[uint16](ctx, "commandType", ReadUnsignedShort(readBuffer, 16), codegen.WithByteOrder(binary.BigEndian)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandType' field")) } // Implicit Field (packetLen) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) diff --git a/plc4go/protocols/abeth/readwrite/model/DF1RequestCommand.go b/plc4go/protocols/abeth/readwrite/model/DF1RequestCommand.go index 060cccb5e7..e50de155c2 100644 --- a/plc4go/protocols/abeth/readwrite/model/DF1RequestCommand.go +++ b/plc4go/protocols/abeth/readwrite/model/DF1RequestCommand.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func DF1RequestCommandParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (functionCode) (Used as input to a switch field) - functionCode, _functionCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("functionCode", 8) - if _functionCodeErr != nil { - return nil, errors.Wrap(_functionCodeErr, "Error parsing 'functionCode' field of DF1RequestCommand") + functionCode, err := ReadDiscriminatorField[uint8](ctx, "functionCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'functionCode' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/abeth/readwrite/model/DF1RequestMessage.go b/plc4go/protocols/abeth/readwrite/model/DF1RequestMessage.go index b9b6068cc3..28ed090746 100644 --- a/plc4go/protocols/abeth/readwrite/model/DF1RequestMessage.go +++ b/plc4go/protocols/abeth/readwrite/model/DF1RequestMessage.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -205,10 +207,9 @@ func DF1RequestMessageParseWithBuffer(ctx context.Context, readBuffer utils.Read } } - // Discriminator Field (commandCode) (Used as input to a switch field) - commandCode, _commandCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("commandCode", 8) - if _commandCodeErr != nil { - return nil, errors.Wrap(_commandCodeErr, "Error parsing 'commandCode' field of DF1RequestMessage") + commandCode, err := ReadDiscriminatorField[uint8](ctx, "commandCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandCode' field")) } // Simple Field (status) diff --git a/plc4go/protocols/abeth/readwrite/model/DF1ResponseMessage.go b/plc4go/protocols/abeth/readwrite/model/DF1ResponseMessage.go index d336d7b8b8..acc451b669 100644 --- a/plc4go/protocols/abeth/readwrite/model/DF1ResponseMessage.go +++ b/plc4go/protocols/abeth/readwrite/model/DF1ResponseMessage.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -229,10 +231,9 @@ func DF1ResponseMessageParseWithBuffer(ctx context.Context, readBuffer utils.Rea } } - // Discriminator Field (commandCode) (Used as input to a switch field) - commandCode, _commandCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("commandCode", 8) - if _commandCodeErr != nil { - return nil, errors.Wrap(_commandCodeErr, "Error parsing 'commandCode' field of DF1ResponseMessage") + commandCode, err := ReadDiscriminatorField[uint8](ctx, "commandCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandCode' field")) } // Simple Field (status) diff --git a/plc4go/protocols/ads/discovery/readwrite/model/AdsDiscoveryBlock.go b/plc4go/protocols/ads/discovery/readwrite/model/AdsDiscoveryBlock.go index faab6357e9..e03ebd9878 100644 --- a/plc4go/protocols/ads/discovery/readwrite/model/AdsDiscoveryBlock.go +++ b/plc4go/protocols/ads/discovery/readwrite/model/AdsDiscoveryBlock.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,17 +121,9 @@ func AdsDiscoveryBlockParseWithBuffer(ctx context.Context, readBuffer utils.Read currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (blockType) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("blockType"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for blockType") - } - blockType_temp, _blockTypeErr := AdsDiscoveryBlockTypeParseWithBuffer(ctx, readBuffer) - var blockType AdsDiscoveryBlockType = blockType_temp - if closeErr := readBuffer.CloseContext("blockType"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for blockType") - } - if _blockTypeErr != nil { - return nil, errors.Wrap(_blockTypeErr, "Error parsing 'blockType' field of AdsDiscoveryBlock") + blockType, err := ReadDiscriminatorEnumField[AdsDiscoveryBlockType](ctx, "blockType", "AdsDiscoveryBlockType", ReadEnum(AdsDiscoveryBlockTypeByValue, ReadUnsignedShort(readBuffer, 16))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'blockType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/ads/readwrite/model/AmsPacket.go b/plc4go/protocols/ads/readwrite/model/AmsPacket.go index 4c178abd9e..7f9a6cc7e5 100644 --- a/plc4go/protocols/ads/readwrite/model/AmsPacket.go +++ b/plc4go/protocols/ads/readwrite/model/AmsPacket.go @@ -320,17 +320,9 @@ func AmsPacketParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } sourceAmsPort := _sourceAmsPort - // Discriminator Field (commandId) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("commandId"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for commandId") - } - commandId_temp, _commandIdErr := CommandIdParseWithBuffer(ctx, readBuffer) - var commandId CommandId = commandId_temp - if closeErr := readBuffer.CloseContext("commandId"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for commandId") - } - if _commandIdErr != nil { - return nil, errors.Wrap(_commandIdErr, "Error parsing 'commandId' field of AmsPacket") + commandId, err := ReadDiscriminatorEnumField[CommandId](ctx, "commandId", "CommandId", ReadEnum(CommandIdByValue, ReadUnsignedShort(readBuffer, 16))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandId' field")) } initCommand, err := ReadConstField[bool](ctx, "initCommand", ReadBoolean(readBuffer), AmsPacket_INITCOMMAND) @@ -375,10 +367,9 @@ func AmsPacketParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } _ = noReturn - // Discriminator Field (response) (Used as input to a switch field) - response, _responseErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("response") - if _responseErr != nil { - return nil, errors.Wrap(_responseErr, "Error parsing 'response' field of AmsPacket") + response, err := ReadDiscriminatorField[bool](ctx, "response", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'response' field")) } broadcast, err := ReadConstField[bool](ctx, "broadcast", ReadBoolean(readBuffer), AmsPacket_BROADCAST) diff --git a/plc4go/protocols/bacnetip/readwrite/model/APDU.go b/plc4go/protocols/bacnetip/readwrite/model/APDU.go index e9d7d1d124..cadd58ccbb 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/APDU.go +++ b/plc4go/protocols/bacnetip/readwrite/model/APDU.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,17 +124,9 @@ func APDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, apduL currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (apduType) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("apduType"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for apduType") - } - apduType_temp, _apduTypeErr := ApduTypeParseWithBuffer(ctx, readBuffer) - var apduType ApduType = apduType_temp - if closeErr := readBuffer.CloseContext("apduType"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for apduType") - } - if _apduTypeErr != nil { - return nil, errors.Wrap(_apduTypeErr, "Error parsing 'apduType' field of APDU") + apduType, err := ReadDiscriminatorEnumField[ApduType](ctx, "apduType", "ApduType", ReadEnum(ApduTypeByValue, ReadUnsignedByte(readBuffer, 4))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'apduType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/bacnetip/readwrite/model/BACnetConfirmedServiceRequest.go b/plc4go/protocols/bacnetip/readwrite/model/BACnetConfirmedServiceRequest.go index d0e5672165..c47fa39861 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/BACnetConfirmedServiceRequest.go +++ b/plc4go/protocols/bacnetip/readwrite/model/BACnetConfirmedServiceRequest.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -142,17 +144,9 @@ func BACnetConfirmedServiceRequestParseWithBuffer(ctx context.Context, readBuffe currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (serviceChoice) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("serviceChoice"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for serviceChoice") - } - serviceChoice_temp, _serviceChoiceErr := BACnetConfirmedServiceChoiceParseWithBuffer(ctx, readBuffer) - var serviceChoice BACnetConfirmedServiceChoice = serviceChoice_temp - if closeErr := readBuffer.CloseContext("serviceChoice"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for serviceChoice") - } - if _serviceChoiceErr != nil { - return nil, errors.Wrap(_serviceChoiceErr, "Error parsing 'serviceChoice' field of BACnetConfirmedServiceRequest") + serviceChoice, err := ReadDiscriminatorEnumField[BACnetConfirmedServiceChoice](ctx, "serviceChoice", "BACnetConfirmedServiceChoice", ReadEnum(BACnetConfirmedServiceChoiceByValue, ReadUnsignedByte(readBuffer, 8))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'serviceChoice' field")) } // Virtual field diff --git a/plc4go/protocols/bacnetip/readwrite/model/BACnetServiceAck.go b/plc4go/protocols/bacnetip/readwrite/model/BACnetServiceAck.go index 5f99e80b9d..dcbd43925e 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/BACnetServiceAck.go +++ b/plc4go/protocols/bacnetip/readwrite/model/BACnetServiceAck.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -142,17 +144,9 @@ func BACnetServiceAckParseWithBuffer(ctx context.Context, readBuffer utils.ReadB currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (serviceChoice) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("serviceChoice"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for serviceChoice") - } - serviceChoice_temp, _serviceChoiceErr := BACnetConfirmedServiceChoiceParseWithBuffer(ctx, readBuffer) - var serviceChoice BACnetConfirmedServiceChoice = serviceChoice_temp - if closeErr := readBuffer.CloseContext("serviceChoice"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for serviceChoice") - } - if _serviceChoiceErr != nil { - return nil, errors.Wrap(_serviceChoiceErr, "Error parsing 'serviceChoice' field of BACnetServiceAck") + serviceChoice, err := ReadDiscriminatorEnumField[BACnetConfirmedServiceChoice](ctx, "serviceChoice", "BACnetConfirmedServiceChoice", ReadEnum(BACnetConfirmedServiceChoiceByValue, ReadUnsignedByte(readBuffer, 8))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'serviceChoice' field")) } // Virtual field diff --git a/plc4go/protocols/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequest.go b/plc4go/protocols/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequest.go index 83f45c0c46..4f74537ce8 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequest.go +++ b/plc4go/protocols/bacnetip/readwrite/model/BACnetUnconfirmedServiceRequest.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,17 +124,9 @@ func BACnetUnconfirmedServiceRequestParseWithBuffer(ctx context.Context, readBuf currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (serviceChoice) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("serviceChoice"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for serviceChoice") - } - serviceChoice_temp, _serviceChoiceErr := BACnetUnconfirmedServiceChoiceParseWithBuffer(ctx, readBuffer) - var serviceChoice BACnetUnconfirmedServiceChoice = serviceChoice_temp - if closeErr := readBuffer.CloseContext("serviceChoice"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for serviceChoice") - } - if _serviceChoiceErr != nil { - return nil, errors.Wrap(_serviceChoiceErr, "Error parsing 'serviceChoice' field of BACnetUnconfirmedServiceRequest") + serviceChoice, err := ReadDiscriminatorEnumField[BACnetUnconfirmedServiceChoice](ctx, "serviceChoice", "BACnetUnconfirmedServiceChoice", ReadEnum(BACnetUnconfirmedServiceChoiceByValue, ReadUnsignedByte(readBuffer, 8))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'serviceChoice' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/bacnetip/readwrite/model/BVLC.go b/plc4go/protocols/bacnetip/readwrite/model/BVLC.go index d83a526248..3b1e0c5add 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/BVLC.go +++ b/plc4go/protocols/bacnetip/readwrite/model/BVLC.go @@ -171,10 +171,9 @@ func BVLCParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (BVLC } _ = bacnetType - // Discriminator Field (bvlcFunction) (Used as input to a switch field) - bvlcFunction, _bvlcFunctionErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("bvlcFunction", 8) - if _bvlcFunctionErr != nil { - return nil, errors.Wrap(_bvlcFunctionErr, "Error parsing 'bvlcFunction' field of BVLC") + bvlcFunction, err := ReadDiscriminatorField[uint8](ctx, "bvlcFunction", ReadUnsignedByte(readBuffer, 8), codegen.WithByteOrder(binary.BigEndian)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'bvlcFunction' field")) } // Implicit Field (bvlcLength) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) diff --git a/plc4go/protocols/bacnetip/readwrite/model/NLM.go b/plc4go/protocols/bacnetip/readwrite/model/NLM.go index f0c9243b2d..d03c1c576d 100644 --- a/plc4go/protocols/bacnetip/readwrite/model/NLM.go +++ b/plc4go/protocols/bacnetip/readwrite/model/NLM.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -143,10 +145,9 @@ func NLMParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, apduLe currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (messageType) (Used as input to a switch field) - messageType, _messageTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("messageType", 8) - if _messageTypeErr != nil { - return nil, errors.Wrap(_messageTypeErr, "Error parsing 'messageType' field of NLM") + messageType, err := ReadDiscriminatorField[uint8](ctx, "messageType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'messageType' field")) } // Virtual field diff --git a/plc4go/protocols/df1/readwrite/model/DF1Command.go b/plc4go/protocols/df1/readwrite/model/DF1Command.go index c69d618ee4..efb5ae31e1 100644 --- a/plc4go/protocols/df1/readwrite/model/DF1Command.go +++ b/plc4go/protocols/df1/readwrite/model/DF1Command.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -149,10 +151,9 @@ func DF1CommandParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (commandCode) (Used as input to a switch field) - commandCode, _commandCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("commandCode", 8) - if _commandCodeErr != nil { - return nil, errors.Wrap(_commandCodeErr, "Error parsing 'commandCode' field of DF1Command") + commandCode, err := ReadDiscriminatorField[uint8](ctx, "commandCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandCode' field")) } // Simple Field (status) diff --git a/plc4go/protocols/df1/readwrite/model/DF1Symbol.go b/plc4go/protocols/df1/readwrite/model/DF1Symbol.go index 83367ecd6a..3b3ec35603 100644 --- a/plc4go/protocols/df1/readwrite/model/DF1Symbol.go +++ b/plc4go/protocols/df1/readwrite/model/DF1Symbol.go @@ -149,10 +149,9 @@ func DF1SymbolParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } _ = messageStart - // Discriminator Field (symbolType) (Used as input to a switch field) - symbolType, _symbolTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("symbolType", 8) - if _symbolTypeErr != nil { - return nil, errors.Wrap(_symbolTypeErr, "Error parsing 'symbolType' field of DF1Symbol") + symbolType, err := ReadDiscriminatorField[uint8](ctx, "symbolType", ReadUnsignedByte(readBuffer, 8), codegen.WithByteOrder(binary.BigEndian)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'symbolType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/CipService.go b/plc4go/protocols/eip/readwrite/model/CipService.go index 42895cbb79..86d99381be 100644 --- a/plc4go/protocols/eip/readwrite/model/CipService.go +++ b/plc4go/protocols/eip/readwrite/model/CipService.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -130,16 +132,14 @@ func CipServiceParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (response) (Used as input to a switch field) - response, _responseErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("response") - if _responseErr != nil { - return nil, errors.Wrap(_responseErr, "Error parsing 'response' field of CipService") + response, err := ReadDiscriminatorField[bool](ctx, "response", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'response' field")) } - // Discriminator Field (service) (Used as input to a switch field) - service, _serviceErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("service", 7) - if _serviceErr != nil { - return nil, errors.Wrap(_serviceErr, "Error parsing 'service' field of CipService") + service, err := ReadDiscriminatorField[uint8](ctx, "service", ReadUnsignedByte(readBuffer, 7)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'service' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/CommandSpecificDataItem.go b/plc4go/protocols/eip/readwrite/model/CommandSpecificDataItem.go index f6036328b7..bbddb0993c 100644 --- a/plc4go/protocols/eip/readwrite/model/CommandSpecificDataItem.go +++ b/plc4go/protocols/eip/readwrite/model/CommandSpecificDataItem.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func CommandSpecificDataItemParseWithBuffer(ctx context.Context, readBuffer util currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (itemType) (Used as input to a switch field) - itemType, _itemTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint16("itemType", 16) - if _itemTypeErr != nil { - return nil, errors.Wrap(_itemTypeErr, "Error parsing 'itemType' field of CommandSpecificDataItem") + itemType, err := ReadDiscriminatorField[uint16](ctx, "itemType", ReadUnsignedShort(readBuffer, 16)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'itemType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/DataSegmentType.go b/plc4go/protocols/eip/readwrite/model/DataSegmentType.go index 823ee148eb..8198e62bb4 100644 --- a/plc4go/protocols/eip/readwrite/model/DataSegmentType.go +++ b/plc4go/protocols/eip/readwrite/model/DataSegmentType.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func DataSegmentTypeParseWithBuffer(ctx context.Context, readBuffer utils.ReadBu currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (dataSegmentType) (Used as input to a switch field) - dataSegmentType, _dataSegmentTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("dataSegmentType", 5) - if _dataSegmentTypeErr != nil { - return nil, errors.Wrap(_dataSegmentTypeErr, "Error parsing 'dataSegmentType' field of DataSegmentType") + dataSegmentType, err := ReadDiscriminatorField[uint8](ctx, "dataSegmentType", ReadUnsignedByte(readBuffer, 5)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'dataSegmentType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/EipPacket.go b/plc4go/protocols/eip/readwrite/model/EipPacket.go index d4e9bd2df6..50be88635a 100644 --- a/plc4go/protocols/eip/readwrite/model/EipPacket.go +++ b/plc4go/protocols/eip/readwrite/model/EipPacket.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -180,10 +182,9 @@ func EipPacketParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (command) (Used as input to a switch field) - command, _commandErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint16("command", 16) - if _commandErr != nil { - return nil, errors.Wrap(_commandErr, "Error parsing 'command' field of EipPacket") + command, err := ReadDiscriminatorField[uint16](ctx, "command", ReadUnsignedShort(readBuffer, 16)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'command' field")) } // Implicit Field (packetLength) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) diff --git a/plc4go/protocols/eip/readwrite/model/LogicalSegmentType.go b/plc4go/protocols/eip/readwrite/model/LogicalSegmentType.go index fcf7173f46..e99b119684 100644 --- a/plc4go/protocols/eip/readwrite/model/LogicalSegmentType.go +++ b/plc4go/protocols/eip/readwrite/model/LogicalSegmentType.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func LogicalSegmentTypeParseWithBuffer(ctx context.Context, readBuffer utils.Rea currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (logicalSegmentType) (Used as input to a switch field) - logicalSegmentType, _logicalSegmentTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("logicalSegmentType", 3) - if _logicalSegmentTypeErr != nil { - return nil, errors.Wrap(_logicalSegmentTypeErr, "Error parsing 'logicalSegmentType' field of LogicalSegmentType") + logicalSegmentType, err := ReadDiscriminatorField[uint8](ctx, "logicalSegmentType", ReadUnsignedByte(readBuffer, 3)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'logicalSegmentType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/PathSegment.go b/plc4go/protocols/eip/readwrite/model/PathSegment.go index 9432af8e64..9013abfee3 100644 --- a/plc4go/protocols/eip/readwrite/model/PathSegment.go +++ b/plc4go/protocols/eip/readwrite/model/PathSegment.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func PathSegmentParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (pathSegment) (Used as input to a switch field) - pathSegment, _pathSegmentErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("pathSegment", 3) - if _pathSegmentErr != nil { - return nil, errors.Wrap(_pathSegmentErr, "Error parsing 'pathSegment' field of PathSegment") + pathSegment, err := ReadDiscriminatorField[uint8](ctx, "pathSegment", ReadUnsignedByte(readBuffer, 3)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'pathSegment' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/PortSegmentType.go b/plc4go/protocols/eip/readwrite/model/PortSegmentType.go index 73350e9070..c4f4cfe2d6 100644 --- a/plc4go/protocols/eip/readwrite/model/PortSegmentType.go +++ b/plc4go/protocols/eip/readwrite/model/PortSegmentType.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func PortSegmentTypeParseWithBuffer(ctx context.Context, readBuffer utils.ReadBu currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (extendedLinkAddress) (Used as input to a switch field) - extendedLinkAddress, _extendedLinkAddressErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("extendedLinkAddress") - if _extendedLinkAddressErr != nil { - return nil, errors.Wrap(_extendedLinkAddressErr, "Error parsing 'extendedLinkAddress' field of PortSegmentType") + extendedLinkAddress, err := ReadDiscriminatorField[bool](ctx, "extendedLinkAddress", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'extendedLinkAddress' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/eip/readwrite/model/TypeId.go b/plc4go/protocols/eip/readwrite/model/TypeId.go index 8dbf4a4dc5..500b7555b7 100644 --- a/plc4go/protocols/eip/readwrite/model/TypeId.go +++ b/plc4go/protocols/eip/readwrite/model/TypeId.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func TypeIdParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (Ty currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (id) (Used as input to a switch field) - id, _idErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint16("id", 16) - if _idErr != nil { - return nil, errors.Wrap(_idErr, "Error parsing 'id' field of TypeId") + id, err := ReadDiscriminatorField[uint16](ctx, "id", ReadUnsignedShort(readBuffer, 16)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'id' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/firmata/readwrite/model/FirmataCommand.go b/plc4go/protocols/firmata/readwrite/model/FirmataCommand.go index 976191d777..90e6a29b03 100644 --- a/plc4go/protocols/firmata/readwrite/model/FirmataCommand.go +++ b/plc4go/protocols/firmata/readwrite/model/FirmataCommand.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func FirmataCommandParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuf currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (commandCode) (Used as input to a switch field) - commandCode, _commandCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("commandCode", 4) - if _commandCodeErr != nil { - return nil, errors.Wrap(_commandCodeErr, "Error parsing 'commandCode' field of FirmataCommand") + commandCode, err := ReadDiscriminatorField[uint8](ctx, "commandCode", ReadUnsignedByte(readBuffer, 4)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandCode' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/firmata/readwrite/model/FirmataMessage.go b/plc4go/protocols/firmata/readwrite/model/FirmataMessage.go index f8d8b5fbba..dbe55bd054 100644 --- a/plc4go/protocols/firmata/readwrite/model/FirmataMessage.go +++ b/plc4go/protocols/firmata/readwrite/model/FirmataMessage.go @@ -27,6 +27,9 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + "github.com/apache/plc4x/plc4go/spi/codegen" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -123,10 +126,9 @@ func FirmataMessageParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuf currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (messageType) (Used as input to a switch field) - messageType, _messageTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("messageType", 4) - if _messageTypeErr != nil { - return nil, errors.Wrap(_messageTypeErr, "Error parsing 'messageType' field of FirmataMessage") + messageType, err := ReadDiscriminatorField[uint8](ctx, "messageType", ReadUnsignedByte(readBuffer, 4), codegen.WithByteOrder(binary.BigEndian)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'messageType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/firmata/readwrite/model/SysexCommand.go b/plc4go/protocols/firmata/readwrite/model/SysexCommand.go index fc4b48382a..64a80fcec7 100644 --- a/plc4go/protocols/firmata/readwrite/model/SysexCommand.go +++ b/plc4go/protocols/firmata/readwrite/model/SysexCommand.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func SysexCommandParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffe currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (commandType) (Used as input to a switch field) - commandType, _commandTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("commandType", 8) - if _commandTypeErr != nil { - return nil, errors.Wrap(_commandTypeErr, "Error parsing 'commandType' field of SysexCommand") + commandType, err := ReadDiscriminatorField[uint8](ctx, "commandType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'commandType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/Apdu.go b/plc4go/protocols/knxnetip/readwrite/model/Apdu.go index 41a169fb18..0abcb6c012 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/Apdu.go +++ b/plc4go/protocols/knxnetip/readwrite/model/Apdu.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -152,10 +154,9 @@ func ApduParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, dataL currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (control) (Used as input to a switch field) - control, _controlErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("control", 1) - if _controlErr != nil { - return nil, errors.Wrap(_controlErr, "Error parsing 'control' field of Apdu") + control, err := ReadDiscriminatorField[uint8](ctx, "control", ReadUnsignedByte(readBuffer, 1)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'control' field")) } // Simple Field (numbered) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ApduControl.go b/plc4go/protocols/knxnetip/readwrite/model/ApduControl.go index 9fb408087a..8021337df6 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ApduControl.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ApduControl.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func ApduControlParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (controlType) (Used as input to a switch field) - controlType, _controlTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("controlType", 2) - if _controlTypeErr != nil { - return nil, errors.Wrap(_controlTypeErr, "Error parsing 'controlType' field of ApduControl") + controlType, err := ReadDiscriminatorField[uint8](ctx, "controlType", ReadUnsignedByte(readBuffer, 2)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'controlType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ApduData.go b/plc4go/protocols/knxnetip/readwrite/model/ApduData.go index 9040f67994..40bd0258a9 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ApduData.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ApduData.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func ApduDataParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, d currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (apciType) (Used as input to a switch field) - apciType, _apciTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("apciType", 4) - if _apciTypeErr != nil { - return nil, errors.Wrap(_apciTypeErr, "Error parsing 'apciType' field of ApduData") + apciType, err := ReadDiscriminatorField[uint8](ctx, "apciType", ReadUnsignedByte(readBuffer, 4)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'apciType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ApduDataExt.go b/plc4go/protocols/knxnetip/readwrite/model/ApduDataExt.go index a1477278c3..eae0a2aa63 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ApduDataExt.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ApduDataExt.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func ApduDataExtParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (extApciType) (Used as input to a switch field) - extApciType, _extApciTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("extApciType", 6) - if _extApciTypeErr != nil { - return nil, errors.Wrap(_extApciTypeErr, "Error parsing 'extApciType' field of ApduDataExt") + extApciType, err := ReadDiscriminatorField[uint8](ctx, "extApciType", ReadUnsignedByte(readBuffer, 6)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'extApciType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/CEMI.go b/plc4go/protocols/knxnetip/readwrite/model/CEMI.go index 5fb69cbcf9..bdd7e0a85d 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/CEMI.go +++ b/plc4go/protocols/knxnetip/readwrite/model/CEMI.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func CEMIParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, size currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (messageCode) (Used as input to a switch field) - messageCode, _messageCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("messageCode", 8) - if _messageCodeErr != nil { - return nil, errors.Wrap(_messageCodeErr, "Error parsing 'messageCode' field of CEMI") + messageCode, err := ReadDiscriminatorField[uint8](ctx, "messageCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'messageCode' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/CEMIAdditionalInformation.go b/plc4go/protocols/knxnetip/readwrite/model/CEMIAdditionalInformation.go index 1439e40d30..96f9fe4a30 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/CEMIAdditionalInformation.go +++ b/plc4go/protocols/knxnetip/readwrite/model/CEMIAdditionalInformation.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func CEMIAdditionalInformationParseWithBuffer(ctx context.Context, readBuffer ut currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (additionalInformationType) (Used as input to a switch field) - additionalInformationType, _additionalInformationTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("additionalInformationType", 8) - if _additionalInformationTypeErr != nil { - return nil, errors.Wrap(_additionalInformationTypeErr, "Error parsing 'additionalInformationType' field of CEMIAdditionalInformation") + additionalInformationType, err := ReadDiscriminatorField[uint8](ctx, "additionalInformationType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'additionalInformationType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ConnectionRequestInformation.go b/plc4go/protocols/knxnetip/readwrite/model/ConnectionRequestInformation.go index 8357c369e6..d5cbd6eaca 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ConnectionRequestInformation.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ConnectionRequestInformation.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -129,10 +131,9 @@ func ConnectionRequestInformationParseWithBuffer(ctx context.Context, readBuffer return nil, errors.Wrap(_structureLengthErr, "Error parsing 'structureLength' field of ConnectionRequestInformation") } - // Discriminator Field (connectionType) (Used as input to a switch field) - connectionType, _connectionTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("connectionType", 8) - if _connectionTypeErr != nil { - return nil, errors.Wrap(_connectionTypeErr, "Error parsing 'connectionType' field of ConnectionRequestInformation") + connectionType, err := ReadDiscriminatorField[uint8](ctx, "connectionType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'connectionType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ConnectionResponseDataBlock.go b/plc4go/protocols/knxnetip/readwrite/model/ConnectionResponseDataBlock.go index e0aec52cd3..2bd4e1c4bb 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ConnectionResponseDataBlock.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ConnectionResponseDataBlock.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -129,10 +131,9 @@ func ConnectionResponseDataBlockParseWithBuffer(ctx context.Context, readBuffer return nil, errors.Wrap(_structureLengthErr, "Error parsing 'structureLength' field of ConnectionResponseDataBlock") } - // Discriminator Field (connectionType) (Used as input to a switch field) - connectionType, _connectionTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("connectionType", 8) - if _connectionTypeErr != nil { - return nil, errors.Wrap(_connectionTypeErr, "Error parsing 'connectionType' field of ConnectionResponseDataBlock") + connectionType, err := ReadDiscriminatorField[uint8](ctx, "connectionType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'connectionType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/knxnetip/readwrite/model/KnxNetIpMessage.go b/plc4go/protocols/knxnetip/readwrite/model/KnxNetIpMessage.go index 6dcd28b1e1..8d19837f38 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/KnxNetIpMessage.go +++ b/plc4go/protocols/knxnetip/readwrite/model/KnxNetIpMessage.go @@ -162,10 +162,9 @@ func KnxNetIpMessageParseWithBuffer(ctx context.Context, readBuffer utils.ReadBu } _ = protocolVersion - // Discriminator Field (msgType) (Used as input to a switch field) - msgType, _msgTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint16("msgType", 16) - if _msgTypeErr != nil { - return nil, errors.Wrap(_msgTypeErr, "Error parsing 'msgType' field of KnxNetIpMessage") + msgType, err := ReadDiscriminatorField[uint16](ctx, "msgType", ReadUnsignedShort(readBuffer, 16), codegen.WithByteOrder(binary.BigEndian)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'msgType' field")) } // Implicit Field (totalLength) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) diff --git a/plc4go/protocols/knxnetip/readwrite/model/LDataFrame.go b/plc4go/protocols/knxnetip/readwrite/model/LDataFrame.go index 073ff35c60..ff2b6bef38 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/LDataFrame.go +++ b/plc4go/protocols/knxnetip/readwrite/model/LDataFrame.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -191,10 +193,9 @@ func LDataFrameParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } frameType := _frameType - // Discriminator Field (polling) (Used as input to a switch field) - polling, _pollingErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("polling") - if _pollingErr != nil { - return nil, errors.Wrap(_pollingErr, "Error parsing 'polling' field of LDataFrame") + polling, err := ReadDiscriminatorField[bool](ctx, "polling", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'polling' field")) } // Simple Field (notRepeated) @@ -204,10 +205,9 @@ func LDataFrameParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } notRepeated := _notRepeated - // Discriminator Field (notAckFrame) (Used as input to a switch field) - notAckFrame, _notAckFrameErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("notAckFrame") - if _notAckFrameErr != nil { - return nil, errors.Wrap(_notAckFrameErr, "Error parsing 'notAckFrame' field of LDataFrame") + notAckFrame, err := ReadDiscriminatorField[bool](ctx, "notAckFrame", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'notAckFrame' field")) } // Simple Field (priority) diff --git a/plc4go/protocols/knxnetip/readwrite/model/ServiceId.go b/plc4go/protocols/knxnetip/readwrite/model/ServiceId.go index 2c789f3e95..684b329899 100644 --- a/plc4go/protocols/knxnetip/readwrite/model/ServiceId.go +++ b/plc4go/protocols/knxnetip/readwrite/model/ServiceId.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func ServiceIdParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (serviceType) (Used as input to a switch field) - serviceType, _serviceTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("serviceType", 8) - if _serviceTypeErr != nil { - return nil, errors.Wrap(_serviceTypeErr, "Error parsing 'serviceType' field of ServiceId") + serviceType, err := ReadDiscriminatorField[uint8](ctx, "serviceType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'serviceType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/modbus/readwrite/model/ModbusPDU.go b/plc4go/protocols/modbus/readwrite/model/ModbusPDU.go index 8be6b29dbb..e6539a8463 100644 --- a/plc4go/protocols/modbus/readwrite/model/ModbusPDU.go +++ b/plc4go/protocols/modbus/readwrite/model/ModbusPDU.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -127,16 +129,14 @@ func ModbusPDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (errorFlag) (Used as input to a switch field) - errorFlag, _errorFlagErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadBit("errorFlag") - if _errorFlagErr != nil { - return nil, errors.Wrap(_errorFlagErr, "Error parsing 'errorFlag' field of ModbusPDU") + errorFlag, err := ReadDiscriminatorField[bool](ctx, "errorFlag", ReadBoolean(readBuffer)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'errorFlag' field")) } - // Discriminator Field (functionFlag) (Used as input to a switch field) - functionFlag, _functionFlagErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("functionFlag", 7) - if _functionFlagErr != nil { - return nil, errors.Wrap(_functionFlagErr, "Error parsing 'functionFlag' field of ModbusPDU") + functionFlag, err := ReadDiscriminatorField[uint8](ctx, "functionFlag", ReadUnsignedByte(readBuffer, 7)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'functionFlag' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/opcua/readwrite/model/MessagePDU.go b/plc4go/protocols/opcua/readwrite/model/MessagePDU.go index d593d452b2..1e9c201f9a 100644 --- a/plc4go/protocols/opcua/readwrite/model/MessagePDU.go +++ b/plc4go/protocols/opcua/readwrite/model/MessagePDU.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -145,10 +147,9 @@ func MessagePDUParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (messageType) (Used as input to a switch field) - messageType, _messageTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadString("messageType", uint32(24), utils.WithEncoding("UTF-8")) - if _messageTypeErr != nil { - return nil, errors.Wrap(_messageTypeErr, "Error parsing 'messageType' field of MessagePDU") + messageType, err := ReadDiscriminatorField[string](ctx, "messageType", ReadString(readBuffer, 24)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'messageType' field")) } // Simple Field (chunk) diff --git a/plc4go/protocols/opcua/readwrite/model/NodeIdTypeDefinition.go b/plc4go/protocols/opcua/readwrite/model/NodeIdTypeDefinition.go index 74b8aa89d5..b512d54c07 100644 --- a/plc4go/protocols/opcua/readwrite/model/NodeIdTypeDefinition.go +++ b/plc4go/protocols/opcua/readwrite/model/NodeIdTypeDefinition.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -137,17 +139,9 @@ func NodeIdTypeDefinitionParseWithBuffer(ctx context.Context, readBuffer utils.R currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (nodeType) (Used as input to a switch field) - if pullErr := readBuffer.PullContext("nodeType"); pullErr != nil { - return nil, errors.Wrap(pullErr, "Error pulling for nodeType") - } - nodeType_temp, _nodeTypeErr := NodeIdTypeParseWithBuffer(ctx, readBuffer) - var nodeType NodeIdType = nodeType_temp - if closeErr := readBuffer.CloseContext("nodeType"); closeErr != nil { - return nil, errors.Wrap(closeErr, "Error closing for nodeType") - } - if _nodeTypeErr != nil { - return nil, errors.Wrap(_nodeTypeErr, "Error parsing 'nodeType' field of NodeIdTypeDefinition") + nodeType, err := ReadDiscriminatorEnumField[NodeIdType](ctx, "nodeType", "NodeIdType", ReadEnum(NodeIdTypeByValue, ReadUnsignedByte(readBuffer, 6))) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'nodeType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/opcua/readwrite/model/Variant.go b/plc4go/protocols/opcua/readwrite/model/Variant.go index 6aa1accd36..f4eb176aee 100644 --- a/plc4go/protocols/opcua/readwrite/model/Variant.go +++ b/plc4go/protocols/opcua/readwrite/model/Variant.go @@ -191,10 +191,9 @@ func VariantParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (V } arrayDimensionsSpecified := _arrayDimensionsSpecified - // Discriminator Field (VariantType) (Used as input to a switch field) - VariantType, _VariantTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("VariantType", 6) - if _VariantTypeErr != nil { - return nil, errors.Wrap(_VariantTypeErr, "Error parsing 'VariantType' field of Variant") + VariantType, err := ReadDiscriminatorField[uint8](ctx, "VariantType", ReadUnsignedByte(readBuffer, 6)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'VariantType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/s7/readwrite/model/COTPPacket.go b/plc4go/protocols/s7/readwrite/model/COTPPacket.go index 00c6f67cdb..78b2e5b9c4 100644 --- a/plc4go/protocols/s7/readwrite/model/COTPPacket.go +++ b/plc4go/protocols/s7/readwrite/model/COTPPacket.go @@ -173,10 +173,9 @@ func COTPPacketParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, return nil, errors.Wrap(_headerLengthErr, "Error parsing 'headerLength' field of COTPPacket") } - // Discriminator Field (tpduCode) (Used as input to a switch field) - tpduCode, _tpduCodeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("tpduCode", 8) - if _tpduCodeErr != nil { - return nil, errors.Wrap(_tpduCodeErr, "Error parsing 'tpduCode' field of COTPPacket") + tpduCode, err := ReadDiscriminatorField[uint8](ctx, "tpduCode", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'tpduCode' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/s7/readwrite/model/COTPParameter.go b/plc4go/protocols/s7/readwrite/model/COTPParameter.go index bf41a633a7..ece383c54a 100644 --- a/plc4go/protocols/s7/readwrite/model/COTPParameter.go +++ b/plc4go/protocols/s7/readwrite/model/COTPParameter.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -125,10 +127,9 @@ func COTPParameterParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuff currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (parameterType) (Used as input to a switch field) - parameterType, _parameterTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("parameterType", 8) - if _parameterTypeErr != nil { - return nil, errors.Wrap(_parameterTypeErr, "Error parsing 'parameterType' field of COTPParameter") + parameterType, err := ReadDiscriminatorField[uint8](ctx, "parameterType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'parameterType' field")) } // Implicit Field (parameterLength) (Used for parsing, but its value is not stored as it's implicitly given by the objects content) diff --git a/plc4go/protocols/s7/readwrite/model/S7Address.go b/plc4go/protocols/s7/readwrite/model/S7Address.go index 16e9eff076..d6efe01a79 100644 --- a/plc4go/protocols/s7/readwrite/model/S7Address.go +++ b/plc4go/protocols/s7/readwrite/model/S7Address.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func S7AddressParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (addressType) (Used as input to a switch field) - addressType, _addressTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("addressType", 8) - if _addressTypeErr != nil { - return nil, errors.Wrap(_addressTypeErr, "Error parsing 'addressType' field of S7Address") + addressType, err := ReadDiscriminatorField[uint8](ctx, "addressType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'addressType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/s7/readwrite/model/S7Message.go b/plc4go/protocols/s7/readwrite/model/S7Message.go index 26399fa322..9747495a00 100644 --- a/plc4go/protocols/s7/readwrite/model/S7Message.go +++ b/plc4go/protocols/s7/readwrite/model/S7Message.go @@ -202,10 +202,9 @@ func S7MessageParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) } _ = protocolId - // Discriminator Field (messageType) (Used as input to a switch field) - messageType, _messageTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("messageType", 8) - if _messageTypeErr != nil { - return nil, errors.Wrap(_messageTypeErr, "Error parsing 'messageType' field of S7Message") + messageType, err := ReadDiscriminatorField[uint8](ctx, "messageType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'messageType' field")) } var reservedField0 *uint16 diff --git a/plc4go/protocols/s7/readwrite/model/S7Parameter.go b/plc4go/protocols/s7/readwrite/model/S7Parameter.go index b67f61cdd5..69c89733fc 100644 --- a/plc4go/protocols/s7/readwrite/model/S7Parameter.go +++ b/plc4go/protocols/s7/readwrite/model/S7Parameter.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -122,10 +124,9 @@ func S7ParameterParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (parameterType) (Used as input to a switch field) - parameterType, _parameterTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("parameterType", 8) - if _parameterTypeErr != nil { - return nil, errors.Wrap(_parameterTypeErr, "Error parsing 'parameterType' field of S7Parameter") + parameterType, err := ReadDiscriminatorField[uint8](ctx, "parameterType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'parameterType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/s7/readwrite/model/S7ParameterUserDataItem.go b/plc4go/protocols/s7/readwrite/model/S7ParameterUserDataItem.go index af64e808bb..f66b6f7909 100644 --- a/plc4go/protocols/s7/readwrite/model/S7ParameterUserDataItem.go +++ b/plc4go/protocols/s7/readwrite/model/S7ParameterUserDataItem.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func S7ParameterUserDataItemParseWithBuffer(ctx context.Context, readBuffer util currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (itemType) (Used as input to a switch field) - itemType, _itemTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("itemType", 8) - if _itemTypeErr != nil { - return nil, errors.Wrap(_itemTypeErr, "Error parsing 'itemType' field of S7ParameterUserDataItem") + itemType, err := ReadDiscriminatorField[uint8](ctx, "itemType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'itemType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/protocols/s7/readwrite/model/S7VarRequestParameterItem.go b/plc4go/protocols/s7/readwrite/model/S7VarRequestParameterItem.go index d1a8f56b16..1e0020ac17 100644 --- a/plc4go/protocols/s7/readwrite/model/S7VarRequestParameterItem.go +++ b/plc4go/protocols/s7/readwrite/model/S7VarRequestParameterItem.go @@ -26,6 +26,8 @@ import ( "github.com/pkg/errors" "github.com/rs/zerolog" + . "github.com/apache/plc4x/plc4go/spi/codegen/fields" + . "github.com/apache/plc4x/plc4go/spi/codegen/io" "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -119,10 +121,9 @@ func S7VarRequestParameterItemParseWithBuffer(ctx context.Context, readBuffer ut currentPos := positionAware.GetPos() _ = currentPos - // Discriminator Field (itemType) (Used as input to a switch field) - itemType, _itemTypeErr := /*TODO: migrate me*/ /*TODO: migrate me*/ readBuffer.ReadUint8("itemType", 8) - if _itemTypeErr != nil { - return nil, errors.Wrap(_itemTypeErr, "Error parsing 'itemType' field of S7VarRequestParameterItem") + itemType, err := ReadDiscriminatorField[uint8](ctx, "itemType", ReadUnsignedByte(readBuffer, 8)) + if err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("Error parsing 'itemType' field")) } // Switch Field (Depending on the discriminator values, passes the instantiation to a sub-type) diff --git a/plc4go/spi/codegen/io/DataReaderEnumDefault.go b/plc4go/spi/codegen/io/DataReaderEnumDefault.go index 4c9944b265..3810862b5c 100644 --- a/plc4go/spi/codegen/io/DataReaderEnumDefault.go +++ b/plc4go/spi/codegen/io/DataReaderEnumDefault.go @@ -23,26 +23,21 @@ import ( "context" "encoding/binary" - "github.com/pkg/errors" - "github.com/rs/zerolog" - "github.com/apache/plc4x/plc4go/spi/utils" + "github.com/pkg/errors" ) type DataReaderEnumDefault[T any, I any] struct { enumResolver func(I) (T, bool) dataReader DataReader[I] - - log zerolog.Logger } var _ DataReaderEnum[string] = (*DataReaderEnumDefault[string, string])(nil) -func NewDataReaderEnumDefault[T any, I any](enumResolver func(I) (T, bool), dataReader DataReader[I], logger zerolog.Logger) *DataReaderEnumDefault[T, I] { +func NewDataReaderEnumDefault[T any, I any](enumResolver func(I) (T, bool), dataReader DataReader[I]) *DataReaderEnumDefault[T, I] { return &DataReaderEnumDefault[T, I]{ enumResolver: enumResolver, dataReader: dataReader, - log: logger, } } @@ -69,8 +64,8 @@ func (d *DataReaderEnumDefault[T, I]) Read(ctx context.Context, logicalName stri return zero, errors.Wrap(err, "error reading raw data") } enumValue, ok := d.enumResolver(rawValue) - if !ok { // - d.log.Debug().Str("logicalName", logicalName).Interface("rawValue", rawValue).Msg("no enum value found") + if !ok { // TODO: decide if we want to log... maybe we always pass the context so we can extract that + //d.log.Debug().Str("logicalName", logicalName).Interface("rawValue", rawValue).Msg("no enum value found") } return enumValue, nil } diff --git a/plc4go/spi/codegen/io/DataReaderFactory.go b/plc4go/spi/codegen/io/DataReaderFactory.go index 64e3cd76da..0ab227b499 100644 --- a/plc4go/spi/codegen/io/DataReaderFactory.go +++ b/plc4go/spi/codegen/io/DataReaderFactory.go @@ -24,8 +24,6 @@ import ( "math/big" "time" - "github.com/rs/zerolog" - "github.com/apache/plc4x/plc4go/spi/utils" ) @@ -89,8 +87,8 @@ func ReadString(readBuffer utils.ReadBuffer, bitLength uint32) DataReader[string return NewDataReaderSimpleString(readBuffer, bitLength) } -func ReadEnum[T any, I any](enumResolver func(I) (T, bool), dataReader DataReader[I], logger zerolog.Logger) *DataReaderEnumDefault[T, I] { - return NewDataReaderEnumDefault[T, I](enumResolver, dataReader, logger) +func ReadEnum[T any, I any](enumResolver func(I) (T, bool), dataReader DataReader[I]) *DataReaderEnumDefault[T, I] { + return NewDataReaderEnumDefault[T, I](enumResolver, dataReader) } func ReadComplex[T any](complexSupplier func(context.Context, utils.ReadBuffer) (T, error), readBuffer utils.ReadBuffer) *DataReaderComplexDefault[T] {