From 9dce63af1fad7e3678d836ea4dae3fd64a1f379e Mon Sep 17 00:00:00 2001 From: Christofer Dutz Date: Mon, 8 Dec 2025 09:42:48 +0100 Subject: [PATCH 1/7] chore: Started defining the new buffer-api kicking off the SPI3 refactoring (At this state the project should not be buildable) --- plc4j/drivers/firmata/pom.xml | 56 ++ .../java/firmata/readwrite/FirmataIT.java | 303 ++++++++ .../readwrite/TestcontainerSupport.java | 58 ++ .../resources/firmata/StandardFirmata.ino | 289 +++++++ .../src/test/resources/firmata/libraries.txt | 1 + plc4j/drivers/pom.xml | 4 +- .../logback-test.xml => buffers/api/pom.xml} | 39 +- .../java/spi/buffers/api/AbstractBuffer.java | 73 ++ .../plc4x/java/spi/buffers/api/Buffer.java} | 14 +- .../plc4x/java/spi/buffers/api}/Message.java | 4 +- .../java/spi/buffers/api}/MessageInput.java | 7 +- .../java/spi/buffers/api}/MessageOutput.java | 9 +- .../java/spi/buffers/api/ReadBuffer.java | 203 +++++ .../java/spi/buffers/api}/Serializable.java | 9 +- .../java/spi/buffers/api/WithOption.java | 317 ++++++++ .../java/spi/buffers/api/WriteBuffer.java | 225 ++++++ .../api/exceptions/BufferException.java} | 11 +- .../api/exceptions/BufferValueException.java} | 13 +- plc4j/spi/buffers/ascii-box/pom.xml | 41 + plc4j/spi/buffers/byte/pom.xml | 41 + plc4j/spi/buffers/pom.xml | 46 ++ plc4j/spi/buffers/xml/pom.xml | 41 + plc4j/spi/pom.xml | 87 +-- .../plc4x/java/spi/ConversationContext.java | 159 ---- .../java/spi/EventListenerMessageCodec.java | 64 -- .../GeneratedDriverByteToMessageCodec.java | 110 --- .../plc4x/java/spi/Plc4xNettyWrapper.java | 279 ------- .../plc4x/java/spi/Plc4xProtocolBase.java | 104 --- .../java/spi/PlcMessageToMessageCodec.java | 60 -- .../apache/plc4x/java/spi/TimedOperation.java | 32 - .../apache/plc4x/java/spi/TimeoutManager.java | 40 - .../plc4x/java/spi/codegen/FieldCommons.java | 93 --- .../java/spi/codegen/ThreadLocalHelper.java | 26 - .../plc4x/java/spi/codegen/WithOption.java | 50 -- .../codegen/fields/FieldReaderAbstract.java | 37 - .../spi/codegen/fields/FieldReaderArray.java | 98 --- .../spi/codegen/fields/FieldReaderAssert.java | 48 -- .../codegen/fields/FieldReaderChecksum.java | 43 -- .../spi/codegen/fields/FieldReaderConst.java | 43 -- .../fields/FieldReaderDiscriminator.java | 37 - .../fields/FieldReaderDiscriminatorEnum.java | 41 - .../spi/codegen/fields/FieldReaderEnum.java | 41 - .../codegen/fields/FieldReaderFactory.java | 152 ---- .../codegen/fields/FieldReaderImplicit.java | 37 - .../spi/codegen/fields/FieldReaderManual.java | 41 - .../fields/FieldReaderManualArray.java | 77 -- .../codegen/fields/FieldReaderOptional.java | 82 -- .../codegen/fields/FieldReaderPadding.java | 50 -- .../spi/codegen/fields/FieldReaderPeek.java | 47 -- .../codegen/fields/FieldReaderReserved.java | 44 -- .../spi/codegen/fields/FieldReaderSimple.java | 37 - .../codegen/fields/FieldReaderTypeSwitch.java | 37 - .../codegen/fields/FieldReaderUnknown.java | 39 - .../codegen/fields/FieldReaderVirtual.java | 88 --- .../spi/codegen/fields/FieldWriterArray.java | 71 -- .../codegen/fields/FieldWriterChecksum.java | 37 - .../spi/codegen/fields/FieldWriterConst.java | 37 - .../fields/FieldWriterDiscriminator.java | 37 - .../fields/FieldWriterDiscriminatorEnum.java | 39 - .../spi/codegen/fields/FieldWriterEnum.java | 39 - .../codegen/fields/FieldWriterFactory.java | 114 --- .../codegen/fields/FieldWriterImplicit.java | 37 - .../spi/codegen/fields/FieldWriterManual.java | 37 - .../fields/FieldWriterManualArray.java | 45 -- .../codegen/fields/FieldWriterOptional.java | 63 -- .../fields/FieldWriterOptionalEnum.java | 64 -- .../codegen/fields/FieldWriterPadding.java | 44 -- .../codegen/fields/FieldWriterReserved.java | 37 - .../spi/codegen/fields/FieldWriterSimple.java | 37 - .../codegen/fields/FieldWriterSimpleEnum.java | 39 - .../java/spi/codegen/io/ByteOrderAware.java | 27 - .../spi/codegen/io/ComplexTypeSupplier.java | 28 - .../java/spi/codegen/io/ContextReader.java | 28 - .../java/spi/codegen/io/ContextWriter.java | 27 - .../plc4x/java/spi/codegen/io/DataReader.java | 31 - .../spi/codegen/io/DataReaderComplex.java | 28 - .../codegen/io/DataReaderComplexDefault.java | 93 --- .../java/spi/codegen/io/DataReaderEnum.java | 28 - .../spi/codegen/io/DataReaderEnumDefault.java | 91 --- .../spi/codegen/io/DataReaderFactory.java | 111 --- .../spi/codegen/io/DataReaderSimpleBase.java | 68 -- .../io/DataReaderSimpleBigDecimal.java | 38 - .../codegen/io/DataReaderSimpleBoolean.java | 36 - .../spi/codegen/io/DataReaderSimpleByte.java | 39 - .../codegen/io/DataReaderSimpleByteArray.java | 39 - .../spi/codegen/io/DataReaderSimpleDate.java | 40 - .../codegen/io/DataReaderSimpleDateTime.java | 39 - .../codegen/io/DataReaderSimpleDouble.java | 36 - .../spi/codegen/io/DataReaderSimpleFloat.java | 36 - .../io/DataReaderSimpleSignedBigInteger.java | 38 - .../io/DataReaderSimpleSignedByte.java | 36 - .../codegen/io/DataReaderSimpleSignedInt.java | 36 - .../io/DataReaderSimpleSignedLong.java | 36 - .../io/DataReaderSimpleSignedShort.java | 36 - .../codegen/io/DataReaderSimpleString.java | 36 - .../spi/codegen/io/DataReaderSimpleTime.java | 40 - .../DataReaderSimpleUnsignedBigInteger.java | 38 - .../io/DataReaderSimpleUnsignedByte.java | 36 - .../io/DataReaderSimpleUnsignedInt.java | 36 - .../io/DataReaderSimpleUnsignedLong.java | 36 - .../io/DataReaderSimpleUnsignedShort.java | 36 - .../plc4x/java/spi/codegen/io/DataWriter.java | 31 - .../spi/codegen/io/DataWriterComplex.java | 23 - .../codegen/io/DataWriterComplexDefault.java | 77 -- .../codegen/io/DataWriterDataIoDefault.java | 72 -- .../java/spi/codegen/io/DataWriterEnum.java | 28 - .../spi/codegen/io/DataWriterEnumDefault.java | 81 -- .../spi/codegen/io/DataWriterFactory.java | 120 --- .../spi/codegen/io/DataWriterSimpleBase.java | 61 -- .../io/DataWriterSimpleBigDecimal.java | 38 - .../codegen/io/DataWriterSimpleBoolean.java | 39 - .../spi/codegen/io/DataWriterSimpleByte.java | 39 - .../codegen/io/DataWriterSimpleByteArray.java | 40 - .../spi/codegen/io/DataWriterSimpleDate.java | 38 - .../codegen/io/DataWriterSimpleDateTime.java | 40 - .../codegen/io/DataWriterSimpleDouble.java | 36 - .../spi/codegen/io/DataWriterSimpleFloat.java | 36 - .../io/DataWriterSimpleSignedBigInteger.java | 38 - .../io/DataWriterSimpleSignedByte.java | 36 - .../codegen/io/DataWriterSimpleSignedInt.java | 36 - .../io/DataWriterSimpleSignedLong.java | 36 - .../io/DataWriterSimpleSignedShort.java | 36 - .../codegen/io/DataWriterSimpleString.java | 36 - .../spi/codegen/io/DataWriterSimpleTime.java | 40 - .../DataWriterSimpleUnsignedBigInteger.java | 38 - .../io/DataWriterSimpleUnsignedByte.java | 36 - .../io/DataWriterSimpleUnsignedInt.java | 36 - .../io/DataWriterSimpleUnsignedLong.java | 36 - .../io/DataWriterSimpleUnsignedShort.java | 36 - .../java/spi/codegen/io/ParseSupplier.java | 28 - .../java/spi/codegen/io/PositionMover.java | 26 - .../plc4x/java/spi/codegen/io/VintIo.java | 69 -- .../configuration/ConfigurationFactory.java | 343 -------- .../ConfigurationParameterConverter.java | 44 -- .../spi/configuration/HasConfiguration.java | 35 - .../spi/configuration/PlcConfiguration.java | 23 - .../PlcConnectionConfiguration.java | 23 - .../PlcTransportConfiguration.java | 22 - .../ComplexConfigurationParameter.java | 36 - ...ConfigurationParameterDefaultOverride.java | 27 - ...onfigurationParameterRequiredOverride.java | 27 - .../annotations/ConfigurationParameter.java | 32 - .../annotations/Description.java | 32 - .../annotations/ParameterConverter.java | 41 - .../configuration/annotations/Required.java | 29 - .../spi/configuration/annotations/Since.java | 32 - .../defaults/BooleanDefaultValue.java | 32 - .../defaults/DoubleDefaultValue.java | 32 - .../defaults/FloatDefaultValue.java | 32 - .../annotations/defaults/IntDefaultValue.java | 32 - .../defaults/LongDefaultValue.java | 32 - .../defaults/StringDefaultValue.java | 32 - .../exceptions/ConfigurationException.java | 34 - .../spi/connection/AbstractPlcConnection.java | 396 ---------- .../connection/ChannelExposingConnection.java | 27 - .../java/spi/connection/ChannelFactory.java | 42 - .../CustomProtocolStackConfigurer.java | 188 ----- .../connection/DefaultNettyPlcConnection.java | 304 -------- .../spi/connection/EncryptionHandler.java | 71 -- .../spi/connection/GeneratedDriverBase.java | 448 ----------- .../GeneratedProtocolMessageCodec.java | 71 -- .../spi/connection/NettyChannelFactory.java | 168 ---- .../java/spi/connection/PlcTagHandler.java | 33 - .../connection/ProtocolStackConfigurer.java | 34 - .../SingleProtocolStackConfigurer.java | 204 ----- .../plc4x/java/spi/context/DriverContext.java | 22 - .../java/spi/discovery/ActiveDiscovery.java | 25 - .../spi/discovery/BroadcastDiscovery.java | 25 - .../java/spi/discovery/PassiveDiscovery.java | 25 - .../java/spi/discovery/SupportsDiscovery.java | 25 - .../java/spi/events/CloseConnectionEvent.java | 23 - .../plc4x/java/spi/events/ConnectEvent.java | 22 - .../plc4x/java/spi/events/ConnectedEvent.java | 22 - .../java/spi/events/DisconnectEvent.java | 39 - .../java/spi/events/DisconnectedEvent.java | 22 - .../plc4x/java/spi/events/DiscoverEvent.java | 24 - .../java/spi/events/DiscoveredEvent.java | 33 - .../java/spi/generation/BufferCommons.java | 97 --- .../plc4x/java/spi/generation/ByteOrder.java | 24 - .../java/spi/generation/EvaluationHelper.java | 71 -- .../spi/generation/ParseAssertException.java | 33 - .../generation/ParseValidationException.java | 33 - .../java/spi/generation/PositionAware.java | 23 - .../plc4x/java/spi/generation/ReadBuffer.java | 139 ---- .../spi/generation/ReadBufferByteBased.java | 731 ------------------ .../spi/generation/ReadBufferJsonBased.java | 428 ---------- .../spi/generation/ReadBufferXmlBased.java | 300 ------- .../java/spi/generation/StaticHelper.java | 161 ---- .../java/spi/generation/WithReaderArgs.java | 22 - .../spi/generation/WithReaderWriterArgs.java | 75 -- .../java/spi/generation/WithWriterArgs.java | 22 - .../java/spi/generation/WriteBuffer.java | 153 ---- .../spi/generation/WriteBufferBoxBased.java | 289 ------- .../spi/generation/WriteBufferByteBased.java | 629 --------------- .../spi/generation/WriteBufferJsonBased.java | 350 --------- .../spi/generation/WriteBufferXmlBased.java | 289 ------- .../spi/generation/io/MyDefaultBitInput.java | 61 -- .../spi/generation/io/MyDefaultBitOutput.java | 36 - .../spi/internal/DefaultContextHandler.java | 49 -- .../internal/DefaultConversationContext.java | 106 --- .../internal/DefaultExpectRequestContext.java | 130 ---- .../internal/DefaultSendRequestContext.java | 191 ----- .../spi/internal/HandlerRegistration.java | 172 ----- .../spi/messages/DefaultPlcBrowseItem.java | 177 ----- .../spi/messages/DefaultPlcBrowseRequest.java | 107 --- .../messages/DefaultPlcBrowseResponse.java | 70 -- .../spi/messages/DefaultPlcDiscoveryItem.java | 140 ---- .../messages/DefaultPlcDiscoveryRequest.java | 94 --- .../messages/DefaultPlcDiscoveryResponse.java | 65 -- .../spi/messages/DefaultPlcPingRequest.java | 49 -- .../spi/messages/DefaultPlcPingResponse.java | 62 -- .../spi/messages/DefaultPlcReadRequest.java | 170 ---- .../spi/messages/DefaultPlcReadResponse.java | 689 ----------------- .../messages/DefaultPlcSubscriptionEvent.java | 63 -- .../DefaultPlcSubscriptionRequest.java | 301 -------- .../DefaultPlcSubscriptionResponse.java | 125 --- .../DefaultPlcUnsubscriptionRequest.java | 102 --- .../DefaultPlcUnsubscriptionResponse.java | 46 -- .../spi/messages/DefaultPlcWriteRequest.java | 213 ----- .../spi/messages/DefaultPlcWriteResponse.java | 119 --- .../plc4x/java/spi/messages/PlcBrowser.java | 42 - .../java/spi/messages/PlcDiscoverer.java | 42 - .../plc4x/java/spi/messages/PlcPinger.java | 31 - .../java/spi/messages/PlcProtocolMessage.java | 25 - .../plc4x/java/spi/messages/PlcReader.java | 39 - .../spi/messages/PlcRequestContainer.java | 88 --- .../java/spi/messages/PlcSubscriber.java | 70 -- .../plc4x/java/spi/messages/PlcWriter.java | 39 - .../utils/DefaultPlcResponseItem.java | 67 -- .../utils/DefaultPlcTagErrorItem.java | 47 -- .../spi/messages/utils/DefaultPlcTagItem.java | 50 -- .../utils/DefaultPlcTagValueItem.java | 56 -- .../spi/messages/utils/PlcResponseItem.java | 30 - .../java/spi/messages/utils/PlcTagItem.java | 35 - .../spi/messages/utils/PlcTagValueItem.java | 30 - .../java/spi/metadata/DefaultMetadata.java | 132 ---- .../java/spi/metadata/DefaultOption.java | 75 -- .../spi/metadata/DefaultOptionMetadata.java | 46 -- .../java/spi/model/DefaultArrayInfo.java | 48 -- .../model/DefaultPlcConsumerRegistration.java | 87 --- .../model/DefaultPlcSubscriptionHandle.java | 65 -- .../spi/model/DefaultPlcSubscriptionTag.java | 83 -- .../netty/NettyHashTimerTimeoutManager.java | 80 -- .../java/spi/optimizer/BaseOptimizer.java | 243 ------ .../spi/optimizer/SingleTagOptimizer.java | 76 -- .../plc4x/java/spi/tag/TagConfigParser.java | 63 -- .../RequestTransactionManager.java | 232 ------ .../plc4x/java/spi/transport/Transport.java | 36 - .../plc4x/java/spi/utils/ascii/AsciiBox.java | 122 --- .../java/spi/utils/ascii/AsciiBoxWriter.java | 317 -------- .../java/spi/utils/ascii/AsciiBoxer.java | 34 - .../plc4x/java/spi/utils/ascii/BoxSet.java | 78 -- .../apache/plc4x/java/spi/utils/hex/Hex.java | 184 ----- .../spi/values/DefaultPlcValueHandler.java | 275 ------- .../spi/values/LegacyPlcValueHandler.java | 264 ------- .../apache/plc4x/java/spi/values/PlcBOOL.java | 275 ------- .../apache/plc4x/java/spi/values/PlcBYTE.java | 288 ------- .../apache/plc4x/java/spi/values/PlcCHAR.java | 326 -------- .../apache/plc4x/java/spi/values/PlcDATE.java | 195 ----- .../java/spi/values/PlcDATE_AND_LTIME.java | 215 ------ .../java/spi/values/PlcDATE_AND_TIME.java | 236 ------ .../apache/plc4x/java/spi/values/PlcDINT.java | 264 ------- .../plc4x/java/spi/values/PlcDWORD.java | 291 ------- .../plc4x/java/spi/values/PlcIECValue.java | 84 -- .../apache/plc4x/java/spi/values/PlcINT.java | 266 ------- .../plc4x/java/spi/values/PlcLDATE.java | 189 ----- .../java/spi/values/PlcLDATE_AND_TIME.java | 205 ----- .../apache/plc4x/java/spi/values/PlcLINT.java | 265 ------- .../plc4x/java/spi/values/PlcLREAL.java | 261 ------- .../plc4x/java/spi/values/PlcLTIME.java | 187 ----- .../java/spi/values/PlcLTIME_OF_DAY.java | 161 ---- .../plc4x/java/spi/values/PlcLWORD.java | 305 -------- .../apache/plc4x/java/spi/values/PlcList.java | 96 --- .../apache/plc4x/java/spi/values/PlcNull.java | 295 ------- .../apache/plc4x/java/spi/values/PlcREAL.java | 255 ------ .../java/spi/values/PlcRawByteArray.java | 80 -- .../apache/plc4x/java/spi/values/PlcSINT.java | 267 ------- .../plc4x/java/spi/values/PlcSTRING.java | 217 ------ .../plc4x/java/spi/values/PlcStruct.java | 102 --- .../apache/plc4x/java/spi/values/PlcTIME.java | 171 ---- .../plc4x/java/spi/values/PlcTIME_OF_DAY.java | 160 ---- .../plc4x/java/spi/values/PlcUDINT.java | 283 ------- .../apache/plc4x/java/spi/values/PlcUINT.java | 275 ------- .../plc4x/java/spi/values/PlcULINT.java | 295 ------- .../plc4x/java/spi/values/PlcUSINT.java | 277 ------- .../java/spi/values/PlcValueAdapter.java | 326 -------- .../java/spi/values/PlcValueHandler.java | 29 - .../plc4x/java/spi/values/PlcValues.java | 86 --- .../plc4x/java/spi/values/PlcWCHAR.java | 300 ------- .../apache/plc4x/java/spi/values/PlcWORD.java | 285 ------- .../plc4x/java/spi/values/PlcWSTRING.java | 217 ------ .../plc4x/java/spi/Plc4xNettyWrapperTest.java | 173 ----- .../plc4x/java/spi/codegen/io/VintIoTest.java | 65 -- .../ConfigurationFactoryTest.java | 122 --- .../config/ParameterConverterType.java | 34 - .../ParameterConverterTypeConverter.java | 36 - .../config/TestConfigurationComplex.java | 34 - .../config/TestConfigurationDefaults.java | 76 -- .../TestConfigurationParameterConverter.java | 36 - .../config/TestConfigurationRequired.java | 76 -- .../config/TestConfigurationSimple.java | 69 -- .../DefaultNettyPlcConnectionTest.java | 215 ------ .../plc4x/java/spi/connection/GateKeeper.java | 83 -- .../spi/connection/PlcConnectionFactory.java | 55 -- .../SingleProtocolStackConfigurerTest.java | 122 --- .../spi/connection/TestChannelFactory.java | 46 -- .../java/spi/connection/TestMessage.java | 77 -- .../java/spi/connection/TestProtocol.java | 60 -- .../java/spi/generation/ReadBufferTest.java | 56 -- .../generation/UnsignedBigIntegerTest.java | 140 ---- .../plc4x/java/spi/generation/VarIntTest.java | 96 --- .../DefaultSendRequestContextTest.java | 116 --- .../RequestTransactionManagerTest.java | 173 ----- .../java/spi/parser/ConnectionParserTest.java | 71 -- .../java/spi/tag/TagTagConfigParserTest.java | 62 -- .../spi/utils/ascii/AsciiBoxWriterTest.java | 625 --------------- .../plc4x/java/spi/utils/hex/HexTest.java | 271 ------- .../values/DefaultPlcValueHandlerTest.java | 573 -------------- plc4j/transports/pom.xml | 4 +- 319 files changed, 1765 insertions(+), 31001 deletions(-) create mode 100644 plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/FirmataIT.java create mode 100644 plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/TestcontainerSupport.java create mode 100644 plc4j/drivers/firmata/src/test/resources/firmata/StandardFirmata.ino create mode 100644 plc4j/drivers/firmata/src/test/resources/firmata/libraries.txt rename plc4j/spi/{src/test/resources/logback-test.xml => buffers/api/pom.xml} (56%) create mode 100644 plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/AbstractBuffer.java rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/codegen/io/DataIoSerializerFunction.java => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Buffer.java} (72%) rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/generation => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api}/Message.java (90%) rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/generation => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api}/MessageInput.java (82%) rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/generation => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api}/MessageOutput.java (75%) create mode 100644 plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/ReadBuffer.java rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/utils => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api}/Serializable.java (78%) create mode 100644 plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WithOption.java create mode 100644 plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WriteBuffer.java rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/generation/ParseException.java => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferException.java} (77%) rename plc4j/spi/{src/main/java/org/apache/plc4x/java/spi/generation/SerializationException.java => buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferValueException.java} (74%) create mode 100644 plc4j/spi/buffers/ascii-box/pom.xml create mode 100644 plc4j/spi/buffers/byte/pom.xml create mode 100644 plc4j/spi/buffers/pom.xml create mode 100644 plc4j/spi/buffers/xml/pom.xml delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/EventListenerMessageCodec.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xProtocolBase.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/PlcMessageToMessageCodec.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimedOperation.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/FieldCommons.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/ThreadLocalHelper.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/WithOption.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAbstract.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAssert.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderChecksum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderConst.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminator.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminatorEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderImplicit.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManual.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManualArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderOptional.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPadding.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPeek.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderReserved.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderSimple.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderTypeSwitch.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderUnknown.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderVirtual.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterChecksum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterConst.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminator.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminatorEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterImplicit.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManual.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManualArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptional.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptionalEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterPadding.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterReserved.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimple.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimpleEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ByteOrderAware.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ComplexTypeSupplier.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextReader.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextWriter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReader.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplex.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplexDefault.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnumDefault.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBase.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBigDecimal.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBoolean.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByteArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDate.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDateTime.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDouble.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleFloat.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedBigInteger.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedInt.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedLong.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedShort.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleString.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleTime.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedBigInteger.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedInt.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedLong.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedShort.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplex.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplexDefault.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterDataIoDefault.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnum.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnumDefault.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBase.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBigDecimal.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBoolean.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByteArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDate.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDateTime.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDouble.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleFloat.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedBigInteger.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedInt.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedLong.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedShort.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleString.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleTime.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedBigInteger.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedByte.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedInt.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedLong.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedShort.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ParseSupplier.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/PositionMover.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/VintIo.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationParameterConverter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/HasConfiguration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConfiguration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConnectionConfiguration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcTransportConfiguration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterDefaultOverride.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterRequiredOverride.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ConfigurationParameter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Description.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ParameterConverter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Required.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Since.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/BooleanDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/DoubleDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/FloatDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/IntDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/LongDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/StringDefaultValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/exceptions/ConfigurationException.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/AbstractPlcConnection.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelExposingConnection.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/CustomProtocolStackConfigurer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/EncryptionHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/GeneratedDriverBase.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/GeneratedProtocolMessageCodec.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/NettyChannelFactory.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/PlcTagHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ProtocolStackConfigurer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/context/DriverContext.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/discovery/ActiveDiscovery.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/discovery/BroadcastDiscovery.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/discovery/PassiveDiscovery.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/discovery/SupportsDiscovery.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/CloseConnectionEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/ConnectEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/ConnectedEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/DisconnectEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/DisconnectedEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/DiscoverEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/events/DiscoveredEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/BufferCommons.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ByteOrder.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/EvaluationHelper.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ParseAssertException.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ParseValidationException.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/PositionAware.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBuffer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBufferByteBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBufferJsonBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ReadBufferXmlBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/StaticHelper.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WithReaderArgs.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WithReaderWriterArgs.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WithWriterArgs.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferByteBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferJsonBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferXmlBased.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/io/MyDefaultBitInput.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/io/MyDefaultBitOutput.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultContextHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultConversationContext.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultExpectRequestContext.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContext.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/internal/HandlerRegistration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcBrowseResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcDiscoveryResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcPingRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcPingResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcReadRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcReadResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionEvent.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcSubscriptionResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcUnsubscriptionRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcUnsubscriptionResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcWriteRequest.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/DefaultPlcWriteResponse.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcBrowser.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcDiscoverer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcPinger.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcProtocolMessage.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcReader.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcRequestContainer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcSubscriber.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/PlcWriter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/DefaultPlcResponseItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/DefaultPlcTagErrorItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/DefaultPlcTagItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/DefaultPlcTagValueItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/PlcResponseItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/PlcTagItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/messages/utils/PlcTagValueItem.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/metadata/DefaultMetadata.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/metadata/DefaultOption.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/metadata/DefaultOptionMetadata.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/model/DefaultArrayInfo.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/model/DefaultPlcConsumerRegistration.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/model/DefaultPlcSubscriptionHandle.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/model/DefaultPlcSubscriptionTag.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/netty/NettyHashTimerTimeoutManager.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/SingleTagOptimizer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/tag/TagConfigParser.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/transaction/RequestTransactionManager.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/transport/Transport.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/ascii/AsciiBox.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/ascii/AsciiBoxWriter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/ascii/AsciiBoxer.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/ascii/BoxSet.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/hex/Hex.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/DefaultPlcValueHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/LegacyPlcValueHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcBOOL.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcBYTE.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcCHAR.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_LTIME.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_TIME.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDWORD.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcIECValue.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE_AND_TIME.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLREAL.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME_OF_DAY.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLWORD.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcList.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcNull.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcREAL.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcRawByteArray.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcSINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcSTRING.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcStruct.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME_OF_DAY.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcUDINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcUINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcULINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcUSINT.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcValueAdapter.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcValueHandler.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcValues.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcWCHAR.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcWORD.java delete mode 100644 plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcWSTRING.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/Plc4xNettyWrapperTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/codegen/io/VintIoTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactoryTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/ParameterConverterType.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/ParameterConverterTypeConverter.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/TestConfigurationComplex.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/TestConfigurationDefaults.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/TestConfigurationParameterConverter.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/TestConfigurationRequired.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/configuration/config/TestConfigurationSimple.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnectionTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/GateKeeper.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/PlcConnectionFactory.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/SingleProtocolStackConfigurerTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/TestChannelFactory.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/TestMessage.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/connection/TestProtocol.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/generation/ReadBufferTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/generation/UnsignedBigIntegerTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/generation/VarIntTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/internal/DefaultSendRequestContextTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/optimizer/RequestTransactionManagerTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/parser/ConnectionParserTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/tag/TagTagConfigParserTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/utils/ascii/AsciiBoxWriterTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/utils/hex/HexTest.java delete mode 100644 plc4j/spi/src/test/java/org/apache/plc4x/java/spi/values/DefaultPlcValueHandlerTest.java diff --git a/plc4j/drivers/firmata/pom.xml b/plc4j/drivers/firmata/pom.xml index 8dbf53dabef..cd219426845 100644 --- a/plc4j/drivers/firmata/pom.xml +++ b/plc4j/drivers/firmata/pom.xml @@ -134,6 +134,62 @@ test + + + org.testcontainers + testcontainers + 2.0.2 + test + + + org.testcontainers + testcontainers-junit-jupiter + 2.0.2 + test + + + io.github.pfichtner + testcontainers-virtualavr + 0.0.2-SNAPSHOT + test + + + + + io.github.java-native + jssc + 2.10.2 + test + + + org.assertj + assertj-core + 3.27.6 + test + + + org.awaitility + awaitility + 4.3.0 + test + + + + + org.java-websocket + Java-WebSocket + 1.6.0 + test + + + + + com.google.code.gson + gson + 2.11.0 + test + + org.apache.plc4x plc4j-utils-test-utils diff --git a/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/FirmataIT.java b/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/FirmataIT.java new file mode 100644 index 00000000000..12d88cc5ef2 --- /dev/null +++ b/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/FirmataIT.java @@ -0,0 +1,303 @@ +package org.apache.plc4x.java.firmata.readwrite; + +import com.github.pfichtner.testcontainers.virtualavr.VirtualAvrConnection; +import com.github.pfichtner.testcontainers.virtualavr.VirtualAvrContainer; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.PlcDriverManager; +import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; +import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse; +import org.junit.jupiter.api.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testcontainers.images.ImagePullPolicy; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Integration test for the Firmata driver using VirtualAVR in TestContainers. + *

+ * This test simulates: + * - Analog input (A0): Sine wave from 0 to 1023 + * - Digital inputs (pins 2-5): 4-bit counter cycling 0-15 + *

+ * The test verifies that the Firmata driver correctly receives these values + * through subscriptions. + *

+ * NOTE: Each test uses @TestInstance(PER_METHOD) with @Container to get a fresh + * container instance. This is necessary because the socat TCP-to-PTY bridge on + * macOS doesn't handle connection reuse well, and the Arduino needs a clean state + * for each test. + */ +@Testcontainers(disabledWithoutDocker = true) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class FirmataIT { + + private static final Logger LOGGER = LoggerFactory.getLogger(FirmataIT.class); + + // Pin configuration + private static final String ANALOG_PIN_A0 = "A0"; // Analog pin for sine wave + private static final int[] DIGITAL_PINS = {2, 3, 4, 5}; // 4 digital pins for counter + + // Simulation parameters + private static final double SINE_WAVE_PERIOD_MS = 2000; // 2-second period + private static final int COUNTER_INCREMENT_MS = 500; // Increment every 500ms + + // Container is created fresh for each test method + @Container + VirtualAvrContainer virtualavr = TestcontainerSupport.virtualAvrContainer(loadClasspath("/firmata/StandardFirmata.ino")) + .withBaudrate(57600); + + static File loadClasspath(String name) { + try { + return new File(Objects.requireNonNull(FirmataIT.class.getResource(name)).toURI()); + } catch (URISyntaxException e) { + throw new IllegalStateException(e); + } + } + + private ScheduledExecutorService simulationExecutor; + private ScheduledFuture sineWaveFuture; + private ScheduledFuture counterFuture; + + @BeforeEach + void setup() { + simulationExecutor = Executors.newScheduledThreadPool(2); + startSimulation(); + } + + @AfterEach + void teardown() { + stopSimulation(); + if (simulationExecutor != null) { + simulationExecutor.shutdown(); + try { + if (!simulationExecutor.awaitTermination(5, TimeUnit.SECONDS)) { + simulationExecutor.shutdownNow(); + } + } catch (InterruptedException e) { + simulationExecutor.shutdownNow(); + Thread.currentThread().interrupt(); + } + LOGGER.info("Simulation executor terminated"); + } + } + + /** + * Start the pin value simulation. + * - Sine wave on analog pin A0 (0-1023) + * - 4-bit counter on digital pins 2-5 (0-15) + */ + private void startSimulation() { + VirtualAvrConnection avrConnection = virtualavr.avr(); + + // Sine wave simulation on A0 + AtomicInteger sinePhase = new AtomicInteger(0); + sineWaveFuture = simulationExecutor.scheduleAtFixedRate(() -> { + try { + int phase = sinePhase.getAndIncrement(); + double radians = (2 * Math.PI * phase) / (SINE_WAVE_PERIOD_MS / 100); + int value = (int) ((Math.sin(radians) + 1) * 511.5); // Map -1..1 to 0..1023 + avrConnection.pinState(ANALOG_PIN_A0, value); + LOGGER.debug("Sine wave: phase={}, value={}", phase, value); + } catch (Exception e) { + LOGGER.error("Error in sine wave simulation", e); + } + }, 0, 50, TimeUnit.MILLISECONDS); + + // Counter simulation on digital pins + AtomicInteger counter = new AtomicInteger(0); + counterFuture = simulationExecutor.scheduleAtFixedRate(() -> { + try { + int count = counter.getAndIncrement() % 16; + for (int i = 0; i < DIGITAL_PINS.length; i++) { + boolean bitValue = ((count >> i) & 1) == 1; + avrConnection.pinState(String.valueOf(DIGITAL_PINS[i]), bitValue); + } + LOGGER.debug("Counter: {} (binary: {})", count, Integer.toBinaryString(count)); + } catch (Exception e) { + LOGGER.error("Error in counter simulation", e); + } + }, 0, COUNTER_INCREMENT_MS, TimeUnit.MILLISECONDS); + + LOGGER.info("Simulation started: Sine wave on {}, Counter on pins {}-{}", + ANALOG_PIN_A0, DIGITAL_PINS[0], DIGITAL_PINS[DIGITAL_PINS.length - 1]); + } + + private void stopSimulation() { + // Cancel any running scheduled tasks + if (sineWaveFuture != null) { + sineWaveFuture.cancel(false); + sineWaveFuture = null; + } + if (counterFuture != null) { + counterFuture.cancel(false); + counterFuture = null; + } + } + + @Test + @Order(1) + @DisplayName("Test analog pins (sine wave simulation)") + void testAnalogInputs() throws Exception { + String serialDevicePath = virtualavr.serialPortDescriptor(); + LOGGER.info("Started virtual serial port on {}", serialDevicePath); + + boolean received; + List receivedValues = new CopyOnWriteArrayList<>(); + CountDownLatch valuesReceived = new CountDownLatch(20); + + // Create a connection using the serialDevicePath and subscribe to analog pin A0 + try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection("firmata://" + serialDevicePath + "?serial.baud-rate=57600")) { //&log.driver-testsuite-file=audit-log.txt + PlcSubscriptionResponse subscriptionResponse = connection.subscriptionRequestBuilder() + .addChangeOfStateTagAddress(ANALOG_PIN_A0, "analog:0", plcSubscriptionEvent -> { + LOGGER.info("Received event: {}", plcSubscriptionEvent.getPlcValue(ANALOG_PIN_A0).getInteger()); + receivedValues.add(plcSubscriptionEvent.getPlcValue(ANALOG_PIN_A0).getInteger()); + valuesReceived.countDown(); + }) + .build() + .execute().get(1000, TimeUnit.MILLISECONDS); + + // Wait for values (longer timeout for QEMU emulation) + received = valuesReceived.await(15, TimeUnit.SECONDS); + + // Unsubscribe from all subscriptions + connection.unsubscriptionRequestBuilder() + .addHandles(subscriptionResponse.getSubscriptionHandles()); + } + + assertTrue(received || receivedValues.size() > 5, + "Should receive multiple analog values"); + + // Verify values are in the expected range + for (int value : receivedValues) { + assertTrue(value >= 0 && value <= 1023, + "Analog value should be between 0 and 1023, got: " + value); + } + + // Verify we see variation (sine wave should produce different values) + if (receivedValues.size() > 5) { + int min = receivedValues.stream().mapToInt(Integer::intValue).min().orElse(0); + int max = receivedValues.stream().mapToInt(Integer::intValue).max().orElse(1023); + assertTrue(max - min > 100, + "Should see significant variation in sine wave values"); + } + + LOGGER.info("Received {} analog values, range: {} to {}", + receivedValues.size(), + receivedValues.stream().mapToInt(Integer::intValue).min().orElse(-1), + receivedValues.stream().mapToInt(Integer::intValue).max().orElse(-1)); + } + + @Test + @Order(2) + @DisplayName("Test digital pins (4-bit counter simulation)") + void testDigitalInputs() throws Exception { + String serialDevicePath = virtualavr.serialPortDescriptor(); + LOGGER.info("Started virtual serial port on {}", serialDevicePath); + + boolean received; + List receivedCounterValues = new CopyOnWriteArrayList<>(); + CountDownLatch valuesReceived = new CountDownLatch(16); + + // Create a connection using the serialDevicePath and subscribe to digital pins + try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection("firmata://" + serialDevicePath + "?serial.baud-rate=57600&log.driver-testsuite-file=audit-log.txt")) { + PlcSubscriptionRequest.Builder builder = connection.subscriptionRequestBuilder(); + for (int pin : DIGITAL_PINS) { + builder.addChangeOfStateTagAddress(String.valueOf(pin), "digital:" + pin); + } + builder.setConsumer(plcSubscriptionEvent -> { + LOGGER.info("Received event: {}", plcSubscriptionEvent); + for (String tagName : plcSubscriptionEvent.getTagNames()) { + int integer = plcSubscriptionEvent.getPlcValue(tagName).getInteger(); + receivedCounterValues.add(integer); + } + valuesReceived.countDown(); + }); + PlcSubscriptionResponse subscriptionResponse = builder + .build() + .execute().get(1000, TimeUnit.MILLISECONDS); + + // Wait for values (longer timeout for QEMU emulation) + received = valuesReceived.await(15, TimeUnit.SECONDS); + + // Unsubscribe from all subscriptions + connection.unsubscriptionRequestBuilder() + .addHandles(subscriptionResponse.getSubscriptionHandles()) + .build().execute().get(1000, TimeUnit.MILLISECONDS); + } + + assertTrue(received || receivedCounterValues.size() > 3, + "Should receive multiple counter values"); + + // Verify values are in the expected range (0-15) + for (int value : receivedCounterValues) { + assertTrue(value >= 0 && value <= 15, + "Counter value should be between 0 and 15, got: " + value); + } + + LOGGER.info("Received {} counter state changes", receivedCounterValues.size()); + } + + @Test + @Order(3) + @DisplayName("Test combined analog and digital pins") + void testAnalogAndDigitalInputs() throws Exception { + String serialDevicePath = virtualavr.serialPortDescriptor(); + LOGGER.info("Started virtual serial port on {}", serialDevicePath); + + boolean received; + AtomicInteger analogCount = new AtomicInteger(0); + AtomicInteger digitalCount = new AtomicInteger(0); + CountDownLatch valuesReceived = new CountDownLatch(10); + + // Create a connection using the serialDevicePath and subscribe to both analog and digital pins + try (PlcConnection connection = PlcDriverManager.getDefault().getConnectionManager().getConnection("firmata://" + serialDevicePath + "?serial.baud-rate=57600&log.driver-testsuite-file=audit-log.txt")) { + PlcSubscriptionRequest.Builder builder = connection.subscriptionRequestBuilder(); + for (int pin : DIGITAL_PINS) { + builder.addChangeOfStateTagAddress("D" + pin, "digital:" + pin); + } + builder.addChangeOfStateTagAddress(ANALOG_PIN_A0, "analog:0"); + builder.setConsumer(plcSubscriptionEvent -> { + LOGGER.info("Received event: {}", plcSubscriptionEvent); + for (String tagName : plcSubscriptionEvent.getTagNames()) { + if (tagName.equals(ANALOG_PIN_A0)) { + analogCount.incrementAndGet(); + } else if (tagName.startsWith("D")) { + digitalCount.incrementAndGet(); + } + } + valuesReceived.countDown(); + }); + PlcSubscriptionResponse subscriptionResponse = builder + .build() + .execute().get(1000, TimeUnit.MILLISECONDS); + + // Wait for values (longer timeout for QEMU emulation) + received = valuesReceived.await(15, TimeUnit.SECONDS); + + // Unsubscribe from all subscriptions + connection.unsubscriptionRequestBuilder() + .addHandles(subscriptionResponse.getSubscriptionHandles()) + .build().execute().get(1000, TimeUnit.MILLISECONDS); + } + + LOGGER.info("Received {} analog events and {} digital events", + analogCount.get(), digitalCount.get()); + + // Both simulation types should have produced events + assertTrue(received && (analogCount.get() > 0 || digitalCount.get() > 0), + "Should receive events from both analog and digital simulations"); + } + +} diff --git a/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/TestcontainerSupport.java b/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/TestcontainerSupport.java new file mode 100644 index 00000000000..a752d97fd68 --- /dev/null +++ b/plc4j/drivers/firmata/src/test/java/org/apache/plc4x/java/firmata/readwrite/TestcontainerSupport.java @@ -0,0 +1,58 @@ +package org.apache.plc4x.java.firmata.readwrite; + +import com.github.pfichtner.testcontainers.virtualavr.VirtualAvrContainer; +import org.testcontainers.images.ImagePullPolicy; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.util.UUID; + +public final class TestcontainerSupport { + + private static final String VIRTUALAVR_DOCKER_TAG_PROPERTY_NAME = "virtualavr.docker.tag"; + private static final String VIRTUALAVR_DOCKER_PULL_PROPERTY_NAME = "virtualavr.docker.pull"; + + private TestcontainerSupport() { + super(); + } + + @SuppressWarnings("resource") + public static VirtualAvrContainer virtualAvrContainer(File inoFile) { + VirtualAvrContainer container = new VirtualAvrContainer<>(imageName()) // + .withImagePullPolicy(onlyPullIfEnabled()) // + .withSketchFile(inoFile) // + .withDeviceName("virtualavr" + UUID.randomUUID()) // + .withDeviceGroup("root") // + .withDeviceMode(666); + + // Use TCP serial mode on non-Linux systems (macOS/Windows with Docker Desktop) + if (!isLinux()) { + container.withTcpSerialMode(); + } + + return container; + } + + public static ImagePullPolicy onlyPullIfEnabled() { + return imageName -> System.getProperty(VIRTUALAVR_DOCKER_PULL_PROPERTY_NAME) != null; + } + + public static DockerImageName imageName() { + String dockerTagName = System.getProperty(VIRTUALAVR_DOCKER_TAG_PROPERTY_NAME, "dev"); + DockerImageName defaultImageName = VirtualAvrContainer.DEFAULT_IMAGE_NAME; + return dockerTagName == null ? defaultImageName : defaultImageName.withTag(dockerTagName); + } + + /** + * Checks if the current OS is Linux. + * On Linux, the standard PTY mode works because /dev can be bind-mounted. + * On macOS/Windows with Docker Desktop, TCP serial mode is needed. + * + * @return true if running on Linux + */ + public static boolean isLinux() { + String os = System.getProperty("os.name", "").toLowerCase(); + return os.contains("linux"); + } + +} diff --git a/plc4j/drivers/firmata/src/test/resources/firmata/StandardFirmata.ino b/plc4j/drivers/firmata/src/test/resources/firmata/StandardFirmata.ino new file mode 100644 index 00000000000..5604f3aa2ec --- /dev/null +++ b/plc4j/drivers/firmata/src/test/resources/firmata/StandardFirmata.ino @@ -0,0 +1,289 @@ +/* + * StandardFirmata sketch for VirtualAVR integration testing. + * This is a minimal Firmata implementation that works with avr8js simulator. + * + * Based on StandardFirmata by Firmata (LGPL v2.1+) + * Simplified for testing purposes. + * + * Debug output: The built-in LED (pin 13) blinks when Firmata commands are received. + * Analog changes are indicated by PWM on pin 9 (proportional to A0 value). + */ + +#include + +/* Debug LED for visual feedback */ +#define DEBUG_LED 13 +#define DEBUG_PWM 9 + +/* Command counters for debugging */ +volatile unsigned int commandCount = 0; +volatile unsigned int analogChangeCount = 0; + +/* analog inputs */ +int analogInputsToReport = 0; // bitwise array to store pin reporting +int lastAnalogValues[16]; + +/* digital input ports */ +byte reportPINs[TOTAL_PORTS]; // 1 = report this port, 0 = silence +byte previousPINs[TOTAL_PORTS]; // previous 8 bits sent + +/* pins configuration */ +byte pinConfig[TOTAL_PINS]; // configuration of every pin +byte portConfigInputs[TOTAL_PORTS]; // each bit: 1 = pin in INPUT, 0 = anything else + +/* timer variables */ +unsigned long currentMillis; // store the current value from millis() +unsigned long previousMillis; // for comparison with currentMillis +unsigned int samplingInterval = 19; // how often to sample analog inputs (in ms) + +/* Debug: Toggle LED to indicate activity */ +void debugBlink() { + static bool ledState = false; + ledState = !ledState; + digitalWrite(DEBUG_LED, ledState ? HIGH : LOW); + commandCount++; +} + +/* Debug: Show analog value on PWM pin */ +void debugAnalog(int value) { + // Map 0-1023 to 0-255 for PWM + analogWrite(DEBUG_PWM, value >> 2); + analogChangeCount++; +} + +void outputPort(byte portNumber, byte portValue, byte forceSend) +{ + portValue = portValue & portConfigInputs[portNumber]; + if (forceSend || previousPINs[portNumber] != portValue) { + Firmata.sendDigitalPort(portNumber, portValue); + previousPINs[portNumber] = portValue; + } +} + +void checkDigitalInputs(void) +{ + if (TOTAL_PORTS > 0 && reportPINs[0]) outputPort(0, readPort(0, portConfigInputs[0]), false); + if (TOTAL_PORTS > 1 && reportPINs[1]) outputPort(1, readPort(1, portConfigInputs[1]), false); + if (TOTAL_PORTS > 2 && reportPINs[2]) outputPort(2, readPort(2, portConfigInputs[2]), false); +} + +void setPinModeCallback(byte pin, int mode) +{ + debugBlink(); // Visual feedback for received command + if (pin < TOTAL_PINS) { + pinConfig[pin] = mode; + + if (mode == PIN_MODE_INPUT || mode == PIN_MODE_PULLUP) { + portConfigInputs[pin / 8] |= (1 << (pin & 7)); + if (mode == PIN_MODE_PULLUP) { + digitalWrite(pin, HIGH); + } + pinMode(pin, INPUT); + } else if (mode == PIN_MODE_OUTPUT) { + portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); + pinMode(pin, OUTPUT); + } else if (mode == PIN_MODE_ANALOG) { + portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); + } else if (mode == PIN_MODE_PWM) { + portConfigInputs[pin / 8] &= ~(1 << (pin & 7)); + pinMode(pin, OUTPUT); + } + } +} + +void setDigitalPinValueCallback(byte pin, int value) +{ + debugBlink(); // Visual feedback for received command + if (pin < TOTAL_PINS && pinConfig[pin] == PIN_MODE_OUTPUT) { + digitalWrite(pin, value); + } +} + +void analogWriteCallback(byte pin, int value) +{ + debugBlink(); // Visual feedback for received command + if (pin < TOTAL_PINS) { + switch (pinConfig[pin]) { + case PIN_MODE_PWM: + analogWrite(pin, value); + break; + } + } +} + +void digitalWriteCallback(byte port, int value) +{ + debugBlink(); // Visual feedback for received command + byte pin, lastPin, mask = 1, pinWriteMask = 0; + + if (port < TOTAL_PORTS) { + lastPin = port * 8 + 8; + if (lastPin > TOTAL_PINS) lastPin = TOTAL_PINS; + + for (pin = port * 8; pin < lastPin; pin++) { + if (pinConfig[pin] == PIN_MODE_OUTPUT) { + pinWriteMask |= mask; + } + mask = mask << 1; + } + writePort(port, (byte)value, pinWriteMask); + } +} + +void reportAnalogCallback(byte analogPin, int value) +{ + debugBlink(); // Visual feedback for received command + if (analogPin < TOTAL_ANALOG_PINS) { + if (value == 0) { + analogInputsToReport &= ~(1 << analogPin); + } else { + analogInputsToReport |= (1 << analogPin); + } + } +} + +void reportDigitalCallback(byte port, int value) +{ + debugBlink(); // Visual feedback for received command + if (port < TOTAL_PORTS) { + reportPINs[port] = (byte)value; + if (value) outputPort(port, readPort(port, portConfigInputs[port]), true); + } +} + +void sysexCallback(byte command, byte argc, byte *argv) +{ + switch (command) { + case SAMPLING_INTERVAL: + if (argc > 1) { + samplingInterval = argv[0] + (argv[1] << 7); + if (samplingInterval < 10) { + samplingInterval = 10; + } + } + break; + case CAPABILITY_QUERY: + Firmata.write(START_SYSEX); + Firmata.write(CAPABILITY_RESPONSE); + for (byte pin = 0; pin < TOTAL_PINS; pin++) { + if (IS_PIN_DIGITAL(pin)) { + Firmata.write((byte)PIN_MODE_INPUT); + Firmata.write(1); + Firmata.write((byte)PIN_MODE_PULLUP); + Firmata.write(1); + Firmata.write((byte)PIN_MODE_OUTPUT); + Firmata.write(1); + } + if (IS_PIN_ANALOG(pin)) { + Firmata.write(PIN_MODE_ANALOG); + Firmata.write(10); // 10-bit resolution + } + if (IS_PIN_PWM(pin)) { + Firmata.write(PIN_MODE_PWM); + Firmata.write(8); // 8-bit resolution + } + Firmata.write(127); + } + Firmata.write(END_SYSEX); + break; + case PIN_STATE_QUERY: + if (argc > 0) { + byte pin = argv[0]; + Firmata.write(START_SYSEX); + Firmata.write(PIN_STATE_RESPONSE); + Firmata.write(pin); + if (pin < TOTAL_PINS) { + Firmata.write((byte)pinConfig[pin]); + if (pinConfig[pin] == PIN_MODE_OUTPUT) { + Firmata.write((byte)digitalRead(pin)); + } + } + Firmata.write(END_SYSEX); + } + break; + case ANALOG_MAPPING_QUERY: + Firmata.write(START_SYSEX); + Firmata.write(ANALOG_MAPPING_RESPONSE); + for (byte pin = 0; pin < TOTAL_PINS; pin++) { + Firmata.write(IS_PIN_ANALOG(pin) ? PIN_TO_ANALOG(pin) : 127); + } + Firmata.write(END_SYSEX); + break; + } +} + +void systemResetCallback() +{ + for (byte i = 0; i < TOTAL_PORTS; i++) { + reportPINs[i] = false; + portConfigInputs[i] = 0; + previousPINs[i] = 0; + } + for (byte i = 0; i < TOTAL_PINS; i++) { + pinConfig[i] = PIN_MODE_OUTPUT; + } + for (byte i = 0; i < TOTAL_ANALOG_PINS; i++) { + lastAnalogValues[i] = 0; + } + analogInputsToReport = 0; +} + +void setup() +{ + // Initialize debug pins + pinMode(DEBUG_LED, OUTPUT); + pinMode(DEBUG_PWM, OUTPUT); + digitalWrite(DEBUG_LED, LOW); + + // Blink LED 3 times to indicate startup + for (int i = 0; i < 3; i++) { + digitalWrite(DEBUG_LED, HIGH); + delay(100); + digitalWrite(DEBUG_LED, LOW); + delay(100); + } + + Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); + + Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); + Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); + Firmata.attach(REPORT_ANALOG, reportAnalogCallback); + Firmata.attach(REPORT_DIGITAL, reportDigitalCallback); + Firmata.attach(SET_PIN_MODE, setPinModeCallback); + Firmata.attach(SET_DIGITAL_PIN_VALUE, setDigitalPinValueCallback); + Firmata.attach(START_SYSEX, sysexCallback); + Firmata.attach(SYSTEM_RESET, systemResetCallback); + + Firmata.begin(57600); + systemResetCallback(); +} + +void loop() +{ + byte pin, analogPin; + + checkDigitalInputs(); + + currentMillis = millis(); + if (currentMillis - previousMillis >= samplingInterval) { + previousMillis = currentMillis; + + for (pin = 0; pin < TOTAL_ANALOG_PINS; pin++) { + if (analogInputsToReport & (1 << pin)) { + int value = analogRead(pin); + if (value != lastAnalogValues[pin]) { + Firmata.sendAnalog(pin, value); + lastAnalogValues[pin] = value; + // Debug: Show analog value changes on PWM pin 9 + if (pin == 0) { + debugAnalog(value); + } + } + } + } + } + + while (Firmata.available()) { + Firmata.processInput(); + } +} diff --git a/plc4j/drivers/firmata/src/test/resources/firmata/libraries.txt b/plc4j/drivers/firmata/src/test/resources/firmata/libraries.txt new file mode 100644 index 00000000000..8520e927140 --- /dev/null +++ b/plc4j/drivers/firmata/src/test/resources/firmata/libraries.txt @@ -0,0 +1 @@ +Firmata diff --git a/plc4j/drivers/pom.xml b/plc4j/drivers/pom.xml index deb6a14ca0f..ef562a7ebdd 100644 --- a/plc4j/drivers/pom.xml +++ b/plc4j/drivers/pom.xml @@ -38,7 +38,7 @@ - ab-eth + diff --git a/plc4j/spi/src/test/resources/logback-test.xml b/plc4j/spi/buffers/api/pom.xml similarity index 56% rename from plc4j/spi/src/test/resources/logback-test.xml rename to plc4j/spi/buffers/api/pom.xml index 2b9cea25dc8..2bcb1bde706 100644 --- a/plc4j/spi/src/test/resources/logback-test.xml +++ b/plc4j/spi/buffers/api/pom.xml @@ -17,20 +17,25 @@ specific language governing permissions and limitations under the License. --> - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file + + 4.0.0 + + + org.apache.plc4x + plc4j-spi-buffers + 0.14.0-SNAPSHOT + + + plc4j-spi-buffers-api + + PLC4J: SPI: Buffers: API + + + 2024-02-16T14:53:02Z + + + + + + diff --git a/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/AbstractBuffer.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/AbstractBuffer.java new file mode 100644 index 00000000000..2abffcf7a5e --- /dev/null +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/AbstractBuffer.java @@ -0,0 +1,73 @@ +/* + * 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. + */ +package org.apache.plc4x.java.spi.buffers.api; + +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; + +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; + +public abstract class AbstractBuffer implements Buffer { + + protected final Stack context; + + public AbstractBuffer(WithOption... options) { + context = new Stack<>(); + context.push(options); + } + + @Override + public void pushContext(WithOption... options) throws BufferException { + Map, WithOption> newOptions = new HashMap<>(); + + // Add all new options. + for (WithOption option : options) { + newOptions.put(option.getClass(), option); + } + + // Add all inherited options. + if (!context.isEmpty()) { + for (WithOption option : context.peek()) { + if (option.isSticky() && !newOptions.containsKey(option.getClass())) { + newOptions.put(option.getClass(), option); + } + } + } + + // Switch the context to the next one. + context.push(newOptions.values().toArray(new WithOption[0])); + } + + @Override + public void popContext(WithOption... options) throws BufferException { + if (!context.isEmpty()) { + context.pop(); + } + } + + @Override + public WithOption[] getContext() { + if (!context.isEmpty()) { + return context.peek(); + } + return new WithOption[0]; + } + +} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataIoSerializerFunction.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Buffer.java similarity index 72% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataIoSerializerFunction.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Buffer.java index 6933895647d..a7df69a031f 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataIoSerializerFunction.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Buffer.java @@ -16,14 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.codegen.io; +package org.apache.plc4x.java.spi.buffers.api; -import org.apache.plc4x.java.api.value.PlcValue; -import org.apache.plc4x.java.spi.generation.SerializationException; +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; -@FunctionalInterface -public interface DataIoSerializerFunction { +public interface Buffer { - void apply(T t, PlcValue value) throws SerializationException; + void pushContext(WithOption... options) throws BufferException; + + void popContext(WithOption... options) throws BufferException; + + WithOption[] getContext(); } diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/Message.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Message.java similarity index 90% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/Message.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Message.java index 8bc28c060dc..f4623bf0331 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/Message.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Message.java @@ -16,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.generation; - -import org.apache.plc4x.java.spi.utils.Serializable; +package org.apache.plc4x.java.spi.buffers.api; public interface Message extends Serializable { diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageInput.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageInput.java similarity index 82% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageInput.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageInput.java index e6005a1a877..748c6ccd4bd 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageInput.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageInput.java @@ -16,11 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.generation; +package org.apache.plc4x.java.spi.buffers.api; + + +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; @FunctionalInterface public interface MessageInput { - PARSER_TYPE parse(ReadBuffer io) throws ParseException; + PARSER_TYPE parse(ReadBuffer io) throws BufferException; } diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageOutput.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageOutput.java similarity index 75% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageOutput.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageOutput.java index e28d465eefe..be98e3393f6 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/MessageOutput.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/MessageOutput.java @@ -16,10 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.generation; +package org.apache.plc4x.java.spi.buffers.api; -public interface MessageOutput { - WriteBufferByteBased serialize(SERIALIZER_TYPE value) throws SerializationException; +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; + +public interface MessageOutput { + + PARSER_TYPE serialize(SERIALIZER_TYPE value) throws BufferException; } diff --git a/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/ReadBuffer.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/ReadBuffer.java new file mode 100644 index 00000000000..307a69ad0b0 --- /dev/null +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/ReadBuffer.java @@ -0,0 +1,203 @@ +/* + * 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. + */ +package org.apache.plc4x.java.spi.buffers.api; + +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; + +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * Interface for reading data from a buffer with bit-level precision. + * Provides methods for reading various data types with specified bit lengths. + */ +public interface ReadBuffer extends Buffer { + + /** + * Reads a single bit from the buffer. + * + * @return true if the bit is set, false otherwise + */ + boolean readBit(WithOption... options) throws BufferException; + + /** + * Reads a specified number of bits from the buffer. + * + * @param numBits the number of bits to read + * @return a byte array containing the read bits + */ + byte[] readBits(int numBits, WithOption... options) throws BufferException; + + /** + * Reads an unsigned byte value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the unsigned byte value as a short value + */ + byte readUnsignedByte(int numBits, WithOption... options) throws BufferException; + + /** + * Reads an unsigned short value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the unsigned short value as an int value + */ + short readUnsignedShort(int numBits, WithOption... options) throws BufferException; + + /** + * Reads an unsigned int value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the unsigned int value as a long value + */ + int readUnsignedInt(int numBits, WithOption... options) throws BufferException; + + /** + * Reads an unsigned long value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the unsigned long value as a BigInteger value + */ + long readUnsignedLong(int numBits, WithOption... options) throws BufferException; + + /** + * Reads an unsigned big integer with the specified bit length. + * + * @param bitLength the number of bits to read + * @param options additional options for reading + * @return the unsigned big integer value + */ + BigInteger readUnsignedBigInteger(int bitLength, WithOption... options) throws BufferException; + + /** + * Reads a signed byte value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the signed byte value + */ + byte readSignedByte(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a signed short value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the signed short value + */ + short readSignedShort(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a signed int value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the signed int value + */ + int readSignedInt(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a signed long value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the signed long value + */ + long readSignedLong(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a signed big integer with the specified bit length. + * + * @param bitLength the number of bits to read + * @param options additional options for reading + * @return the signed big integer value + */ + BigInteger readSignedBigInteger(int bitLength, WithOption... options) throws BufferException; + + /** + * Reads a float value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the float value + */ + float readFloat(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a double value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the double value + */ + double readDouble(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a big decimal value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the big decimal value + */ + BigDecimal readBigDecimal(int numBits, WithOption... options) throws BufferException; + + /** + * Reads a string value with the specified bit length. + * + * @param numBits the number of bits to read + * @param options additional options for reading + * @return the string value + */ + String readString(int numBits, WithOption... options) throws BufferException; + + /** + * Creates a sub-buffer with the specified bit length. + * + * @param numBits the number of bits for the sub-buffer + * @param options additional options for creating the sub-buffer + * @return a new ReadBuffer instance representing the sub-buffer + */ + ReadBuffer createSubBuffer(int numBits, WithOption... options) throws BufferException; + + /** + * Gets the current position in the buffer in bits. + * + * @return the current position in bits + */ + int getPositionInBits(); + + /** + * Gets the number of remaining bits in the buffer. + * + * @return the number of remaining bits + */ + int getRemainingBits(); + + /** + * Sets the current position in the buffer in bits. + * + * @param positionInBits the new position in bits + */ + void setPositionInBits(int positionInBits); + +} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/Serializable.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Serializable.java similarity index 78% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/Serializable.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Serializable.java index 43265fddb1c..6f8d5766819 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/utils/Serializable.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/Serializable.java @@ -16,11 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.utils; +package org.apache.plc4x.java.spi.buffers.api; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WriteBuffer; +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; public interface Serializable { - void serialize(WriteBuffer writeBuffer) throws SerializationException; + + void serialize(WriteBuffer writeBuffer) throws BufferException; + } diff --git a/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WithOption.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WithOption.java new file mode 100644 index 00000000000..ebf8d8ff94e --- /dev/null +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WithOption.java @@ -0,0 +1,317 @@ +/* + * 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. + */ +package org.apache.plc4x.java.spi.buffers.api; + +import java.util.Optional; + +public interface WithOption { + /** + * @return true if the option should also be valid in sub-contexts. + */ + boolean isSticky(); + + static WithOption[] AddOptions(WithOption[] options, WithOption... newOptions) { + WithOption[] newOptionsArray = new WithOption[newOptions.length + options.length]; + System.arraycopy(newOptions, 0, newOptionsArray, 0, newOptions.length); + System.arraycopy(options, 0, newOptionsArray, newOptions.length, options.length); + return newOptionsArray; + } + + static WithOption[] UpdateOptions(WithOption[] options, WithOption... updateOptions) { + WithOption[] newOptionsArray = new WithOption[options.length]; + // First, simply copy over all options. + System.arraycopy(options, 0, newOptionsArray, 0, options.length); + // Then update existing options. + for (WithOption updateOption : updateOptions) { + for (int i = 0; i < newOptionsArray.length; i++) { + WithOption option = newOptionsArray[i]; + if (option.getClass() == updateOption.getClass()) { + newOptionsArray[i] = updateOption; + break; + } + } + } + return newOptionsArray; + } + + static WithOption WithName(String name) { + return (withOptionName) () -> name; + } + + /** + * This sets the encoding for all types of values. Use the With*Encoding methods to set encoding for specific types. + * + * @param encodingName name of the encoding to use for all operations. + * @return option + */ + static WithOption WithEncoding(String encodingName) { + return (withOptionEncoding) () -> encodingName; + } + + /** + * This sets the encoding for reading unsigned integers. + * + * @param encodingName name of the encoding to use for unsigned integer operations. + * @return option + */ + static WithOption WithUnsignedIntegerEncoding(String encodingName) { + return (withOptionUnsignedIntegerEncoding) () -> encodingName; + } + + /** + * This sets the encoding for reading signed integers. + * + * @param encodingName name of the encoding to use for signed integer operations. + * @return option + */ + static WithOption WithSignedIntegerEncoding(String encodingName) { + return (withOptionSignedIntegerEncoding) () -> encodingName; + } + + /** + * This sets the encoding for reading floating point values. + * + * @param encodingName name of the encoding to use for floating point value operations. + * @return option + */ + static WithOption WithFloatEncoding(String encodingName) { + return (withOptionFloatEncoding) () -> encodingName; + } + + /** + * This sets the encoding for reading strings. + * + * @param encodingName name of the encoding to use for string operations. + * @return option + */ + static WithOption WithStringEncoding(String encodingName) { + return (withOptionStringEncoding) () -> encodingName; + } + + static WithOption WithAdditionalStringRepresentation(String stringRepresentation) { + return (withOptionAdditionalStringRepresentation) () -> stringRepresentation; + } + + static WithOption WithRenderAsList(boolean renderAsList) { + return (withOptionRenderAsList) () -> renderAsList; + } + + static Optional extractName(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionName) { + return Optional.of(((withOptionName) option).name()); + } + } + } + return Optional.empty(); + } + + static Optional extractName(WithOption[] options, WithOption[] defaultOptions) { + Optional byteOrder = extractName(options); + if (byteOrder.isPresent()) { + return byteOrder; + } + return extractName(defaultOptions); + } + + static Optional extractEncoding(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionEncoding) { + return Optional.of(((withOptionEncoding) option).encodingName()); + } + } + } + return Optional.empty(); + } + + static Optional extractEncoding(WithOption[] options, WithOption[] defaultOptions) { + Optional encoding = extractEncoding(options); + if (encoding.isPresent()) { + return encoding; + } + return extractEncoding(defaultOptions); + } + + static Optional extractUnsignedIntegerEncoding(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionUnsignedIntegerEncoding) { + return Optional.of(((withOptionUnsignedIntegerEncoding) option).encodingName()); + } + } + } + return Optional.empty(); + } + + static Optional extractUnsignedIntegerEncoding(WithOption[] options, WithOption[] defaultOptions) { + Optional encoding = extractUnsignedIntegerEncoding(options); + if (encoding.isPresent()) { + return encoding; + } + return extractUnsignedIntegerEncoding(defaultOptions); + } + + static Optional extractSignedIntegerEncoding(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionSignedIntegerEncoding) { + return Optional.of(((withOptionSignedIntegerEncoding) option).encodingName()); + } + } + } + return Optional.empty(); + } + + static Optional extractSignedIntegerEncoding(WithOption[] options, WithOption[] defaultOptions) { + Optional encoding = extractSignedIntegerEncoding(options); + if (encoding.isPresent()) { + return encoding; + } + return extractSignedIntegerEncoding(defaultOptions); + } + + static Optional extractFloatEncoding(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionFloatEncoding) { + return Optional.of(((withOptionFloatEncoding) option).encodingName()); + } + } + } + return Optional.empty(); + } + + static Optional extractFloatEncoding(WithOption[] options, WithOption[] defaultOptions) { + Optional encoding = extractFloatEncoding(options); + if (encoding.isPresent()) { + return encoding; + } + return extractFloatEncoding(defaultOptions); + } + + static Optional extractStringEncoding(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionStringEncoding) { + return Optional.of(((withOptionStringEncoding) option).encodingName()); + } + } + } + return Optional.empty(); + } + + static Optional extractStringEncoding(WithOption[] options, WithOption[] defaultOptions) { + Optional encoding = extractStringEncoding(options); + if (encoding.isPresent()) { + return encoding; + } + return extractStringEncoding(defaultOptions); + } + + static Optional extractAdditionalStringRepresentation(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionAdditionalStringRepresentation) { + return Optional.of(((withOptionAdditionalStringRepresentation) option).stringRepresentation()); + } + } + } + return Optional.empty(); + } + + static Optional extractRenderAsList(WithOption[] options) { + if (options != null) { + for (WithOption option : options) { + if (option instanceof withOptionRenderAsList) { + return Optional.of(((withOptionRenderAsList) option).renderAsList()); + } + } + } + return Optional.empty(); + } + +} + +interface withOptionName extends WithOption { + String name(); + + default boolean isSticky() { + return false; + } +} + +interface withOptionEncoding extends WithOption { + String encodingName(); + + default boolean isSticky() { + return true; + } +} + +interface withOptionUnsignedIntegerEncoding extends WithOption { + String encodingName(); + + default boolean isSticky() { + return true; + } +} + +interface withOptionSignedIntegerEncoding extends WithOption { + String encodingName(); + + default boolean isSticky() { + return true; + } +} + +interface withOptionFloatEncoding extends WithOption { + String encodingName(); + + default boolean isSticky() { + return true; + } +} + +interface withOptionStringEncoding extends WithOption { + String encodingName(); + + default boolean isSticky() { + return true; + } +} + +interface withOptionAdditionalStringRepresentation extends WithOption { + String stringRepresentation(); + + default boolean isSticky() { + return false; + } +} + +interface withOptionRenderAsList extends WithOption { + boolean renderAsList(); + + default boolean isSticky() { + return false; + } +} + + diff --git a/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WriteBuffer.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WriteBuffer.java new file mode 100644 index 00000000000..ae5f0fd3223 --- /dev/null +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/WriteBuffer.java @@ -0,0 +1,225 @@ +/* + * 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. + */ +package org.apache.plc4x.java.spi.buffers.api; + +import org.apache.plc4x.java.spi.buffers.api.exceptions.BufferException; + +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * Interface for writing data to a buffer with bit-level precision. + * Provides methods for writing various data types with specified bit lengths. + */ +public interface WriteBuffer extends Buffer { + + /** + * Writes a single bit to the buffer. + * + * @param value the bit value to write (true for 1, false for 0) + */ + void writeBit(boolean value, WithOption... options) throws BufferException; + + /** + * Writes a specified number of bits to the buffer. + * + * @param numBits the number of bits to write + * @param value the byte array containing the bits to write + */ + void writeBits(int numBits, byte[] value, WithOption... options) throws BufferException; + + /** + * Writes an unsigned byte value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the unsigned byte value as a byte value + * @param options additional options for writing + */ + void writeUnsignedByte(int numBits, byte value, WithOption... options) throws BufferException; + + /** + * Writes an unsigned short value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the unsigned short value as an short value + * @param options additional options for writing + */ + void writeUnsignedShort(int numBits, short value, WithOption... options) throws BufferException; + + /** + * Writes an unsigned int value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the unsigned int value as a int value + * @param options additional options for writing + */ + void writeUnsignedInt(int numBits, int value, WithOption... options) throws BufferException; + + /** + * Writes an unsigned long value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the unsigned long value as a long value + * @param options additional options for writing + */ + void writeUnsignedLong(int numBits, long value, WithOption... options) throws BufferException; + + /** + * Writes an unsigned big integer with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the unsigned BigInteger value + * @param options additional options for writing + */ + void writeUnsignedBigInteger(int numBits, BigInteger value, WithOption... options) throws BufferException; + + /** + * Writes a signed byte value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the signed byte value + * @param options additional options for writing + */ + void writeSignedByte(int numBits, byte value, WithOption... options) throws BufferException; + + /** + * Writes a signed short value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the signed short value + * @param options additional options for writing + */ + void writeSignedShort(int numBits, short value, WithOption... options) throws BufferException; + + /** + * Writes a signed int value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the signed int value + * @param options additional options for writing + */ + void writeSignedInt(int numBits, int value, WithOption... options) throws BufferException; + + /** + * Writes a signed long value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the signed long value + * @param options additional options for writing + */ + void writeSignedLong(int numBits, long value, WithOption... options) throws BufferException; + + /** + * Writes a signed big integer with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the signed big integer value + * @param options additional options for writing + */ + void writeSignedBigInteger(int numBits, BigInteger value, WithOption... options) throws BufferException; + + /** + * Writes a float value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the float value + * @param options additional options for writing + */ + void writeFloat(int numBits, float value, WithOption... options) throws BufferException; + + /** + * Writes a double value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the double value + * @param options additional options for writing + */ + void writeDouble(int numBits, double value, WithOption... options) throws BufferException; + + /** + * Writes a big decimal value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the big decimal value + * @param options additional options for writing + */ + void writeBigDecimal(int numBits, BigDecimal value, WithOption... options) throws BufferException; + + /** + * Writes a string value with the specified bit length. + * + * @param numBits the number of bits to write + * @param value the string value + * @param options additional options for writing + */ + void writeString(int numBits, String value, WithOption... options) throws BufferException; + + /** + * this method can be used to influence serializing (e.g. intercept whole types and render them in a simplified form) + * + * @param message the value to be serialized + * @throws BufferException if something goes wrong + */ + default void writeMessage(Message message) throws BufferException { + if (message == null) { + return; + } + message.serialize(this); + } + + /** + * Creates a sub-buffer with the specified bit length. + * + * @param numBits the number of bits for the sub-buffer + * @param options additional options for creating the sub-buffer + * @return a new WriteBuffer instance representing the sub-buffer + */ + WriteBuffer createSubBuffer(int numBits, WithOption... options) throws BufferException; + + /** + * Gets the current position in the buffer in bits. + * + * @return the current position in bits + */ + int getPositionInBits(); + + /** + * Gets the number of remaining bits in the buffer. + * + * @return the number of remaining bits + */ + int getRemainingBits(); + + /** + * Gets the byte array representation of the buffer's content. + * + * @return the byte array containing the buffer's data + */ + byte[] getBytes(); + + /** + * This is only implemented to return true for byte-based byte buffers. + * + * @return true, if this is a byte-based buffer. + */ + default boolean isByteBased() { + return false; + } + +} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ParseException.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferException.java similarity index 77% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ParseException.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferException.java index 749d48d8fc6..f5b273cd2bb 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/ParseException.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferException.java @@ -16,15 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.generation; +package org.apache.plc4x.java.spi.buffers.api.exceptions; -public class ParseException extends Exception { +public class BufferException extends Exception { - public ParseException(String message) { + public BufferException() { + } + + public BufferException(String message) { super(message); } - public ParseException(String message, Throwable cause) { + public BufferException(String message, Throwable cause) { super(message, cause); } diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/SerializationException.java b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferValueException.java similarity index 74% rename from plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/SerializationException.java rename to plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferValueException.java index 97a94c412c0..52a3f1d8dd2 100644 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/SerializationException.java +++ b/plc4j/spi/buffers/api/src/main/java/org/apache/plc4x/java/spi/buffers/api/exceptions/BufferValueException.java @@ -16,16 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.plc4x.java.spi.generation; +package org.apache.plc4x.java.spi.buffers.api.exceptions; -public class SerializationException extends Exception { +public class BufferValueException extends BufferException { - public SerializationException(String message) { + private final Object value; + + public BufferValueException(String message, Object value) { super(message); + this.value = value; } - public SerializationException(String message, Throwable cause) { - super(message, cause); + public Object getValue() { + return value; } } diff --git a/plc4j/spi/buffers/ascii-box/pom.xml b/plc4j/spi/buffers/ascii-box/pom.xml new file mode 100644 index 00000000000..395c03022a7 --- /dev/null +++ b/plc4j/spi/buffers/ascii-box/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.apache.plc4x + plc4j-spi-buffers + 0.14.0-SNAPSHOT + + + plc4j-spi-buffers-ascii-box + + PLC4J: SPI: Buffers: ASCII-box + + + 2024-02-16T14:53:02Z + + + + + + diff --git a/plc4j/spi/buffers/byte/pom.xml b/plc4j/spi/buffers/byte/pom.xml new file mode 100644 index 00000000000..33562dde13d --- /dev/null +++ b/plc4j/spi/buffers/byte/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.apache.plc4x + plc4j-spi-buffers + 0.14.0-SNAPSHOT + + + plc4j-spi-buffers-byte + + PLC4J: SPI: Buffers: Byte + + + 2024-02-16T14:53:02Z + + + + + + diff --git a/plc4j/spi/buffers/pom.xml b/plc4j/spi/buffers/pom.xml new file mode 100644 index 00000000000..56827a40254 --- /dev/null +++ b/plc4j/spi/buffers/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + + org.apache.plc4x + plc4j-spi + 0.14.0-SNAPSHOT + + + plc4j-spi-buffers + pom + + PLC4J: SPI: Buffers + + + 2024-02-16T14:53:02Z + + + + api + ascii-box + byte + xml + + + diff --git a/plc4j/spi/buffers/xml/pom.xml b/plc4j/spi/buffers/xml/pom.xml new file mode 100644 index 00000000000..9daa5900e56 --- /dev/null +++ b/plc4j/spi/buffers/xml/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + + org.apache.plc4x + plc4j-spi-buffers + 0.14.0-SNAPSHOT + + + plc4j-spi-buffers-xml + + PLC4J: SPI: Buffers: Xml + + + 2024-02-16T14:53:02Z + + + + + + diff --git a/plc4j/spi/pom.xml b/plc4j/spi/pom.xml index b31a2b1cbe2..08860401baf 100644 --- a/plc4j/spi/pom.xml +++ b/plc4j/spi/pom.xml @@ -27,6 +27,8 @@ plc4j-spi + pom + PLC4J: SPI Internal API Module. @@ -34,87 +36,8 @@ 2025-08-02T13:55:11Z - - - io.netty - netty-buffer - - - io.netty - netty-codec - - - io.netty - netty-common - - - io.netty - netty-transport - - - - com.fasterxml.woodstox - woodstox-core - runtime - - - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-core - - - - io.vavr - vavr - - - - org.apache.plc4x - plc4j-api - 0.14.0-SNAPSHOT - compile - - - org.apache.commons - commons-lang3 - - - - com.github.jinahya - bit-io - - - commons-codec - commons-codec - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - - com.github.jinahya.bit.io;resolution:=optional, - * - - com.github.jinahya.bit.io - io.netty.bootstrap,* - - * - * - - - - - + + buffers + \ No newline at end of file diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java deleted file mode 100644 index a37b08548d6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/ConversationContext.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import io.netty.channel.Channel; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration; -import org.apache.plc4x.java.api.exceptions.PlcRuntimeException; - -import java.time.Duration; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; - -public interface ConversationContext { - - PlcAuthentication getAuthentication(); - - Channel getChannel(); - - boolean isPassive(); - - void sendToWire(T msg); - - void fireConnected(); - - void fireDisconnected(); - - void fireDiscovered(PlcConnectionConfiguration c); - - SendRequestContext sendRequest(T packet); - - interface SendRequestContext { - - /** - * names this conversation - * - * @param name the name of this conversation - * @return this - */ - SendRequestContext name(String name); - - /** - * defines a response type to be expected with an additional timeout - * - * @param clazz the type of the response - * @param timeout the timeout - * @return this - */ - SendRequestContext expectResponse(Class clazz, Duration timeout); - - /** - * checks the message using the supplied {@code checker} - * - * @param checker function to check the message. Should return true if ok. - * @return this - */ - SendRequestContext check(Predicate checker); - - /** - * final message handle - * - * @param packetConsumer consumer used to handle the message - * @return this - */ - ContextHandler handle(Consumer packetConsumer); - - CompletableFuture toFuture(); - - /** - * allows to define a timeout handler which then calls {@code packetConsumer} - * - * @param packetConsumer the timeout handler - * @return this - */ - SendRequestContext onTimeout(Consumer packetConsumer); - - /** - * allows to define an error handler which then calls {@code packetConsumer} - * - * @param packetConsumer the error handler - * @param the error - * @return this - */ - SendRequestContext onError(BiConsumer packetConsumer); - - /** - * unwraps {@code T} and returns {@code R} transformed by {@code unwrapper} - * - * @param unwrapper the function used for the transformation - * @param the unwrapped type - * @return this - */ - SendRequestContext unwrap(Function unwrapper); - - /** - * combines {@link #check } with {@link #unwrap} - * - * @param clazz the {@link Class} to be checked - * @param type for the {@link Class} - * @return this - */ - SendRequestContext only(Class clazz); - } - - ExpectRequestContext expectRequest(Class clazz, Duration timeout); - - interface ExpectRequestContext { - - ExpectRequestContext name(String name); - - ExpectRequestContext check(Predicate checker); - - ContextHandler handle(Consumer packetConsumer); - - ExpectRequestContext onTimeout(Consumer packetConsumer); - - ExpectRequestContext onError(BiConsumer packetConsumer); - - ExpectRequestContext unwrap(Function unwrapper); - } - - class PlcWiringException extends PlcRuntimeException { - public PlcWiringException(String message) { - super(message); - } - } - - interface ContextHandler { - - boolean isDone(); - - void cancel(); - - void await() throws InterruptedException, ExecutionException; - - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/EventListenerMessageCodec.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/EventListenerMessageCodec.java deleted file mode 100644 index d1bcd36d730..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/EventListenerMessageCodec.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageCodec; -import org.apache.plc4x.java.api.listener.EventListener; -import org.apache.plc4x.java.api.listener.MessageExchangeListener; -import org.apache.plc4x.java.spi.generation.Message; - -import java.util.List; - -/** - * Codec which propagate received or sent messages to connection event listeners. - */ -public class EventListenerMessageCodec extends MessageToMessageCodec { - - private final List listeners; - - public EventListenerMessageCodec(List listeners) { - this.listeners = listeners; - } - - @Override - protected void encode(ChannelHandlerContext ctx, Message msg, List out) throws Exception { - if (msg != null) { - for (EventListener listener : listeners) { - if (listener instanceof MessageExchangeListener) { - ((MessageExchangeListener) listener).sending(msg); - } - } - } - out.add(msg); - } - - @Override - protected void decode(ChannelHandlerContext ctx, Message msg, List out) throws Exception { - if (msg != null) { - for (EventListener listener : listeners) { - if (listener instanceof MessageExchangeListener) { - ((MessageExchangeListener) listener).received(msg); - } - } - } - out.add(msg); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java deleted file mode 100644 index d3dac42b5a2..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/GeneratedDriverByteToMessageCodec.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageCodec; -import org.apache.commons.codec.binary.Hex; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public abstract class GeneratedDriverByteToMessageCodec extends ByteToMessageCodec { - - private static final Logger LOGGER = LoggerFactory.getLogger(GeneratedDriverByteToMessageCodec.class); - - private final ByteOrder byteOrder; - private final MessageInput messageInput; - private final MessageOutput messageOutput; - - protected GeneratedDriverByteToMessageCodec(MessageInput messageInput, MessageOutput messageOutput, - Class outboundMessageType, ByteOrder byteOrder) { - super(outboundMessageType); - this.messageInput = messageInput; - this.messageOutput = messageOutput; - this.byteOrder = byteOrder; - } - - @Override - protected void encode(ChannelHandlerContext ctx, T packet, ByteBuf byteBuf) { - try { - WriteBufferByteBased buffer; - if(messageOutput != null) { - buffer = messageOutput.serialize(packet); - } else { - buffer = new WriteBufferByteBased(packet.getLengthInBytes(), byteOrder); - packet.serialize(buffer); - } - byteBuf.writeBytes(buffer.getBytes()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Sending bytes to PLC for message {} as data {}", packet, Hex.encodeHexString(buffer.getBytes())); - } - } catch (Exception e) { - LOGGER.warn("Error encoding package [{}]: {}", packet, e.getMessage(), e); - } - } - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List out) { - LOGGER.trace("Receiving bytes, trying to decode Message..."); - // As long as there is data available, continue checking the content. - while (byteBuf.readableBytes() > 0) { - byte[] bytes = null; - try { - // Check if enough data is present to process the entire package. - int packetSize = getPacketSize(byteBuf); - if (packetSize == -1 || packetSize > byteBuf.readableBytes()) { - return; - } - - // Read the packet data into a new ReadBuffer - bytes = new byte[packetSize]; - byteBuf.readBytes(bytes); - ReadBuffer readBuffer = new ReadBufferByteBased(bytes, byteOrder); - - // Parse the packet. - T packet = messageInput.parse(readBuffer); - - // Pass the packet to the pipeline. - out.add(packet); - - // It seems that one batch of 16 messages is the maximum, so we have to give up - // and process the rest next time. - if (out.size() >= 16) { - return; - } - } catch (Exception e) { - if (bytes != null) { - LOGGER.warn("Error decoding package with content [{}]: {}", - Hex.encodeHexString(bytes), e.getMessage(), e); - } - // Just remove any trailing junk ... if there is any. - removeRestOfCorruptPackage(byteBuf); - } - } - } - - protected abstract int getPacketSize(ByteBuf byteBuf); - - protected abstract void removeRestOfCorruptPackage(ByteBuf byteBuf); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java deleted file mode 100644 index 4c20b1390d7..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xNettyWrapper.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPromise; -import io.netty.handler.codec.MessageToMessageCodec; -import io.vavr.control.Either; - -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.BiConsumer; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration; -import org.apache.plc4x.java.spi.TimeoutManager.CompletionCallback; -import org.apache.plc4x.java.spi.events.*; -import org.apache.plc4x.java.spi.internal.DefaultConversationContext; -import org.apache.plc4x.java.spi.internal.DefaultExpectRequestContext; -import org.apache.plc4x.java.spi.internal.DefaultSendRequestContext; -import org.apache.plc4x.java.spi.internal.HandlerRegistration; -import org.apache.plc4x.java.spi.netty.NettyHashTimerTimeoutManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Duration; -import java.util.Deque; -import java.util.Iterator; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; - -public class Plc4xNettyWrapper extends MessageToMessageCodec { - - private static final Logger logger = LoggerFactory.getLogger(Plc4xNettyWrapper.class); - - private final Plc4xProtocolBase protocolBase; - - private final PlcAuthentication authentication; - - private final Queue registeredHandlers; - private final boolean passive; - private final TimeoutManager timeoutManager; - - public Plc4xNettyWrapper(ChannelPipeline pipeline, boolean passive, Plc4xProtocolBase protocol, - PlcAuthentication authentication, Class clazz) { - this(new NettyHashTimerTimeoutManager(), pipeline, passive, protocol, authentication, clazz); - } - - public Plc4xNettyWrapper(TimeoutManager timeoutManager, ChannelPipeline pipeline, boolean passive, Plc4xProtocolBase protocol, - PlcAuthentication authentication, Class clazz) { - super(clazz, Object.class); - this.passive = passive; - this.registeredHandlers = new ConcurrentLinkedQueue<>(); - this.protocolBase = protocol; - this.authentication = authentication; - this.timeoutManager = timeoutManager; - this.protocolBase.setConversationContext(new ConversationContext() { - - @Override - public PlcAuthentication getAuthentication() { - return authentication; - } - - @Override - public Channel getChannel() { - return pipeline.channel(); - } - - @Override - public boolean isPassive() { - return passive; - } - - @Override - public void sendToWire(T msg) { - // Under heavy load, we were sometimes getting "Failed to mark a promise as success because it has succeeded already" errors. - // See: https://github.com/apache/plc4x/issues/2043 - try { - pipeline.writeAndFlush(msg);//.syncUninterruptibly(); - } catch (Throwable t) { - logger.error("Error sending message", t); - if(logger.isDebugEnabled()) { - logger.debug("Message: {}", msg); - } - } - } - - @Override - public void fireConnected() { - pipeline.fireUserEventTriggered(ConnectedEvent.class); - } - - @Override - public void fireDisconnected() { - pipeline.fireUserEventTriggered(DisconnectedEvent.class); - } - - @Override - public void fireDiscovered(PlcConnectionConfiguration c) { - pipeline.fireUserEventTriggered(DiscoveredEvent.class); - } - - @Override - public SendRequestContext sendRequest(T packet) { - return new DefaultSendRequestContext<>(null, Plc4xNettyWrapper.this::registerHandler, packet, this); - } - - @Override - public ExpectRequestContext expectRequest(Class clazz, Duration timeout) { - return new DefaultExpectRequestContext<>(null, Plc4xNettyWrapper.this::registerHandler, clazz, timeout, this); - } - - }); - } - - @Override - public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { - super.close(ctx, promise); - timeoutManager.stop(); - } - - @Override - protected void encode(ChannelHandlerContext channelHandlerContext, Object msg, List list) throws Exception { - logger.debug("Forwarding request to plc {}", msg); - list.add(msg); - } - - @Override - protected void decode(ChannelHandlerContext channelHandlerContext, T payload, List list) throws Exception { - logger.trace("Decoding {}", payload); - // Just iterate the list to find a suitable Handler - - registrations: - for (Iterator iter = this.registeredHandlers.iterator(); iter.hasNext(); ) { - HandlerRegistration registration = iter.next(); - // Check if the handler can still be used or should be removed - // Was cancelled? - if (registration.isCancelled()) { - logger.debug("Removing {} as it was cancelled!", registration); - iter.remove(); - continue; - } - // Timeout? - if (registration.isDone()) { - logger.debug("Removing {} as it's already done. Timed out?", registration); - iter.remove(); - continue; - } - logger.trace("Checking handler {} for Object of type {}", registration, payload.getClass().getSimpleName()); - if (registration.getExpectClazz().isInstance(payload)) { - logger.trace("Handler {} has right expected type {}, checking condition", registration, registration.getExpectClazz().getSimpleName()); - Object message = payload; - try { - // Check all Commands / Functions - Deque, Predicate>> commands = registration.getCommands(); - for (Either, Predicate> either : commands) { - if (either.isLeft()) { - Function unwrap = either.getLeft(); - message = unwrap.apply(message); - } else { - Predicate predicate = either.get(); - if (!predicate.test(message)) { - // We do not match -> cannot handle - logger.trace("Registration {} with predicate {} does not match object {} (currently wrapped to {})", registration, predicate, - payload.getClass().getSimpleName(), message.getClass().getSimpleName()); - continue registrations; - } - } - } - logger.trace("Handler {} accepts element {}, calling handle method", registration, payload); - this.registeredHandlers.remove(registration); - Consumer handler = registration.getPacketConsumer(); - handler.accept(message); - // Confirm that it was handled! - registration.confirmHandled(); - } catch (Exception e) { - logger.trace("Failure while processing payload {} with handler {}", message, registration, e); - BiConsumer biConsumer = registration.getErrorConsumer(); - if(biConsumer != null) { - biConsumer.accept(message, e); - } - registration.confirmError(); - } - return; - } - } - logger.trace("None of {} registered handlers could handle message {}, using default decode method", this.registeredHandlers.size(), payload); - protocolBase.decode(new DefaultConversationContext<>(this::registerHandler, channelHandlerContext, authentication, passive), payload); - } - - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - // If the connection has just been established, start setting up the connection - // by sending a connection request to the plc. - logger.debug("User Event triggered {}", evt); - if (evt instanceof ConnectEvent) { - this.protocolBase.onConnect(new DefaultConversationContext<>(this::registerHandler, ctx, authentication, passive)); - } else if (evt instanceof DisconnectEvent) { - this.protocolBase.onDisconnect(new DefaultConversationContext<>(this::registerHandler, ctx, authentication, passive)); - } else if (evt instanceof DiscoverEvent) { - this.protocolBase.onDiscover(new DefaultConversationContext<>(this::registerHandler, ctx, authentication, passive)); - } else if (evt instanceof CloseConnectionEvent) { - this.protocolBase.close(new DefaultConversationContext<>(this::registerHandler, ctx, authentication, passive)); - } else { - super.userEventTriggered(ctx, evt); - } - } - - /** - * Performs registration of packet handler and makes sure that its timeout will be handled properly. - * Since timeouts are controlled by {@link TimeoutManager} there is a need to decorate handler - * operations so both sides know what's going on. - * - * @param handler Handler to be registered. - */ - private void registerHandler(HandlerRegistration handler) { - AtomicReference deferred = new AtomicReference<>(); - CompletionCallback completionCallback = this.timeoutManager.register(new TimedOperation() { - @Override - public Consumer getOnTimeoutConsumer() { - return onTimeout(deferred, handler.getOnTimeoutConsumer()); - } - - @Override - public Duration getTimeout() { - return handler.getTimeout(); - } - }); - // wrap handler, so we can catch packet consumer call and inform completion callback. - HandlerRegistration registration = new HandlerRegistration( - handler.getName(), - handler.getCommands(), - handler.getExpectClazz(), - completionCallback.andThen(handler.getPacketConsumer()), - handler.getOnTimeoutConsumer(), - handler.getErrorConsumer(), - handler::confirmHandled, - handler::confirmError, - handler::cancel, - handler.getTimeout() - ); - deferred.set(registration); - registeredHandlers.add(registration); - } - - private Consumer onTimeout(AtomicReference reference, Consumer onTimeoutConsumer) { - return timeoutException -> { - final HandlerRegistration registration = reference.get(); - registeredHandlers.remove(registration); - // Only call the timeout handler, if there is one. - if(onTimeoutConsumer != null) { - onTimeoutConsumer.accept(timeoutException); - } - registration.confirmError(); - }; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xProtocolBase.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xProtocolBase.java deleted file mode 100644 index 965fe33da41..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/Plc4xProtocolBase.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import org.apache.commons.lang3.NotImplementedException; -import org.apache.plc4x.java.api.messages.*; -import org.apache.plc4x.java.spi.connection.PlcTagHandler; -import org.apache.plc4x.java.spi.context.DriverContext; - -import java.util.concurrent.CompletableFuture; - -public abstract class Plc4xProtocolBase { - - protected ConversationContext conversationContext; - - protected DriverContext driverContext; - - public void setDriverContext(DriverContext driverContext) { - this.driverContext = driverContext; - } - - public DriverContext getDriverContext() { - return driverContext; - } - - public void setConversationContext(ConversationContext conversationContext) { - this.conversationContext = conversationContext; - } - - public ConversationContext getConversationContext() { - return conversationContext; - } - - public void onConnect(ConversationContext context) { - // Intentionally do nothing here - } - - public void onDisconnect(ConversationContext context) { - // Intentionally do nothing here - } - - public void onDiscover(ConversationContext context) { - // Intentionally do nothing here - } - - public abstract PlcTagHandler getTagHandler(); - - /** - * Default callback, called if an incoming message can't be correlated with an expected response. - * - * @param context - * @param msg - * @throws Exception - */ - protected void decode(ConversationContext context, T msg) throws Exception { - } - - public CompletableFuture ping(PlcPingRequest pingRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture read(PlcReadRequest readRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture write(PlcWriteRequest writeRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture subscribe(PlcSubscriptionRequest subscriptionRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture browse(PlcBrowseRequest browseRequest) { - throw new NotImplementedException(""); - } - - public CompletableFuture browseWithInterceptor(PlcBrowseRequest browseRequest, PlcBrowseRequestInterceptor interceptor) { - throw new NotImplementedException(""); - } - - public abstract void close(ConversationContext context); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/PlcMessageToMessageCodec.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/PlcMessageToMessageCodec.java deleted file mode 100644 index 10405e7fe1d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/PlcMessageToMessageCodec.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageCodec; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.lang.reflect.Field; - -public abstract class PlcMessageToMessageCodec - extends MessageToMessageCodec { - - private static final Logger logger = LoggerFactory.getLogger(PlcMessageToMessageCodec.class); - - private ChannelHandler prevChannelHandler = null; - - protected PlcMessageToMessageCodec() { - } - - protected PlcMessageToMessageCodec(Class inboundMessageType, - Class outboundMessageType) { - super(inboundMessageType, outboundMessageType); - } - - protected ChannelHandler getPrevChannelHandler(ChannelHandlerContext ctx) { - if(prevChannelHandler == null) { - try { - Field prevField = FieldUtils.getField(ctx.getClass(), "prev", true); - if(prevField != null) { - ChannelHandlerContext prevContext = (ChannelHandlerContext) prevField.get(ctx); - prevChannelHandler = prevContext.handler(); - } - } catch(Exception e) { - logger.error("Error accessing field 'prev'", e); - } - } - return prevChannelHandler; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimedOperation.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimedOperation.java deleted file mode 100644 index 6d60c2ca10d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimedOperation.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; -import java.util.function.Consumer; - -public interface TimedOperation { - - Consumer getOnTimeoutConsumer(); - - Duration getTimeout(); - - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java deleted file mode 100644 index 7d293f78f34..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/TimeoutManager.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi; - -import java.util.function.Consumer; - -public interface TimeoutManager { - - CompletionCallback register(TimedOperation operation); - - void stop(); - - interface CompletionCallback extends Consumer { - - void complete(); - - @Override - default void accept(T data) { - complete(); - } - - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/FieldCommons.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/FieldCommons.java deleted file mode 100644 index 92c60e8d3f1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/FieldCommons.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen; - -import org.apache.plc4x.java.spi.codegen.io.ByteOrderAware; -import org.apache.plc4x.java.spi.generation.*; - -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -public interface FieldCommons { - - default Optional extractByteOrder(WithReaderArgs... readerArgs) { - return extractByteOrder(Stream.of(readerArgs).map(WithReaderWriterArgs.class::cast).toArray(WithReaderWriterArgs[]::new)); - } - - default Optional extractByteOrder(WithWriterArgs... writerArgs) { - return extractByteOrder(Stream.of(writerArgs).map(WithReaderWriterArgs.class::cast).toArray(WithReaderWriterArgs[]::new)); - } - - default Optional extractByteOrder(WithReaderWriterArgs... readerWriterArgs) { - for (WithReaderWriterArgs arg : readerWriterArgs) { - if (arg instanceof withOptionByteOrder) { - return Optional.of(((withOptionByteOrder) arg).byteOrder()); - } - } - return Optional.empty(); - } - - default T switchParseByteOrderIfNecessary(RunParseWrapped runnable, ByteOrderAware byteOrderAware, ByteOrder wantedByteOrder) throws ParseException { - Objects.requireNonNull(runnable); - Objects.requireNonNull(byteOrderAware); - ByteOrder currentByteOrder = byteOrderAware.getByteOrder(); - if (wantedByteOrder == null || currentByteOrder == wantedByteOrder) { - return runnable.run(); - } - try { - byteOrderAware.setByteOrder(wantedByteOrder); - return runnable.run(); - } finally { - byteOrderAware.setByteOrder(currentByteOrder); - } - } - - default void switchSerializeByteOrderIfNecessary(RunSerializeWrapped runnable, ByteOrderAware byteOrderAware, ByteOrder wantedByteOrder) throws SerializationException { - Objects.requireNonNull(runnable); - Objects.requireNonNull(byteOrderAware); - ByteOrder currentByteOrder = byteOrderAware.getByteOrder(); - if (wantedByteOrder == null || currentByteOrder == wantedByteOrder) { - runnable.run(); - } else { - try { - byteOrderAware.setByteOrder(wantedByteOrder); - runnable.run(); - } finally { - byteOrderAware.setByteOrder(currentByteOrder); - } - } - } - - @FunctionalInterface - interface RunParseWrapped { - T run() throws ParseException; - } - - @FunctionalInterface - interface RunSerializeWrapped { - void run() throws SerializationException; - } - - @FunctionalInterface - interface ConsumeSerializeWrapped { - void consume(T value) throws SerializationException; - } - -} \ No newline at end of file diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/ThreadLocalHelper.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/ThreadLocalHelper.java deleted file mode 100644 index c5744cc7bc7..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/ThreadLocalHelper.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen; - -public class ThreadLocalHelper { - - public static final ThreadLocal lastItemThreadLocal = ThreadLocal.withInitial(() -> false); - public static final ThreadLocal curItemThreadLocal = ThreadLocal.withInitial(() -> 0); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/WithOption.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/WithOption.java deleted file mode 100644 index ea6101436ef..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/WithOption.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen; - -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; - -public interface WithOption extends WithReaderWriterArgs { - - static WithOption WithByteOrder(ByteOrder byteOrder) { - return (withOptionByteOrder) () -> byteOrder; - } - - static WithReaderWriterArgs WithEncoding(String encoding) { - return WithReaderWriterArgs.WithEncoding(encoding); - } - - static WithOption WithSerializationContext(String context) { - return (withOptionSerializationContext) () -> context; - } - - static WithReaderWriterArgs WithNullBytesHex(String nullBytesHex) { - return WithReaderWriterArgs.WithNullBytesHex(nullBytesHex); - } - -} - -interface withOptionByteOrder extends WithOption { - ByteOrder byteOrder(); -} - -interface withOptionSerializationContext extends WithOption { - String context(); -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAbstract.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAbstract.java deleted file mode 100644 index 493df4f48ac..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAbstract.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -/** - * This reader should actually never be used as an abstract field never gets read, it only makes sure - * abstract accessor methods are generated in the abstract parent type. - * - * @param - */ -public class FieldReaderAbstract implements FieldCommons { - - public T readAbstractField(String ignored1, DataReader ignored2, WithReaderArgs... ignored3) { - return null; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderArray.java deleted file mode 100644 index 12da2f9dee1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderArray.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.ThreadLocalHelper; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -public class FieldReaderArray implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderArray.class); - - public List readFieldCount(String logicalName, DataReader dataReader, long count, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}. Count: {}", logicalName, count); - if (count > Integer.MAX_VALUE) { - throw new ParseException("Array count of " + count + " exceeds the maximum allowed count of " + Integer.MAX_VALUE); - } - if (count < 0) { - return null; - } - // Ensure we have the render as list argument present - readerArgs = ArrayUtils.add(readerArgs, WithReaderWriterArgs.WithRenderAsList(true)); - dataReader.pullContext(logicalName, readerArgs); - int itemCount = Math.max(0, (int) count); - List result = new ArrayList<>(itemCount); - for (int curItem = 0; curItem < itemCount; curItem++) { - // Make some variables available that would be otherwise challenging to forward. - ThreadLocalHelper.curItemThreadLocal.set(curItem); - ThreadLocalHelper.lastItemThreadLocal.set(curItem == itemCount - 1); - result.add(dataReader.read("", readerArgs)); - } - dataReader.closeContext(logicalName, readerArgs); - LOGGER.debug("done reading field {}", logicalName); - return result; - } - - public List readFieldLength(String logicalName, DataReader dataReader, int length, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}. Length: {}", logicalName, length); - // Ensure we have the render as list argument present - readerArgs = ArrayUtils.add(readerArgs, WithReaderWriterArgs.WithRenderAsList(true)); - dataReader.pullContext(logicalName, readerArgs); - int startPos = dataReader.getPos(); - List result = new ArrayList<>(); - int numberOfElements = 0; - int stopPosition = startPos + length; - LOGGER.debug("start reading at pos {} while < {}", startPos, stopPosition); - while (dataReader.getPos() < stopPosition) { - numberOfElements++; - T element = dataReader.read("", readerArgs); - LOGGER.debug("Read element[{}] {}", numberOfElements, element); - result.add(element); - } - dataReader.closeContext(logicalName, readerArgs); - LOGGER.debug("done reading field {}", logicalName); - return result; - } - - public List readFieldTerminated(String logicalName, DataReader dataReader, Supplier termination, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - // Ensure we have the render as list argument present - readerArgs = ArrayUtils.add(readerArgs, WithReaderWriterArgs.WithRenderAsList(true)); - dataReader.pullContext(logicalName, readerArgs); - List result = new ArrayList<>(); - while (!termination.get()) { - result.add(dataReader.read("", readerArgs)); - } - dataReader.closeContext(logicalName, readerArgs); - LOGGER.debug("done reading field {}", logicalName); - return result; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAssert.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAssert.java deleted file mode 100644 index b58164e95df..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderAssert.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseAssertException; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Objects; - -public class FieldReaderAssert implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderAssert.class); - - public T readAssertField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - T assertValue; - try { - assertValue = dataReader.read(logicalName, readerArgs); - } catch (ArrayIndexOutOfBoundsException e) { - throw new ParseAssertException("Field: " + logicalName + ": Not enough data", e); - } - if (!Objects.equals(assertValue, expectedValue)) { - throw new ParseAssertException("Field: " + logicalName + ": Actual value " + assertValue + " doesn't match expected " + expectedValue); - } - return assertValue; - } -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderChecksum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderChecksum.java deleted file mode 100644 index 142d3c3e18e..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderChecksum.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Objects; - -public class FieldReaderChecksum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderChecksum.class); - - public T readChecksumField(String logicalName, DataReader dataReader, T referenceValue, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - T checksumValue = switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - if (!Objects.equals(checksumValue, referenceValue)) { - throw new ParseException("Checksum value '" + checksumValue + "' doesn't match expected '" + referenceValue + "'"); - } - return checksumValue; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderConst.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderConst.java deleted file mode 100644 index 677ba870b54..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderConst.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Objects; - -public class FieldReaderConst implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderConst.class); - - public T readConstField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - T constValue = switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - if (!Objects.equals(constValue, expectedValue)) { - throw new ParseException("Actual value " + constValue + " doesn't match expected " + expectedValue + ". Byte position: " + dataReader.getPos()); - } - return constValue; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminator.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminator.java deleted file mode 100644 index 410b2bac253..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderDiscriminator implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderDiscriminator.class); - - public T readDiscriminatorField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - return switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminatorEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminatorEnum.java deleted file mode 100644 index dc475f08426..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderDiscriminatorEnum.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderDiscriminatorEnum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderDiscriminatorEnum.class); - - public T readDiscriminatorEnumField(String logicalName, String innerName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - dataReader.pullContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - T result = switchParseByteOrderIfNecessary(() -> dataReader.read(innerName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - dataReader.closeContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - return result; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderEnum.java deleted file mode 100644 index 24342316966..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderEnum.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderEnum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderEnum.class); - - public T readEnumField(String logicalName, String innerName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - dataReader.pullContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - T result = switchParseByteOrderIfNecessary(() -> dataReader.read(innerName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - dataReader.closeContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - return result; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderFactory.java deleted file mode 100644 index c4877f8c894..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderFactory.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.codegen.io.ParseSupplier; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.math.BigInteger; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; - -public class FieldReaderFactory { - - @SuppressWarnings("unused") - public static T readAbstractField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderAbstract().readAbstractField(logicalName, dataReader, readerArgs); - } - - // TODO: only used as lazy workaround - @Deprecated - public static List readCountArrayField(String logicalName, DataReader dataReader, BigInteger count, WithReaderArgs... readerArgs) throws ParseException { - if (count.bitLength() > 64) { - throw new IllegalStateException("can't handle more than 64 bit. Actual: " + count.bitLength()); - } - return readCountArrayField(logicalName, dataReader, count.longValue(), readerArgs); - } - - public static List readCountArrayField(String logicalName, DataReader dataReader, long count, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderArray().readFieldCount(logicalName, dataReader, count, readerArgs); - } - - public static List readLengthArrayField(String logicalName, DataReader dataReader, int length, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderArray().readFieldLength(logicalName, dataReader, length, readerArgs); - } - - /** - * In some protocols a long is used as length, but we simply can't address that many bytes, - * so we simply cast it down to int as on java we couldn't even read more bytes as MAX-INT. - * - * @param logicalName the logical name of this field - * @param dataReader the dataReader used to retrieve this field - * @param length the length of the array - * @param readerArgs optional read args - * @param the type of the array elements - * @return the read length array - * @throws ParseException if something went wrong parsing - */ - public static List readLengthArrayField(String logicalName, DataReader dataReader, long length, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderArray().readFieldLength(logicalName, dataReader, (int) length, readerArgs); - } - - public static List readTerminatedArrayField(String logicalName, DataReader dataReader, Supplier termination, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderArray().readFieldTerminated(logicalName, dataReader, termination, readerArgs); - } - - public static T readAssertField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderAssert().readAssertField(logicalName, dataReader, expectedValue, readerArgs); - } - - public static T readChecksumField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderChecksum().readChecksumField(logicalName, dataReader, expectedValue, readerArgs); - } - - public static T readConstField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderConst().readConstField(logicalName, dataReader, expectedValue, readerArgs); - } - - public static T readDiscriminatorField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderDiscriminator().readDiscriminatorField(logicalName, dataReader, readerArgs); - } - - public static T readDiscriminatorEnumField(String logicalName, String innerName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderDiscriminatorEnum().readDiscriminatorEnumField(logicalName, innerName, dataReader, readerArgs); - } - - public static T readEnumField(String logicalName, String innerName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderEnum().readEnumField(logicalName, innerName, dataReader, readerArgs); - } - - public static T readImplicitField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderImplicit().readImplicitField(logicalName, dataReader, readerArgs); - } - - public static T readOptionalField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderOptional().readOptionalField(logicalName, dataReader, true, readerArgs); - } - - public static T readOptionalField(String logicalName, DataReader dataReader, boolean condition, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderOptional().readOptionalField(logicalName, dataReader, condition, readerArgs); - } - - public static byte[] readManualByteArrayField(String logicalName, ReadBuffer readBuffer, Function termination, ParseSupplier parse, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderManualArray().readManualByteArrayField(logicalName, readBuffer, termination, parse, readerArgs); - } - - public static List readManualArrayField(String logicalName, ReadBuffer readBuffer, Function, Boolean> termination, ParseSupplier parse, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderManualArray().readManualArrayField(logicalName, readBuffer, termination, parse, readerArgs); - } - - public static T readManualField(String logicalName, ReadBuffer readBuffer, ParseSupplier parse, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderManual().readManualField(logicalName, readBuffer, parse, readerArgs); - } - - public static void readPaddingField(DataReader dataReader, int timesPadding, WithReaderArgs... readerArgs) throws ParseException { - new FieldReaderPadding().readPaddingField(dataReader, timesPadding, readerArgs); - } - - public static T readReservedField(String logicalName, DataReader dataReader, T expectedValue, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderReserved().readReservedField(logicalName, dataReader, expectedValue, readerArgs); - } - - public static T readSimpleField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderSimple().readSimpleField(logicalName, dataReader, readerArgs); - } - - public static T readUnknownField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderUnknown().readUnknownField(logicalName, dataReader, readerArgs); - } - - public static T readVirtualField(String logicalName, Class type, Object valueExpression, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderVirtual().readVirtualField(logicalName, type, valueExpression, readerArgs); - } - - public static T readPeekField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderPeek().readPeekField(logicalName, dataReader, 0, readerArgs); - } - - public static T readPeekField(String logicalName, DataReader dataReader, int offset, WithReaderArgs... readerArgs) throws ParseException { - return new FieldReaderPeek().readPeekField(logicalName, dataReader, offset, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderImplicit.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderImplicit.java deleted file mode 100644 index c0300070b58..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderImplicit.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderImplicit implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderImplicit.class); - - public T readImplicitField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - return switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManual.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManual.java deleted file mode 100644 index 0c253aabed1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManual.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.ParseSupplier; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderManual implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderManual.class); - - public T readManualField(String logicalName, ReadBuffer readBuffer, ParseSupplier parseFunction, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - readBuffer.pullContext(logicalName); - T value = switchParseByteOrderIfNecessary(parseFunction::get, readBuffer, extractByteOrder(readerArgs).orElse(null)); - readBuffer.closeContext(logicalName); - return value; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManualArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManualArray.java deleted file mode 100644 index 55339b1221a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderManualArray.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.NotImplementedException; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.codegen.io.ParseSupplier; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; - -public class FieldReaderManualArray implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderManualArray.class); - - public byte[] readManualByteArrayField(String logicalName, ReadBuffer readBuffer, Function termination, ParseSupplier parse, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - // Ensure we have the render as list argument present - readerArgs = ArrayUtils.add(readerArgs, WithReaderWriterArgs.WithRenderAsList(true)); - readBuffer.pullContext(logicalName, readerArgs); - List result = new ArrayList<>(); - while (!termination.apply(ArrayUtils.toPrimitive(result.toArray(new Byte[0])))) { - //TODO: maybe switch to iterator here - Byte element = (Byte) parse.get(); - LOGGER.debug("Adding element {}", element); - result.add(element); - } - readBuffer.closeContext(logicalName, readerArgs); - LOGGER.debug("done reading field {}", logicalName); - return ArrayUtils.toPrimitive(result.toArray(new Byte[0])); - } - - public List readManualArrayField(String logicalName, ReadBuffer readBuffer, Function,Boolean> termination, ParseSupplier parse, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - // Ensure we have the render as list argument present - readerArgs = ArrayUtils.add(readerArgs, WithReaderWriterArgs.WithRenderAsList(true)); - readBuffer.pullContext(logicalName, readerArgs); - List result = new ArrayList<>(); - while (!termination.apply(Collections.unmodifiableList(result))) { - //TODO: maybe switch to iterator here - T element = parse.get(); - LOGGER.debug("Adding element {}", element); - result.add(element); - } - readBuffer.closeContext(logicalName, readerArgs); - LOGGER.debug("done reading field {}", logicalName); - return result; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderOptional.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderOptional.java deleted file mode 100644 index c9dcd38e1f5..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderOptional.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.Optional; - -public class FieldReaderOptional implements FieldCommons, WithReaderWriterArgs { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderOptional.class); - - public T readOptionalField(String logicalName, DataReader dataReader, boolean condition, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - if (!condition) { - LOGGER.debug("Condition doesn't match for field {}", logicalName); - return null; - } - - // Check if a nullByteHex is set. - // If it is, peek the equivalent number of bytes and compare. - // If they match, return null. - Optional nullByteHexOptional = extractNullBytesHex(readerArgs); - if(nullByteHexOptional.isPresent()) { - String nullByteHex = nullByteHexOptional.get(); - try { - byte[] nullBytes = Hex.decodeHex(nullByteHex); - ReadBuffer readBuffer = dataReader.getReadBuffer(); - int pos = readBuffer.getPos(); - byte[] curBytes = readBuffer.readByteArray("logicalName", nullBytes.length, readerArgs); - // Compare them, if they equal, return null, if not reset the position and try to read it again. - if (Arrays.equals(nullBytes, curBytes)) { - // Abort with null - return null; - } else { - readBuffer.reset(pos); - } - } catch (DecoderException e) { - // Ignore. - } - } - - int curPos = dataReader.getPos(); - try { - T field = switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - LOGGER.debug("done reading field {}. Value: {}", logicalName, field); - return field; - } catch (ParseAssertException e) { - LOGGER.debug("Assertion doesn't match for field {}. Resetting read position to {}", logicalName, curPos, e); - dataReader.setPos(curPos); - return null; - } catch (ArrayIndexOutOfBoundsException e) { - LOGGER.debug("Not enough bytes for {}. Resetting read position to {}", logicalName, curPos, e); - dataReader.setPos(curPos); - return null; - } - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPadding.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPadding.java deleted file mode 100644 index 99dccd06ed0..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPadding.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderPadding implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderPadding.class); - - public void readPaddingField(DataReader dataReader, int timesPadding, WithReaderArgs... readerArgs) { - LOGGER.debug("reading field padding"); - dataReader.pullContext("padding", WithReaderWriterArgs.WithRenderAsList(true)); - while (timesPadding-- > 0) { - // Just read the padding data and ignore it - try { - dataReader.read("value", readerArgs); - } catch (Exception e) { - // Ignore ... - // This could simply be that we're out of data to read for padding. - // In protocols like the S7 protocol, this can happen if this is the - // last field item, then the packet might end here. - } - } - dataReader.closeContext("padding", WithReaderWriterArgs.WithRenderAsList(true)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPeek.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPeek.java deleted file mode 100644 index d8410d60846..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderPeek.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseAssertException; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderPeek implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderPeek.class); - - public T readPeekField(String logicalName, DataReader dataReader, int offset, WithReaderArgs... readerArgs) throws ParseException { - int curPos = dataReader.getPos(); - try { - // TODO: implement offset. We either need to pass the readBuffer or add a instruction to the dataReader - T field = switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - LOGGER.debug("done reading field {}. Value: {}", logicalName, field); - return field; - } catch (ParseAssertException e) { - LOGGER.debug("Peeking failed for field {}. Resetting read position to {}", logicalName, curPos, e); - return null; - } finally { - dataReader.setPos(curPos); - } - } -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderReserved.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderReserved.java deleted file mode 100644 index 91ce55c857f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderReserved.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Objects; - -public class FieldReaderReserved implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderReserved.class); - - public T readReservedField(String logicalName, DataReader dataReader, T referenceValue, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - T reserved = dataReader.read(logicalName, readerArgs); - if (!Objects.equals(reserved, referenceValue)) { - LOGGER.info("Expected constant value {} but got {} for reserved field {}.", referenceValue, reserved, logicalName); - return reserved; - } - return null; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderSimple.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderSimple.java deleted file mode 100644 index b31c2b61e62..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderSimple.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderSimple implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderSimple.class); - - public T readSimpleField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - return switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - } - -} \ No newline at end of file diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderTypeSwitch.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderTypeSwitch.java deleted file mode 100644 index edb4e7e14f4..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderTypeSwitch.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderTypeSwitch implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderTypeSwitch.class); - - public T readTypeSwitchField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - return switchParseByteOrderIfNecessary(() -> dataReader.read(logicalName, readerArgs), dataReader, extractByteOrder(readerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderUnknown.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderUnknown.java deleted file mode 100644 index 258f8db123b..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderUnknown.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldReaderUnknown implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderUnknown.class); - - public T readUnknownField(String logicalName, DataReader dataReader, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - T unknownValue = dataReader.read(logicalName, readerArgs); - LOGGER.debug("Read unknown value {}", unknownValue); - return unknownValue; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderVirtual.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderVirtual.java deleted file mode 100644 index 3cd922f10d8..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldReaderVirtual.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataReader; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigInteger; - -public class FieldReaderVirtual implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldReaderVirtual.class); - - @SuppressWarnings({"unused", "unchecked"}) - public T readVirtualField(String logicalName, Class type, Object valueExpression, WithReaderArgs... readerArgs) throws ParseException { - LOGGER.debug("reading field {}", logicalName); - if (type.isPrimitive()) { - // for primitives, we need to cast to the primitive as this does autoboxing - if (type == boolean.class) { - return (T) (Boolean) (boolean) valueExpression; - } else if (type == byte.class) { - Number valueExpressionNumber = (Number) valueExpression; - long longValue = valueExpressionNumber.longValue(); - // 0xFF is a special case and a legit value for (unsigned) byte - if ((byte) longValue != longValue && longValue != 0xFF) { - throw new ArithmeticException("byte overflow"); - } - return (T) (Byte) valueExpressionNumber.byteValue(); - } else if (type == short.class) { - Number valueExpressionNumber = (Number) valueExpression; - long longValue = valueExpressionNumber.longValue(); - if ((short) longValue != longValue) { - throw new ArithmeticException("short overflow"); - } - return (T) (Short) valueExpressionNumber.shortValue(); - } else if (type == int.class) { - Number valueExpressionNumber = (Number) valueExpression; - long longValue = valueExpressionNumber.longValue(); - if ((int) longValue != longValue) { - throw new ArithmeticException("integer overflow"); - } - return (T) (Integer) valueExpressionNumber.intValue(); - } else if (type == long.class) { - Number valueExpressionNumber = (Number) valueExpression; - return (T) (Long) valueExpressionNumber.longValue(); - } else if (type == char.class) { - return (T) (Character) (char) valueExpression; - } else if (type == float.class) { - Number valueExpressionNumber = (Number) valueExpression; - return (T) (Float) valueExpressionNumber.floatValue(); - } else if (type == double.class) { - Number valueExpressionNumber = (Number) valueExpression; - return (T) (Double) valueExpressionNumber.doubleValue(); - } else { - throw new IllegalStateException("Unmapped primitive " + type); - } - } - if (type == String.class) { - return type.cast(String.valueOf(valueExpression)); - } - if (type == BigInteger.class) { - long longValue = valueExpression instanceof Long ? (Long) valueExpression : ((Number)valueExpression).longValue(); - return (T) BigInteger.valueOf(longValue); - } - return type.cast(valueExpression); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterArray.java deleted file mode 100644 index d94f491e6c7..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterArray.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.ThreadLocalHelper; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class FieldWriterArray implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterArray.class); - - public void writeByteArrayField(String logicalName, byte[] values, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - if (values != null) { - dataWriter.write(logicalName, values, writerArgs); - } - } - - public void writeSimpleTypeArrayField(String logicalName, List values, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> { - if (values != null) { - dataWriter.pushContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - for (int curItem = 0; curItem < values.size(); curItem++) { - T value = values.get(curItem); - ThreadLocalHelper.lastItemThreadLocal.set(curItem == values.size() - 1); - dataWriter.write("value", value, writerArgs); - } - dataWriter.popContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - } - }, dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - - public void writeComplexTypeArrayField(String logicalName, List values, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> { - if (values != null) { - writeBuffer.pushContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - for (int curItem = 0; curItem < values.size(); curItem++) { - Message value = values.get(curItem); - ThreadLocalHelper.lastItemThreadLocal.set(curItem == values.size() - 1); - value.serialize(writeBuffer); - } - writeBuffer.popContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - } - }, writeBuffer, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterChecksum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterChecksum.java deleted file mode 100644 index 7f0c63411c0..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterChecksum.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterChecksum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterChecksum.class); - - public void writeChecksumField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterConst.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterConst.java deleted file mode 100644 index 61d22895019..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterConst.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterConst implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterConst.class); - - public void writeConstField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminator.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminator.java deleted file mode 100644 index 82ce6dc7cf0..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminator.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterDiscriminator implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterDiscriminator.class); - - public void writeDiscriminatorField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminatorEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminatorEnum.java deleted file mode 100644 index 4a776e3d76f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterDiscriminatorEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterDiscriminatorEnum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterDiscriminatorEnum.class); - - public void writeDiscriminatorEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - dataWriter.pushContext(logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(innerName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - dataWriter.popContext(logicalName); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterEnum.java deleted file mode 100644 index 391566a1d81..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterEnum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterEnum.class); - - public void writeEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - dataWriter.pushContext(logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(innerName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - dataWriter.popContext(logicalName); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterFactory.java deleted file mode 100644 index 73ce88cee5e..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterFactory.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.Message; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.util.Arrays; -import java.util.List; - -public class FieldWriterFactory { - - public static void writeSimpleTypeArrayField(String logicalName, List value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterArray().writeSimpleTypeArrayField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeComplexTypeArrayField(String logicalName, List value, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterArray().writeComplexTypeArrayField(logicalName, value, writeBuffer, writerArgs); - } - - public static void writeByteArrayField(String logicalName, byte[] value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterArray().writeByteArrayField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeChecksumField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterChecksum().writeChecksumField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeConstField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterConst().writeConstField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterEnum().writeEnumField(logicalName, innerName, value, dataWriter, writerArgs); - } - - public static void writeDiscriminatorField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterDiscriminator().writeDiscriminatorField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeDiscriminatorEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterDiscriminatorEnum().writeDiscriminatorEnumField(logicalName, innerName, value, dataWriter, writerArgs); - } - - public static void writeImplicitField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterImplicit().writeImplicitField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeManualField(String logicalName, FieldCommons.RunSerializeWrapped runnable, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterManual<>().writeManualField(logicalName, runnable, writeBuffer, writerArgs); - } - - public static void writeManualArrayField(String logicalName, byte[] bytes, FieldCommons.ConsumeSerializeWrapped runnable, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterManualArray().writeManualArrayField(logicalName, Arrays.asList(ArrayUtils.toObject(bytes)), runnable, writeBuffer, writerArgs); - } - - public static void writeManualArrayField(String logicalName, List values, FieldCommons.ConsumeSerializeWrapped runnable, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterManualArray().writeManualArrayField(logicalName, values, runnable, writeBuffer, writerArgs); - } - - public static void writeOptionalField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterOptional().writeOptionalField(logicalName, value, dataWriter, true, writerArgs); - } - - public static void writeOptionalField(String logicalName, T value, DataWriter dataWriter, boolean condition, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterOptional().writeOptionalField(logicalName, value, dataWriter, condition, writerArgs); - } - - public static void writeOptionalEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterOptionalEnum().writeOptionalEnumField(logicalName, innerName, value, dataWriter, true, writerArgs); - } - - public static void writeOptionalEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, boolean condition, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterOptionalEnum().writeOptionalEnumField(logicalName, innerName, value, dataWriter, condition, writerArgs); - } - - public static void writePaddingField(String logicalName, int timesPadding, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterPadding().writePaddingField(logicalName, timesPadding, value, dataWriter, writerArgs); - } - - public static void writeReservedField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterReserved().writeReservedField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeSimpleField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterSimple().writeSimpleField(logicalName, value, dataWriter, writerArgs); - } - - public static void writeSimpleEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - new FieldWriterSimpleEnum().writeSimpleEnumField(logicalName, innerName, value, dataWriter, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterImplicit.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterImplicit.java deleted file mode 100644 index 35988447434..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterImplicit.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterImplicit implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterImplicit.class); - - public void writeImplicitField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManual.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManual.java deleted file mode 100644 index eaa61fc0c89..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManual.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterManual implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterManual.class); - - public void writeManualField(String logicalName, RunSerializeWrapped consumer, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(consumer, writeBuffer, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManualArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManualArray.java deleted file mode 100644 index b407dc9e279..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterManualArray.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class FieldWriterManualArray implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterManualArray.class); - - public void writeManualArrayField(String logicalName, List values, ConsumeSerializeWrapped consumer, WriteBuffer writeBuffer, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> { - if (values != null) { - writeBuffer.pushContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - for (T value : values) { - consumer.consume(value); - } - writeBuffer.popContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - } - }, writeBuffer, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptional.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptional.java deleted file mode 100644 index c34860bff72..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptional.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.Optional; - -public class FieldWriterOptional implements FieldCommons, WithReaderWriterArgs { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterOptional.class); - - public void writeOptionalField(String logicalName, T value, DataWriter dataWriter, boolean condition, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - if (condition && value != null) { - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } else { - WriteBuffer writeBuffer = dataWriter.getWriteBuffer(); - // This is very special to byte based buffers, it would just confuse the others. - if(writeBuffer instanceof WriteBufferByteBased) { - // Check if a nullByteHex is set. - // If it is, peek the equivalent number of bytes and compare. - // If they match, return null. - Optional nullByteHexOptional = extractNullBytesHex(writerArgs); - if (nullByteHexOptional.isPresent()) { - String nullByteHex = nullByteHexOptional.get(); - try { - byte[] nullBytes = Hex.decodeHex(nullByteHex); - writeBuffer.writeByteArray(logicalName, nullBytes, writerArgs); - } catch (DecoderException e) { - // Ignore. - } - } else { - LOGGER.debug("field {} not written because value is null({}) or condition({}) didn't evaluate to true", logicalName, value != null, condition); - } - } - } - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptionalEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptionalEnum.java deleted file mode 100644 index a8244dd67f6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterOptionalEnum.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.commons.codec.DecoderException; -import org.apache.commons.codec.binary.Hex; -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Optional; - -public class FieldWriterOptionalEnum implements FieldCommons, WithReaderWriterArgs { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterOptionalEnum.class); - - public void writeOptionalEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, boolean condition, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - dataWriter.pushContext(logicalName); - if (condition && value != null) { - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(innerName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } else { - WriteBuffer writeBuffer = dataWriter.getWriteBuffer(); - // This is very special to byte based buffers, it would just confuse the others. - if(writeBuffer instanceof WriteBufferByteBased) { - // Check if a nullByteHex is set. - // If it is, peek the equivalent number of bytes and compare. - // If they match, return null. - Optional nullByteHexOptional = extractNullBytesHex(writerArgs); - if (nullByteHexOptional.isPresent()) { - String nullByteHex = nullByteHexOptional.get(); - try { - byte[] nullBytes = Hex.decodeHex(nullByteHex); - writeBuffer.writeByteArray(logicalName, nullBytes, writerArgs); - } catch (DecoderException e) { - // Ignore. - } - } else { - LOGGER.debug("field {} not written because value is null({}) or condition({}) didn't evaluate to true", logicalName, value != null, condition); - } - } - } - dataWriter.popContext(logicalName); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterPadding.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterPadding.java deleted file mode 100644 index 5e26ee64e3a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterPadding.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithReaderWriterArgs; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterPadding implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterPadding.class); - - public void writePaddingField(String logicalName, int timesPadding, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> { - dataWriter.pushContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - for (int i = 0; i < timesPadding; i++) { - dataWriter.write("", value, writerArgs); - } - dataWriter.popContext(logicalName, WithReaderWriterArgs.WithRenderAsList(true)); - }, dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterReserved.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterReserved.java deleted file mode 100644 index b4931e26744..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterReserved.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterReserved implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterReserved.class); - - public void writeReservedField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimple.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimple.java deleted file mode 100644 index 91c7591c514..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimple.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterSimple implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterSimple.class); - - public void writeSimpleField(String logicalName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(logicalName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimpleEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimpleEnum.java deleted file mode 100644 index 11ff863d229..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/fields/FieldWriterSimpleEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.fields; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.codegen.io.DataWriter; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FieldWriterSimpleEnum implements FieldCommons { - - private static final Logger LOGGER = LoggerFactory.getLogger(FieldWriterSimpleEnum.class); - - public void writeSimpleEnumField(String logicalName, String innerName, T value, DataWriter dataWriter, WithWriterArgs... writerArgs) throws SerializationException { - LOGGER.debug("write field {}", logicalName); - dataWriter.pushContext(logicalName); - switchSerializeByteOrderIfNecessary(() -> dataWriter.write(innerName, value, writerArgs), dataWriter, extractByteOrder(writerArgs).orElse(null)); - dataWriter.popContext(logicalName); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ByteOrderAware.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ByteOrderAware.java deleted file mode 100644 index 079a5010611..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ByteOrderAware.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ByteOrder; - -public interface ByteOrderAware { - ByteOrder getByteOrder(); - - void setByteOrder(ByteOrder byteOrder); -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ComplexTypeSupplier.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ComplexTypeSupplier.java deleted file mode 100644 index 0f92f18a875..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ComplexTypeSupplier.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; - -@FunctionalInterface -public interface ComplexTypeSupplier { - - T get() throws ParseException; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextReader.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextReader.java deleted file mode 100644 index 0e2e24d631c..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextReader.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 - * - * http://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. - */ - -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public interface ContextReader { - void pullContext(String logicalName, WithReaderArgs... readerArgs); - - void closeContext(String logicalName, WithReaderArgs... readerArgs); -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextWriter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextWriter.java deleted file mode 100644 index b4e37b33ddc..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ContextWriter.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 - * - * http://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. - */ - -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.WithWriterArgs; - -public interface ContextWriter { - void pushContext(String logicalName, WithWriterArgs... writerArgs); - void popContext(String logicalName, WithWriterArgs... writerArgs); -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReader.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReader.java deleted file mode 100644 index b714223813f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReader.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public interface DataReader extends ByteOrderAware, PositionMover, ContextReader { - - T read(String logicalName, WithReaderArgs... readerArgs) throws ParseException; - - ReadBuffer getReadBuffer(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplex.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplex.java deleted file mode 100644 index 7af3b2dfc7f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplex.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public interface DataReaderComplex extends DataReader { - - T read(String logicalName, ComplexTypeSupplier complexSupplier, WithReaderArgs... readerArgs) throws ParseException; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplexDefault.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplexDefault.java deleted file mode 100644 index 11b760c0484..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderComplexDefault.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.commons.lang3.StringUtils; -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderComplexDefault implements DataReaderComplex { - - private final ComplexTypeSupplier complexSupplier; - - // TODO: maybe replace with resetable or something so its clear that that's the only purpose - private final ReadBuffer readBuffer; - - public DataReaderComplexDefault(ComplexTypeSupplier complexSupplier, ReadBuffer readBuffer) { - this.complexSupplier = complexSupplier; - this.readBuffer = readBuffer; - } - - @Override - public int getPos() { - return readBuffer.getPos(); - } - - @Override - public void setPos(int position) { - readBuffer.reset(position); - } - - @Override - public ByteOrder getByteOrder() { - return readBuffer.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - readBuffer.setByteOrder(byteOrder); - } - - @Override - public T read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return read(logicalName, complexSupplier, readerArgs); - } - - public T read(String logicalName, ComplexTypeSupplier complexSupplier, WithReaderArgs... readerArgs) throws ParseException { - // TODO: it might be even better if we default to value like in other places... on the other hand a complex type has always a proper logical name so this might be fine like that - boolean hasLogicalName = StringUtils.isNotBlank(logicalName); - if (hasLogicalName) { - readBuffer.pullContext(logicalName, readerArgs); - } - final T t = complexSupplier.get(); - if (hasLogicalName) { - readBuffer.closeContext(logicalName, readerArgs); - } - return t; - } - - @Override - public void pullContext(String logicalName, WithReaderArgs... readerArgs) { - readBuffer.pullContext(logicalName, readerArgs); - } - - @Override - public void closeContext(String logicalName, WithReaderArgs... readerArgs) { - readBuffer.closeContext(logicalName, readerArgs); - } - - @Override - public ReadBuffer getReadBuffer() { - return readBuffer; - } - -} - diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnum.java deleted file mode 100644 index 8822ed53de7..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnum.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public interface DataReaderEnum extends DataReader { - - T read(String logicalName, WithReaderArgs... readerArgs) throws ParseException; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnumDefault.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnumDefault.java deleted file mode 100644 index c997b3373b1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderEnumDefault.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.function.Function; - -public class DataReaderEnumDefault implements DataReaderEnum { - - private static final Logger LOGGER = LoggerFactory.getLogger(DataReaderEnumDefault.class); - - private final Function enumResolver; - private final DataReader dataReader; - - public DataReaderEnumDefault(Function enumResolver, DataReader dataReader) { - this.enumResolver = enumResolver; - this.dataReader = dataReader; - } - - @Override - public int getPos() { - return dataReader.getPos(); - } - - @Override - public void setPos(int position) { - dataReader.setPos(position); - } - - @Override - public ByteOrder getByteOrder() { - return dataReader.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - dataReader.setByteOrder(byteOrder); - } - - @Override - public T read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return read(logicalName, enumResolver, readerArgs); - } - - public T read(String logicalName, Function enumResolver, WithReaderArgs... readerArgs) throws ParseException { - I rawValue = dataReader.read(logicalName, readerArgs); - T enumValue = enumResolver.apply(rawValue); - if (enumValue == null) { - LOGGER.debug("No {} enum found for value {}", logicalName, rawValue); - } - return enumValue; - } - - @Override - public void pullContext(String logicalName, WithReaderArgs... readerArgs) { - dataReader.pullContext(logicalName, readerArgs); - } - - @Override - public void closeContext(String logicalName, WithReaderArgs... readerArgs) { - dataReader.closeContext(logicalName, readerArgs); - } - - @Override - public ReadBuffer getReadBuffer() { - return dataReader.getReadBuffer(); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderFactory.java deleted file mode 100644 index 69a4ed77260..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderFactory.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ReadBuffer; - -import java.math.BigInteger; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.function.Function; - -public class DataReaderFactory { - - public static DataReader readBoolean(ReadBuffer readBuffer) { - return new DataReaderSimpleBoolean(readBuffer); - } - - public static DataReader readUnsignedByte(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleUnsignedByte(readBuffer, bitLength); - } - - public static DataReader readByte(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleByte(readBuffer, bitLength); - } - - public static DataReader readUnsignedShort(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleUnsignedShort(readBuffer, bitLength); - } - - public static DataReader readUnsignedInt(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleUnsignedInt(readBuffer, bitLength); - } - - public static DataReader readUnsignedLong(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleUnsignedLong(readBuffer, bitLength); - } - - public static DataReader readUnsignedBigInteger(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleUnsignedBigInteger(readBuffer, bitLength); - } - - public static DataReader readSignedByte(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleSignedByte(readBuffer, bitLength); - } - - public static DataReader readSignedShort(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleSignedShort(readBuffer, bitLength); - } - - public static DataReader readSignedInt(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleSignedInt(readBuffer, bitLength); - } - - public static DataReader readSignedLong(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleSignedLong(readBuffer, bitLength); - } - - public static DataReader readSignedBigInteger(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleSignedBigInteger(readBuffer, bitLength); - } - - public static DataReader readFloat(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleFloat(readBuffer, bitLength); - } - - public static DataReader readDouble(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleDouble(readBuffer, bitLength); - } - - public static DataReader readString(ReadBuffer readBuffer, int bitLength) { - return new DataReaderSimpleString(readBuffer, bitLength); - } - - public static DataReaderEnumDefault readEnum(Function enumResolver, DataReader dataReader) { - return new DataReaderEnumDefault<>(enumResolver, dataReader); - } - - public static DataReaderComplexDefault readComplex(ComplexTypeSupplier complexSupplier, ReadBuffer readBuffer) { - return new DataReaderComplexDefault<>(complexSupplier, readBuffer); - } - - public static DataReader readDate(ReadBuffer readBuffer) { - return new DataReaderSimpleDate(readBuffer); - } - - public static DataReader readDateTime(ReadBuffer readBuffer) { - return new DataReaderSimpleDateTime(readBuffer); - } - - public static DataReader readTime(ReadBuffer readBuffer) { - return new DataReaderSimpleTime(readBuffer); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBase.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBase.java deleted file mode 100644 index 166ee0af782..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBase.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public abstract class DataReaderSimpleBase implements DataReader { - - protected final ReadBuffer readBuffer; - protected final int bitLength; - - public DataReaderSimpleBase(ReadBuffer readBuffer, int bitLength) { - this.readBuffer = readBuffer; - this.bitLength = bitLength; - } - - public int getPos() { - return readBuffer.getPos(); - } - - public void setPos(int position) { - readBuffer.reset(position); - } - - @Override - public ByteOrder getByteOrder() { - return readBuffer.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - readBuffer.setByteOrder(byteOrder); - } - - @Override - public void pullContext(String logicalName, WithReaderArgs... readerArgs) { - readBuffer.pullContext(logicalName, readerArgs); - } - - @Override - public void closeContext(String logicalName, WithReaderArgs... readerArgs) { - readBuffer.closeContext(logicalName, readerArgs); - } - - @Override - public ReadBuffer getReadBuffer() { - return readBuffer; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBigDecimal.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBigDecimal.java deleted file mode 100644 index c60ab4ec7b6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBigDecimal.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.math.BigDecimal; - -public class DataReaderSimpleBigDecimal extends DataReaderSimpleBase { - - public DataReaderSimpleBigDecimal(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public BigDecimal read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readBigDecimal(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBoolean.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBoolean.java deleted file mode 100644 index 24ce629bebf..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleBoolean.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleBoolean extends DataReaderSimpleBase { - - public DataReaderSimpleBoolean(ReadBuffer readBuffer) { - super(readBuffer, 1); - } - - @Override - public Boolean read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readBit(logicalName, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByte.java deleted file mode 100644 index 072d8369e7b..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByte.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleByte extends DataReaderSimpleBase { - - public DataReaderSimpleByte(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Byte read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - if(bitLength != 8) { - throw new ParseException("Byte fields only support bitLength of 8"); - } - return readBuffer.readByte(logicalName, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByteArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByteArray.java deleted file mode 100644 index dc40e7c2fb9..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleByteArray.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleByteArray extends DataReaderSimpleBase { - - public DataReaderSimpleByteArray(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public byte[] read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - if (bitLength % 8 != 0) { - throw new ParseException("ByteArray fields only support bitLength which are multiples of 8"); - } - return readBuffer.readByteArray(logicalName, bitLength / 8, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDate.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDate.java deleted file mode 100644 index 60081416b49..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDate.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneOffset; - -public class DataReaderSimpleDate extends DataReaderSimpleBase { - - public DataReaderSimpleDate(ReadBuffer readBuffer) { - super(readBuffer, 32); - } - - @Override - public LocalDate read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - long unsignedLong = readBuffer.readUnsignedLong(logicalName, bitLength, readerArgs); - return LocalDate.ofEpochDay(unsignedLong); - } -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDateTime.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDateTime.java deleted file mode 100644 index fd70dd1333e..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDateTime.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.time.LocalDateTime; -import java.time.ZoneOffset; - -public class DataReaderSimpleDateTime extends DataReaderSimpleBase { - - public DataReaderSimpleDateTime(ReadBuffer readBuffer) { - super(readBuffer, 64); - } - - @Override - public LocalDateTime read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - long unsignedLong = readBuffer.readUnsignedLong(logicalName, bitLength, readerArgs); - return LocalDateTime.ofEpochSecond(unsignedLong, 0, ZoneOffset.UTC); - } -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDouble.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDouble.java deleted file mode 100644 index acd99084dfa..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleDouble.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleDouble extends DataReaderSimpleBase { - - public DataReaderSimpleDouble(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Double read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readDouble(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleFloat.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleFloat.java deleted file mode 100644 index 4a3030f9fff..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleFloat.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleFloat extends DataReaderSimpleBase { - - public DataReaderSimpleFloat(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Float read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readFloat(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedBigInteger.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedBigInteger.java deleted file mode 100644 index bd598fd31f3..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedBigInteger.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.math.BigInteger; - -public class DataReaderSimpleSignedBigInteger extends DataReaderSimpleBase { - - public DataReaderSimpleSignedBigInteger(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public BigInteger read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readBigInteger(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedByte.java deleted file mode 100644 index a59aef9c9de..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedByte.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleSignedByte extends DataReaderSimpleBase { - - public DataReaderSimpleSignedByte(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Byte read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readSignedByte(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedInt.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedInt.java deleted file mode 100644 index 1bf1d43a5a7..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedInt.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleSignedInt extends DataReaderSimpleBase { - - public DataReaderSimpleSignedInt(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Integer read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readInt(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedLong.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedLong.java deleted file mode 100644 index ce2fa5c2b49..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedLong.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleSignedLong extends DataReaderSimpleBase { - - public DataReaderSimpleSignedLong(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Long read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readLong(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedShort.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedShort.java deleted file mode 100644 index 762db18c0c5..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleSignedShort.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleSignedShort extends DataReaderSimpleBase { - - public DataReaderSimpleSignedShort(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Short read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readShort(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleString.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleString.java deleted file mode 100644 index 7151dea612a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleString.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleString extends DataReaderSimpleBase { - - public DataReaderSimpleString(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public String read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readString(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleTime.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleTime.java deleted file mode 100644 index f2879dfb5ec..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleTime.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneOffset; - -public class DataReaderSimpleTime extends DataReaderSimpleBase { - - public DataReaderSimpleTime(ReadBuffer readBuffer) { - super(readBuffer, 32); - } - - @Override - public LocalTime read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - long unsignedLong = readBuffer.readUnsignedLong(logicalName, bitLength, readerArgs); - return LocalTime.ofSecondOfDay(unsignedLong); - } -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedBigInteger.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedBigInteger.java deleted file mode 100644 index dc4d0c998a3..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedBigInteger.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -import java.math.BigInteger; - -public class DataReaderSimpleUnsignedBigInteger extends DataReaderSimpleBase { - - public DataReaderSimpleUnsignedBigInteger(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public BigInteger read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readUnsignedBigInteger(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedByte.java deleted file mode 100644 index 3e78a0debbf..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedByte.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleUnsignedByte extends DataReaderSimpleBase { - - public DataReaderSimpleUnsignedByte(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Byte read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readUnsignedByte(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedInt.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedInt.java deleted file mode 100644 index 00dde45cf0d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedInt.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleUnsignedInt extends DataReaderSimpleBase { - - public DataReaderSimpleUnsignedInt(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Integer read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readUnsignedInt(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedLong.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedLong.java deleted file mode 100644 index 5f445cf5215..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedLong.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleUnsignedLong extends DataReaderSimpleBase { - - public DataReaderSimpleUnsignedLong(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Long read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readUnsignedLong(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedShort.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedShort.java deleted file mode 100644 index b9c38b13828..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataReaderSimpleUnsignedShort.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.WithReaderArgs; - -public class DataReaderSimpleUnsignedShort extends DataReaderSimpleBase { - - public DataReaderSimpleUnsignedShort(ReadBuffer readBuffer, int bitLength) { - super(readBuffer, bitLength); - } - - @Override - public Short read(String logicalName, WithReaderArgs... readerArgs) throws ParseException { - return readBuffer.readUnsignedShort(logicalName, bitLength, readerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriter.java deleted file mode 100644 index 809ddab61db..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriter.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public interface DataWriter extends ByteOrderAware, ContextWriter { - - void write(String logicalName, T value, WithWriterArgs... writerArgs) throws SerializationException; - - WriteBuffer getWriteBuffer(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplex.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplex.java deleted file mode 100644 index ad9cb5a8494..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplex.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -public interface DataWriterComplex extends DataWriter { - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplexDefault.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplexDefault.java deleted file mode 100644 index 16e8f1529e3..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterComplexDefault.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.commons.lang3.StringUtils; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DataWriterComplexDefault implements DataWriterComplex { - - private static final Logger LOGGER = LoggerFactory.getLogger(DataWriterComplexDefault.class); - - - protected final WriteBuffer writeBuffer; - - public DataWriterComplexDefault(WriteBuffer writeBuffer) { - this.writeBuffer = writeBuffer; - } - - @Override - public ByteOrder getByteOrder() { - return writeBuffer.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - writeBuffer.setByteOrder(byteOrder); - } - - @Override - public void pushContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.pushContext(logicalName, writerArgs); - } - - @Override - public void popContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.popContext(logicalName, writerArgs); - } - - @Override - public void write(String logicalName, T value, WithWriterArgs... writerArgs) throws SerializationException { - boolean hasLogicalName = StringUtils.isNotBlank(logicalName); - if (hasLogicalName) { - writeBuffer.pushContext(logicalName); - } - if (value == null) { - LOGGER.warn("Trying to serialize null value for {}", logicalName); - } - writeBuffer.writeSerializable(value); - if (hasLogicalName) { - writeBuffer.popContext(logicalName); - } - } - - @Override - public WriteBuffer getWriteBuffer() { - return writeBuffer; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterDataIoDefault.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterDataIoDefault.java deleted file mode 100644 index 588e8a0f781..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterDataIoDefault.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.commons.lang3.StringUtils; -import org.apache.plc4x.java.api.value.PlcValue; -import org.apache.plc4x.java.spi.generation.*; - -public class DataWriterDataIoDefault implements DataWriterComplex { - - protected final WriteBuffer writeBuffer; - protected final DataIoSerializerFunction serializer; - - public DataWriterDataIoDefault(WriteBuffer writeBuffer, DataIoSerializerFunction serializer) { - this.writeBuffer = writeBuffer; - this.serializer = serializer; - } - - @Override - public ByteOrder getByteOrder() { - return writeBuffer.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - writeBuffer.setByteOrder(byteOrder); - } - - @Override - public void pushContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.pushContext(logicalName, writerArgs); - } - - @Override - public void popContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.popContext(logicalName, writerArgs); - } - - @Override - public void write(String logicalName, PlcValue value, WithWriterArgs... writerArgs) throws SerializationException { - boolean hasLogicalName = StringUtils.isNotBlank(logicalName); - if (hasLogicalName) { - writeBuffer.pushContext(logicalName); - } - serializer.apply(writeBuffer, value); - if (hasLogicalName) { - writeBuffer.popContext(logicalName); - } - } - - @Override - public WriteBuffer getWriteBuffer() { - return writeBuffer; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnum.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnum.java deleted file mode 100644 index b448c17f1eb..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnum.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; - -public interface DataWriterEnum extends DataWriter { - - void write(String logicalName, T value, WithWriterArgs... writerArgs) throws SerializationException; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnumDefault.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnumDefault.java deleted file mode 100644 index 6d53bde10db..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterEnumDefault.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.commons.lang3.ArrayUtils; -import org.apache.plc4x.java.spi.generation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.function.Function; - -public class DataWriterEnumDefault implements DataWriterEnum { - - private static final Logger LOGGER = LoggerFactory.getLogger(DataWriterEnumDefault.class); - - private final Function enumSerializer; - private final Function enumNamer; - private final DataWriter dataWriter; - - public DataWriterEnumDefault(Function enumSerializer, Function enumNamer, DataWriter dataWriter) { - this.enumSerializer = enumSerializer; - this.dataWriter = dataWriter; - this.enumNamer = enumNamer; - } - - @Override - public ByteOrder getByteOrder() { - return dataWriter.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - dataWriter.setByteOrder(byteOrder); - } - - @Override - public void write(String logicalName, T value, WithWriterArgs... writerArgs) throws SerializationException { - write(logicalName, value, enumSerializer, enumNamer, dataWriter, writerArgs); - } - - public void write(String logicalName, T value, Function enumSerializer, Function enumNamer, DataWriter rawWriter, WithWriterArgs... writerArgs) throws SerializationException { - if (value == null) { - LOGGER.warn("Trying to serialize null value for {}", logicalName); - return; - } - final I rawValue = enumSerializer.apply(value); - rawWriter.write(logicalName, rawValue, ArrayUtils.addAll(writerArgs, WithReaderWriterArgs.WithAdditionalStringRepresentation(enumNamer.apply(value)))); - } - - @Override - public void pushContext(String logicalName, WithWriterArgs... writerArgs) { - dataWriter.pushContext(logicalName, writerArgs); - } - - @Override - public void popContext(String logicalName, WithWriterArgs... writerArgs) { - dataWriter.popContext(logicalName, writerArgs); - } - - @Override - public WriteBuffer getWriteBuffer() { - return dataWriter.getWriteBuffer(); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterFactory.java deleted file mode 100644 index dbb01f3f13f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterFactory.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.Message; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.math.BigInteger; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.function.Function; - -public class DataWriterFactory { - - public static DataWriter writeBoolean(WriteBuffer writeBuffer) { - return new DataWriterSimpleBoolean(writeBuffer, 1); - } - - public static DataWriter writeUnsignedByte(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleUnsignedByte(writeBuffer, bitLength); - } - - public static DataWriter writeByte(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleByte(writeBuffer, bitLength); - } - - public static DataWriter writeByteArray(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleByteArray(writeBuffer, bitLength); - } - - public static DataWriter writeUnsignedShort(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleUnsignedShort(writeBuffer, bitLength); - } - - public static DataWriter writeUnsignedInt(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleUnsignedInt(writeBuffer, bitLength); - } - - public static DataWriter writeUnsignedLong(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleUnsignedLong(writeBuffer, bitLength); - } - - public static DataWriter writeUnsignedBigInteger(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleUnsignedBigInteger(writeBuffer, bitLength); - } - - public static DataWriter writeSignedByte(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleSignedByte(writeBuffer, bitLength); - } - - public static DataWriter writeSignedShort(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleSignedShort(writeBuffer, bitLength); - } - - public static DataWriter writeSignedInt(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleSignedInt(writeBuffer, bitLength); - } - - public static DataWriter writeSignedLong(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleSignedLong(writeBuffer, bitLength); - } - - public static DataWriter writeSignedBigInteger(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleSignedBigInteger(writeBuffer, bitLength); - } - - public static DataWriter writeFloat(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleFloat(writeBuffer, bitLength); - } - - public static DataWriter writeDouble(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleDouble(writeBuffer, bitLength); - } - - public static DataWriter writeString(WriteBuffer writeBuffer, int bitLength) { - return new DataWriterSimpleString(writeBuffer, bitLength); - } - - public static DataWriterEnumDefault writeEnum(Function enumSerializer, Function enumNamer, DataWriter dataWriter) { - return new DataWriterEnumDefault<>(enumSerializer, enumNamer, dataWriter); - } - - public static DataWriterComplexDefault writeComplex(WriteBuffer writeBuffer) { - return new DataWriterComplexDefault<>(writeBuffer); - } - - public static DataWriterDataIoDefault writeDataIO(WriteBuffer writeBuffer, DataIoSerializerFunction serializer) { - return new DataWriterDataIoDefault(writeBuffer,serializer); - } - - public static DataWriter writeDate(WriteBuffer writeBuffer) { - return new DataWriterSimpleDate(writeBuffer); - } - - public static DataWriter writeDateTime(WriteBuffer writeBuffer) { - return new DataWriterSimpleDateTime(writeBuffer); - } - - public static DataWriter writeTime(WriteBuffer writeBuffer) { - return new DataWriterSimpleTime(writeBuffer); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBase.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBase.java deleted file mode 100644 index 1c442c7813e..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBase.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.codegen.FieldCommons; -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public abstract class DataWriterSimpleBase implements DataWriter, FieldCommons { - - protected final WriteBuffer writeBuffer; - protected final int bitLength; - - public DataWriterSimpleBase(WriteBuffer writeBuffer, int bitLength) { - this.writeBuffer = writeBuffer; - this.bitLength = bitLength; - } - - @Override - public ByteOrder getByteOrder() { - return writeBuffer.getByteOrder(); - } - - @Override - public void setByteOrder(ByteOrder byteOrder) { - writeBuffer.setByteOrder(byteOrder); - } - - @Override - public void pushContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.pushContext(logicalName, writerArgs); - } - - @Override - public void popContext(String logicalName, WithWriterArgs... writerArgs) { - writeBuffer.popContext(logicalName, writerArgs); - } - - @Override - public WriteBuffer getWriteBuffer() { - return writeBuffer; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBigDecimal.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBigDecimal.java deleted file mode 100644 index 8d23b674d94..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBigDecimal.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.math.BigDecimal; - -public class DataWriterSimpleBigDecimal extends DataWriterSimpleBase { - - public DataWriterSimpleBigDecimal(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, BigDecimal value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeBigDecimal(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBoolean.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBoolean.java deleted file mode 100644 index f73c32d47ea..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleBoolean.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleBoolean extends DataWriterSimpleBase { - - public DataWriterSimpleBoolean(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Boolean value, WithWriterArgs... writerArgs) throws SerializationException { - if (bitLength != 1) { - throw new SerializationException("Bit fields only support bitLength of 1"); - } - writeBuffer.writeBit(logicalName, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByte.java deleted file mode 100644 index 0a9d1132cb5..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByte.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleByte extends DataWriterSimpleBase { - - public DataWriterSimpleByte(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Byte value, WithWriterArgs... writerArgs) throws SerializationException { - if(bitLength != 8) { - throw new SerializationException("Byte fields only support bitLength of 8"); - } - writeBuffer.writeByte(logicalName, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByteArray.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByteArray.java deleted file mode 100644 index 6d6986223a2..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleByteArray.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleByteArray extends DataWriterSimpleBase { - - public DataWriterSimpleByteArray(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, byte[] value, WithWriterArgs... writerArgs) throws SerializationException { - if (bitLength != 8) { - throw new SerializationException("ByteArray fields only support bitLength of 8"); - } - // TODO: Get a WirReaderArgs parameter for the number of bytes ... - writeBuffer.writeByteArray(logicalName, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDate.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDate.java deleted file mode 100644 index 8570146df63..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDate.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.time.LocalDate; - -public class DataWriterSimpleDate extends DataWriterSimpleBase { - - public DataWriterSimpleDate(WriteBuffer writeBuffer) { - super(writeBuffer, 32); - } - - @Override - public void write(String logicalName, LocalDate value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedLong(logicalName, bitLength, value.toEpochDay()); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDateTime.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDateTime.java deleted file mode 100644 index cbd0bd6266f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDateTime.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneOffset; - -public class DataWriterSimpleDateTime extends DataWriterSimpleBase { - - public DataWriterSimpleDateTime(WriteBuffer writeBuffer) { - super(writeBuffer, 64); - } - - @Override - public void write(String logicalName, LocalDateTime value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedLong(logicalName, bitLength, value.toEpochSecond(ZoneOffset.UTC)); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDouble.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDouble.java deleted file mode 100644 index 70c5a609a23..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleDouble.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleDouble extends DataWriterSimpleBase { - - public DataWriterSimpleDouble(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Double value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeDouble(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleFloat.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleFloat.java deleted file mode 100644 index 84ad1444cf5..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleFloat.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleFloat extends DataWriterSimpleBase { - - public DataWriterSimpleFloat(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Float value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeFloat(logicalName, bitLength, value); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedBigInteger.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedBigInteger.java deleted file mode 100644 index 54cb6a3d4a6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedBigInteger.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.math.BigInteger; - -public class DataWriterSimpleSignedBigInteger extends DataWriterSimpleBase { - - public DataWriterSimpleSignedBigInteger(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, BigInteger value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeBigInteger(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedByte.java deleted file mode 100644 index a144e12bef6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedByte.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleSignedByte extends DataWriterSimpleBase { - - public DataWriterSimpleSignedByte(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Byte value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeSignedByte(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedInt.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedInt.java deleted file mode 100644 index 17ea447ff1f..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedInt.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleSignedInt extends DataWriterSimpleBase { - - public DataWriterSimpleSignedInt(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Integer value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeInt(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedLong.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedLong.java deleted file mode 100644 index 859a9bf1b87..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedLong.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleSignedLong extends DataWriterSimpleBase { - - public DataWriterSimpleSignedLong(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Long value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeLong(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedShort.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedShort.java deleted file mode 100644 index 54691b8753a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleSignedShort.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleSignedShort extends DataWriterSimpleBase { - - public DataWriterSimpleSignedShort(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Short value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeShort(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleString.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleString.java deleted file mode 100644 index 6da5fc5af36..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleString.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleString extends DataWriterSimpleBase { - - public DataWriterSimpleString(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, String value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeString(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleTime.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleTime.java deleted file mode 100644 index dcc08eb4b12..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleTime.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneOffset; - -public class DataWriterSimpleTime extends DataWriterSimpleBase { - - public DataWriterSimpleTime(WriteBuffer writeBuffer) { - super(writeBuffer, 32); - } - - @Override - public void write(String logicalName, LocalTime value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedLong(logicalName, bitLength, value.toSecondOfDay()); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedBigInteger.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedBigInteger.java deleted file mode 100644 index 4c32fa802ae..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedBigInteger.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -import java.math.BigInteger; - -public class DataWriterSimpleUnsignedBigInteger extends DataWriterSimpleBase { - - public DataWriterSimpleUnsignedBigInteger(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, BigInteger value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedBigInteger(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedByte.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedByte.java deleted file mode 100644 index 162ba8529df..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedByte.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleUnsignedByte extends DataWriterSimpleBase { - - public DataWriterSimpleUnsignedByte(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Byte value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedByte(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedInt.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedInt.java deleted file mode 100644 index 8ca98b7f30a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedInt.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleUnsignedInt extends DataWriterSimpleBase { - - public DataWriterSimpleUnsignedInt(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Integer value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedInt(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedLong.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedLong.java deleted file mode 100644 index d1c71d22e98..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedLong.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleUnsignedLong extends DataWriterSimpleBase { - - public DataWriterSimpleUnsignedLong(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Long value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedLong(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedShort.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedShort.java deleted file mode 100644 index 5b914fdc970..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/DataWriterSimpleUnsignedShort.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WithWriterArgs; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class DataWriterSimpleUnsignedShort extends DataWriterSimpleBase { - - public DataWriterSimpleUnsignedShort(WriteBuffer writeBuffer, int bitLength) { - super(writeBuffer, bitLength); - } - - @Override - public void write(String logicalName, Short value, WithWriterArgs... writerArgs) throws SerializationException { - writeBuffer.writeUnsignedShort(logicalName, bitLength, value, writerArgs); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ParseSupplier.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ParseSupplier.java deleted file mode 100644 index ac9c7bd4321..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/ParseSupplier.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; - -@FunctionalInterface -public interface ParseSupplier { - - T get() throws ParseException; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/PositionMover.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/PositionMover.java deleted file mode 100644 index 2b3a470a0bc..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/PositionMover.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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 - * - * http://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. - */ - -package org.apache.plc4x.java.spi.codegen.io; - -public interface PositionMover { - int getPos(); - - void setPos(int position); -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/VintIo.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/VintIo.java deleted file mode 100644 index 2631cc95cbe..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/codegen/io/VintIo.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.codegen.io; - -import org.apache.plc4x.java.spi.generation.ParseException; -import org.apache.plc4x.java.spi.generation.ReadBuffer; -import org.apache.plc4x.java.spi.generation.SerializationException; -import org.apache.plc4x.java.spi.generation.WriteBuffer; - -public class VintIo { - - public static int getLengthInBytes(long value) { - int numBytes = 1; - // Keep on shifting the value left 7 bits, till the value is 0. - while((value & 0xFFFFFF80) != 0) { - numBytes++; - value = value >> 7; - } - return numBytes; - } - - public static void serialize(long value, WriteBuffer writeBuffer) throws SerializationException { - serializeInternally(value, writeBuffer, true); - } - - private static void serializeInternally(long value, WriteBuffer writeBuffer, boolean lastByte) throws SerializationException { - byte curValue = (byte) ((value & 0x7F) | (lastByte ? 0x00 : 0x80)); - long restValue = value >> 7; - // Recursively serialize the others first. - if(restValue != 0) { - serializeInternally(restValue, writeBuffer, false); - } - // Now serialize the last byte. - writeBuffer.writeUnsignedShort(8, curValue); - } - - public static long parse(ReadBuffer readBuffer) throws ParseException { - long curValue = 0; - short curByte; - do { - // Get the next byte - curByte = readBuffer.readUnsignedShort(8); - // Add the 7 least significant bits to the value. - curValue |= (curByte & 0x7F); - // If the highest bit is set, shift the value right 7 bits and read the next byte. - if((curByte & 0x80) != 0) { - curValue = curValue << 7; - } - } while ((curByte & 0x80) != 0); - return curValue; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java deleted file mode 100644 index cb9f6fd493d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration; - -import org.apache.commons.lang3.ClassUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.plc4x.java.api.exceptions.PlcRuntimeException; -import org.apache.plc4x.java.spi.configuration.annotations.ComplexConfigurationParameter; -import org.apache.plc4x.java.spi.configuration.annotations.ConfigurationParameter; -import org.apache.plc4x.java.spi.configuration.annotations.ParameterConverter; -import org.apache.plc4x.java.spi.configuration.annotations.Required; -import org.apache.plc4x.java.spi.configuration.annotations.defaults.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static java.util.stream.Collectors.mapping; -import static java.util.stream.Collectors.toList; - -/** - * A query contains for our cases mostly of three parts - * - protocol identifier - * - (optional) transport identifier - * - connection address (ip/port), serial port, path (depending on the type of transport) ... - * - (optional) path parameters - */ -public class ConfigurationFactory { - - private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationFactory.class); - - public T createConfiguration(Class pClazz, String protocolCode, String transportCode, - String transportConfig, String paramString) { - - // Get a map of all parameters in the connection string. - Map> paramStringValues = splitQuery(paramString); - return createConfiguration(pClazz, protocolCode, transportCode, transportConfig, paramStringValues); - } - - public T createTransportConfiguration(Class pClazz, String protocolCode, - String transportCode, String transportConfig, - String paramString) { - // Get a map of all parameters in the connection string. - Map> paramStringValues = splitQuery(paramString); - // Filter out the properties, that don't have the current transport code as prefix. - String prefix = transportCode + "."; - Map> filteredParamStringValues = new HashMap<>(); - for (String paramName : paramStringValues.keySet()) { - if(paramName.startsWith(prefix)) { - filteredParamStringValues.put(paramName.substring(prefix.length()), paramStringValues.get(paramName)); - } - } - return createConfiguration(pClazz, protocolCode, transportCode, transportConfig, filteredParamStringValues); - } - - public T createConfiguration(Class pClazz, String protocolCode, String transportCode, - String transportConfig, Map> paramStringValues) { - // Get a map of all configuration parameter fields. - // - Get a list of all fields in the given class. - Map fields = Arrays.stream(FieldUtils.getAllFields(pClazz)) - // - Filter out only the ones annotated with the ConfigurationParameter annotation. - .filter(field -> (field.getAnnotation(ConfigurationParameter.class) != null) || (field.getAnnotation(ComplexConfigurationParameter.class) != null)) - // - Create a map with the field-name as key and the field itself as value. - .collect(Collectors.toMap( - ConfigurationFactory::getConfigurationName, - Function.identity() - )); - - // Get a list of all required configuration parameters. - // TODO: Check for the complex-fields with required annotations. - List missingFieldNames = fields.values().stream() - .filter(field -> field.getAnnotation(Required.class) != null) - .map(ConfigurationFactory::getConfigurationName) - .collect(toList()); - - // Create a new instance of the configuration object. - T instance; - try { - instance = pClazz.getDeclaredConstructor().newInstance(); - } catch (InvocationTargetException | InstantiationException | - IllegalAccessException | NoSuchMethodException e) { - throw new IllegalArgumentException("Unable to Instantiate Configuration Class", e); - } - - // Process the parameters passed in with the connection string. - try { - // Add the other codes to the param strings, so we can make them accessible from Configurations. - // Like this: - // @ConfigurationParameter("protocolCode") - // private String protocolCode; - paramStringValues = new HashMap<>(paramStringValues); - List previousValue; - previousValue = paramStringValues.put("protocol-code", List.of(protocolCode)); - if (previousValue != null) { - LOGGER.warn("protocolCode with value {} overridden by", protocolCode); - } - previousValue = paramStringValues.put("transport-code", List.of(transportCode)); - if (previousValue != null) { - LOGGER.warn("transportCode with value {} overridden by", transportCode); - } - previousValue = paramStringValues.put("transport-config", List.of(transportConfig)); - if (previousValue != null) { - LOGGER.warn("transportConfig with value {} overridden by", transportConfig); - } - - // Iterate over all fields and set the values to either the values specified - // in the param string or to defaults configured by annotations. - for (Map.Entry entry : fields.entrySet()) { - final String configName = entry.getKey(); - final Field field = fields.get(configName); - if (field.getAnnotation(ComplexConfigurationParameter.class) != null) { - // Filter out only the parameters with the given prefix. - String prefix = field.getAnnotation(ComplexConfigurationParameter.class).prefix() + "."; - Map> filteredParamStringValues = new HashMap<>(); - for (String paramName : paramStringValues.keySet()) { - if(paramName.startsWith(prefix)) { - filteredParamStringValues.put(paramName.substring(prefix.length()), paramStringValues.get(paramName)); - } - } - Class configType = (Class) field.getType(); - PlcConfiguration configValue = createConfiguration(configType, protocolCode, transportCode, transportConfig, filteredParamStringValues); - FieldUtils.writeField(instance, field.getName(), configValue, true); - } else if (paramStringValues.containsKey(configName)) { - String stringValue = paramStringValues.get(configName).get(0); - // As the arguments might be URL encoded, be sure it's decoded. - stringValue = URLDecoder.decode(stringValue, StandardCharsets.UTF_8); - FieldUtils.writeField(instance, field.getName(), toFieldValue(field, stringValue), true); - missingFieldNames.remove(configName); - } else { - Object defaultValue = getDefaultValueFromAnnotation(field); - // TODO: Check if the default values type matches. - if (defaultValue != null) { - FieldUtils.writeField(instance, field.getName(), defaultValue, true); - missingFieldNames.remove(configName); - } - } - } - - // If in the end still some required parameters are missing, output an error. - if (!missingFieldNames.isEmpty()) { - throw new IllegalArgumentException("Missing required fields: " + missingFieldNames); - } - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Unable to access all fields from Configuration Class '" + pClazz.getSimpleName() + "'", e); - } - return instance; - } - - public static T configure(PlcConfiguration configuration, T obj) { - // Check if in this object is configurable at all. - if (ClassUtils.isAssignable(obj.getClass(), HasConfiguration.class)) { - // Check if the type declared by the HasConfiguration interface is - // compatible with the given configuration type. - Optional typeOptional = Arrays.stream(obj.getClass().getGenericInterfaces()) - // Check if the interface has a type parameter - .filter(ParameterizedType.class::isInstance) - .map(ParameterizedType.class::cast) - .filter(type -> type.getRawType().equals(HasConfiguration.class)) - .findAny(); - if (typeOptional.isPresent()) { - final ParameterizedType parameterizedType = typeOptional.get(); - final Type configType = parameterizedType.getActualTypeArguments()[0]; - if (configType instanceof Class) { - Class configClass = (Class) configType; - if (configClass.isAssignableFrom(configuration.getClass())) { - try { - ((HasConfiguration) obj).setConfiguration(configuration); - } catch (Throwable t) { - LOGGER.error("Error setting the configuration", t); - throw new PlcRuntimeException("Error setting the configuration", t); - } - } - } - } - - } - return obj; - } - - /** - * Get the configuration parameter name for configuration parameters. - * If an explicit name is provided in the annotation, use that else use the name of the field itself. - * - * @param field name of the field. - * @return name of the configuration (either from the annotation or from the field itself) - */ - public static String getConfigurationName(Field field) { - if (field.getAnnotation(ComplexConfigurationParameter.class) != null) { - return field.getAnnotation(ComplexConfigurationParameter.class).prefix(); - } else if (StringUtils.isBlank(field.getAnnotation(ConfigurationParameter.class).value())) { - return field.getName(); - } else { - return field.getAnnotation(ConfigurationParameter.class).value(); - } - } - - /** - * Convert the string value from the parameter string into the type the field requires. - * - * @param field field that should be set - * @param valueString string representation of the value - * @return parsed value of the field in the type the field requires - */ - private static Object toFieldValue(Field field, String valueString) { - if (field == null) { - throw new IllegalArgumentException("Field not defined"); - } - - if (field.getAnnotation(ParameterConverter.class) != null) { - Class> converterClass = field.getAnnotation(ParameterConverter.class).value(); - - try { - ConfigurationParameterConverter converter = converterClass.getDeclaredConstructor().newInstance(); - if (converter.getType().isAssignableFrom(field.getType())) { - return converter.convert(valueString); - } - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | - NoSuchMethodException e) { - throw new IllegalArgumentException("Could not initialize parameter converter", e); - } - throw new IllegalArgumentException("Unsupported field type " + field.getType() + " for converter " + converterClass); - } - - if (field.getType() == String.class) { - return valueString; - } - if ((field.getType() == boolean.class) || (field.getType() == Boolean.class)) { - return Boolean.parseBoolean(valueString); - } - if ((field.getType() == byte.class) || (field.getType() == Byte.class)) { - return Byte.parseByte(valueString); - } - if ((field.getType() == short.class) || (field.getType() == Short.class)) { - return Short.parseShort(valueString); - } - if ((field.getType() == int.class) || (field.getType() == Integer.class)) { - return Integer.parseInt(valueString); - } - if ((field.getType() == long.class) || (field.getType() == Long.class)) { - return Long.parseLong(valueString); - } - if ((field.getType() == float.class) || (field.getType() == Float.class)) { - return Float.parseFloat(valueString); - } - if ((field.getType() == double.class) || (field.getType() == Double.class)) { - return Double.parseDouble(valueString); - } - if (field.getType() == File.class) { - return new File(valueString); - } - if (field.getType().isEnum()) { - return parseEnumValue(field, valueString); - } - throw new IllegalArgumentException("Unsupported property type " + field.getType().getName()); - } - - public static Object getDefaultValueFromAnnotation(Field field) { - IntDefaultValue intDefaultValue = field.getAnnotation(IntDefaultValue.class); - if (intDefaultValue != null) { - return intDefaultValue.value(); - } - LongDefaultValue longDefaultValue = field.getAnnotation(LongDefaultValue.class); - if(longDefaultValue != null) { - return longDefaultValue.value(); - } - BooleanDefaultValue booleanDefaultValue = field.getAnnotation(BooleanDefaultValue.class); - if (booleanDefaultValue != null) { - return booleanDefaultValue.value(); - } - FloatDefaultValue floatDefaultValue = field.getAnnotation(FloatDefaultValue.class); - if (floatDefaultValue != null) { - return floatDefaultValue.value(); - } - DoubleDefaultValue doubleDefaultValue = field.getAnnotation(DoubleDefaultValue.class); - if (doubleDefaultValue != null) { - return doubleDefaultValue.value(); - } - StringDefaultValue stringDefaultValue = field.getAnnotation(StringDefaultValue.class); - if (stringDefaultValue != null) { - if (field.getType().isEnum()) { - return parseEnumValue(field, stringDefaultValue.value()); - } - return stringDefaultValue.value(); - } - return null; - } - - private static Enum parseEnumValue(Field field, String valueString) { - return Enum.valueOf((Class) field.getType(), valueString); - } - - /** - * https://stackoverflow.com/questions/13592236/parse-a-uri-string-into-name-value-collection/13592567#13592567 - */ - private static Map> splitQuery(String paramString) { - if (StringUtils.isBlank(paramString)) { - return Collections.emptyMap(); - } - // Split the individual parameters which are separated by "&" characters. - return Arrays.stream(paramString.split("&")) - // Split the stream of parameters (Which can be "key=value", "key=" or just "key" into tuples of - // "key & value" - .map(ConfigurationFactory::splitQueryParameter) - // Build a map of "key & List" where the values of elements with equal "key" are - // added to a list of values. - .collect(Collectors.groupingBy(AbstractMap.SimpleImmutableEntry::getKey, LinkedHashMap::new, - mapping(Map.Entry::getValue, toList()))); - } - - private static AbstractMap.SimpleImmutableEntry splitQueryParameter(String it) { - final int idx = it.indexOf('='); - final String key = idx > 0 ? it.substring(0, idx) : it; - final String value = idx > 0 && it.length() > idx + 1 ? it.substring(idx + 1) : null; - return new AbstractMap.SimpleImmutableEntry<>(key, value); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationParameterConverter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationParameterConverter.java deleted file mode 100644 index 582a806b52d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationParameterConverter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration; - -/** - * Interface which allows to convert parameter from URI into its complex form. - */ -public interface ConfigurationParameterConverter { - - /** - * Type of supported configuration parameter. - * - * Returned value determines Java type to which this converter is able to turn string representation. Only if field - * type is assignable to returned type conversion attempt will be made. - * - * @return Java type constructed by converter. - */ - Class getType(); - - /** - * Executes conversion of parameter textual representation into java object. - * - * @param value Parameter value. - * @return Object representing passed string value. - */ - T convert(String value); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/HasConfiguration.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/HasConfiguration.java deleted file mode 100644 index 08ab0b7b7d1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/HasConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration; - -/** - * (Marker) Interface which can be used to tell PLC4X that a class (that is instantiated by PLC4X) - * has a Configuration. - * PLC4X will then try to Instantiate the Class and populate it based on Connection Parameters. - * - * @param Class of the Configuration - */ -public interface HasConfiguration { - - /** - * Is called directly after instantiation before the class is used somewhere. - */ - void setConfiguration(CONFIGURATION configuration); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConfiguration.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConfiguration.java deleted file mode 100644 index cb8d1c856b4..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 - * - * http://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. - */ - -package org.apache.plc4x.java.spi.configuration; - -public interface PlcConfiguration { -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConnectionConfiguration.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConnectionConfiguration.java deleted file mode 100644 index ba72bf80483..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcConnectionConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 - * - * http://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. - */ - -package org.apache.plc4x.java.spi.configuration; - -public interface PlcConnectionConfiguration extends PlcConfiguration { -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcTransportConfiguration.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcTransportConfiguration.java deleted file mode 100644 index cb9908665a6..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/PlcTransportConfiguration.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 - * - * http://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. - */ -package org.apache.plc4x.java.spi.configuration; - -public interface PlcTransportConfiguration extends PlcConfiguration { -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameter.java deleted file mode 100644 index ca5b916c306..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameter.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface ComplexConfigurationParameter { - - String prefix() default ""; - - ComplexConfigurationParameterDefaultOverride[] defaultOverrides(); - - ComplexConfigurationParameterRequiredOverride[] requiredOverrides(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterDefaultOverride.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterDefaultOverride.java deleted file mode 100644 index 0184308b81c..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterDefaultOverride.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -public @interface ComplexConfigurationParameterDefaultOverride { - - String name() default ""; - - String value() default ""; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterRequiredOverride.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterRequiredOverride.java deleted file mode 100644 index 72559b6e3df..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ComplexConfigurationParameterRequiredOverride.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -public @interface ComplexConfigurationParameterRequiredOverride { - - String name() default ""; - - boolean required() default false; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ConfigurationParameter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ConfigurationParameter.java deleted file mode 100644 index e17b0c25482..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ConfigurationParameter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface ConfigurationParameter { - - String value() default ""; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Description.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Description.java deleted file mode 100644 index 4bd1e811068..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Description.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Description { - - String value() default ""; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ParameterConverter.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ParameterConverter.java deleted file mode 100644 index e2644bde291..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/ParameterConverter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.apache.plc4x.java.spi.configuration.ConfigurationParameterConverter; - -/** - * Helper annotation to customize handling of configuration parameter conversion. - */ -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface ParameterConverter { - - /** - * Type which should be used for conversion of text value to object representation. - * - * @return Class implementing necessary conversion logic. - */ - Class> value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Required.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Required.java deleted file mode 100644 index e6347c98b7a..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Required.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Required { -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Since.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Since.java deleted file mode 100644 index 461e746c7ae..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/Since.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface Since { - - String value() default ""; - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/BooleanDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/BooleanDefaultValue.java deleted file mode 100644 index 92c84aeb6d9..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/BooleanDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface BooleanDefaultValue { - - boolean value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/DoubleDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/DoubleDefaultValue.java deleted file mode 100644 index e867a5a5851..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/DoubleDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface DoubleDefaultValue { - - double value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/FloatDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/FloatDefaultValue.java deleted file mode 100644 index 9e595d22a48..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/FloatDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface FloatDefaultValue { - - float value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/IntDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/IntDefaultValue.java deleted file mode 100644 index f2ed5c2ef45..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/IntDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface IntDefaultValue { - - int value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/LongDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/LongDefaultValue.java deleted file mode 100644 index cefb47e6fdf..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/LongDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface LongDefaultValue { - - long value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/StringDefaultValue.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/StringDefaultValue.java deleted file mode 100644 index 64c37f88bb2..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/annotations/defaults/StringDefaultValue.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.annotations.defaults; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -public @interface StringDefaultValue { - - String value(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/exceptions/ConfigurationException.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/exceptions/ConfigurationException.java deleted file mode 100644 index 9ee9ea4e262..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/exceptions/ConfigurationException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.configuration.exceptions; - -public class ConfigurationException extends RuntimeException { - - public ConfigurationException() { - } - - public ConfigurationException(String message) { - super(message); - } - - public ConfigurationException(String message, Throwable cause) { - super(message, cause); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/AbstractPlcConnection.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/AbstractPlcConnection.java deleted file mode 100644 index 8674e6489f8..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/AbstractPlcConnection.java +++ /dev/null @@ -1,396 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import org.apache.commons.lang3.NotImplementedException; -import org.apache.plc4x.java.api.PlcConnection; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.api.exceptions.PlcRuntimeException; -import org.apache.plc4x.java.api.exceptions.PlcUnsupportedOperationException; -import org.apache.plc4x.java.api.messages.*; -import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata; -import org.apache.plc4x.java.api.model.PlcConsumerRegistration; -import org.apache.plc4x.java.api.model.PlcSubscriptionHandle; -import org.apache.plc4x.java.api.model.PlcSubscriptionTag; -import org.apache.plc4x.java.api.model.PlcTag; -import org.apache.plc4x.java.api.types.PlcResponseCode; -import org.apache.plc4x.java.api.value.PlcValue; -import org.apache.plc4x.java.spi.Plc4xProtocolBase; -import org.apache.plc4x.java.spi.generation.Message; -import org.apache.plc4x.java.spi.messages.*; -import org.apache.plc4x.java.spi.messages.utils.DefaultPlcResponseItem; -import org.apache.plc4x.java.spi.messages.utils.DefaultPlcTagItem; -import org.apache.plc4x.java.spi.messages.utils.PlcResponseItem; -import org.apache.plc4x.java.spi.messages.utils.PlcTagItem; -import org.apache.plc4x.java.spi.messages.utils.PlcTagValueItem; -import org.apache.plc4x.java.spi.optimizer.BaseOptimizer; -import org.apache.plc4x.java.spi.values.PlcValueHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; - -/** - * Base class for implementing connections. - * Per default, all operations (read, write, subscribe) are unsupported. - * Concrete implementations should override the methods indicating connection capabilities - * and for obtaining respective request builders. - */ -public abstract class AbstractPlcConnection implements PlcConnection, PlcConnectionMetadata, PlcPinger, PlcReader, PlcWriter, PlcSubscriber, PlcBrowser { - - protected static final Logger logger = LoggerFactory.getLogger(AbstractPlcConnection.class); - - private boolean canPing = false; - private boolean canRead = false; - private boolean canWrite = false; - private boolean canSubscribe = false; - private boolean canBrowse = false; - private final PlcValueHandler valueHandler; - private final BaseOptimizer optimizer; - private final PlcAuthentication authentication; - private Plc4xProtocolBase protocol; - private PlcTagHandler tagHandler; - - protected AbstractPlcConnection(boolean canPing, boolean canRead, boolean canWrite, - boolean canSubscribe, boolean canBrowse, - PlcValueHandler valueHandler, - BaseOptimizer optimizer, PlcAuthentication authentication) { - this.canPing = canPing; - this.canRead = canRead; - this.canWrite = canWrite; - this.canSubscribe = canSubscribe; - this.canBrowse = canBrowse; - this.valueHandler = valueHandler; - this.optimizer = optimizer; - this.authentication = authentication; - } - - protected AbstractPlcConnection(boolean canPing, boolean canRead, boolean canWrite, - boolean canSubscribe, boolean canBrowse, - PlcValueHandler valueHandler, - PlcTagHandler tagHandler, - BaseOptimizer optimizer, PlcAuthentication authentication) { - this.canPing = canPing; - this.canRead = canRead; - this.canWrite = canWrite; - this.canSubscribe = canSubscribe; - this.canBrowse = canBrowse; - this.valueHandler = valueHandler; - this.tagHandler = tagHandler; - this.optimizer = optimizer; - this.authentication = authentication; - } - - public void setProtocol(Plc4xProtocolBase protocol) { - this.protocol = protocol; - this.tagHandler = protocol.getTagHandler(); - } - - public Plc4xProtocolBase getProtocol() { - return protocol; - } - - @Override - public PlcConnectionMetadata getMetadata() { - return this; - } - - @Override - public CompletableFuture ping() { - CompletableFuture future = new CompletableFuture<>(); - future.completeExceptionally(new PlcUnsupportedOperationException("The connection does not support pinging")); - return future; - } - - - @Override - public boolean isReadSupported() { - return canRead; - } - - @Override - public boolean isWriteSupported() { - return canWrite; - } - - @Override - public boolean isSubscribeSupported() { - return canSubscribe; - } - - @Override - public boolean isBrowseSupported() { - return canBrowse; - } - - public PlcTagHandler getPlcTagHandler() { - return this.tagHandler; - } - - public PlcValueHandler getPlcValueHandler() { - return this.valueHandler; - } - - protected PlcAuthentication getAuthentication() { - return authentication; - } - - @Override - public PlcReadRequest.Builder readRequestBuilder() { - if (!isReadSupported()) { - throw new PlcUnsupportedOperationException("The connection does not support reading"); - } - return new DefaultPlcReadRequest.Builder(this, getPlcTagHandler()); - } - - @Override - public PlcWriteRequest.Builder writeRequestBuilder() { - if (!isWriteSupported()) { - throw new PlcUnsupportedOperationException("The connection does not support writing"); - } - return new DefaultPlcWriteRequest.Builder(this, getPlcTagHandler(), getPlcValueHandler()); - } - - @Override - public PlcSubscriptionRequest.Builder subscriptionRequestBuilder() { - if (!isSubscribeSupported()) { - throw new PlcUnsupportedOperationException("The connection does not support subscription"); - } - return new DefaultPlcSubscriptionRequest.Builder(this, getPlcTagHandler()); - } - - @Override - public PlcUnsubscriptionRequest.Builder unsubscriptionRequestBuilder() { - if (!canSubscribe) { - throw new PlcUnsupportedOperationException("The connection does not support subscription"); - } - return new DefaultPlcUnsubscriptionRequest.Builder(this); - } - - @Override - public PlcBrowseRequest.Builder browseRequestBuilder() { - if (!canBrowse) { - throw new PlcUnsupportedOperationException("The connection does not support browsing"); - } - return new DefaultPlcBrowseRequest.Builder(this, getPlcTagHandler()); - } - - @Override - public CompletableFuture ping(PlcPingRequest pingRequest) { - if (!canPing) { - throw new PlcUnsupportedOperationException("The connection does not support pinging"); - } - return protocol.ping(pingRequest); - } - - @Override - public CompletableFuture read(PlcReadRequest readRequest) { - PlcReadRequest filteredReadRequest = getFilteredReadRequest((DefaultPlcReadRequest) readRequest); - return internalRead(filteredReadRequest) - .thenApply(filteredReadResponse -> { - // Shortcut for the case that all tags were valid. - if(readRequest.getNumberOfTags() == filteredReadRequest.getNumberOfTags()) { - return filteredReadResponse; - } - - Map> values = new HashMap<>(); - for (String tagName : readRequest.getTagNames()) { - // If the tag was correct, then we expect a response in the response. - if(filteredReadRequest.getTagResponseCode(tagName) != null) { - values.put(tagName, ((DefaultPlcReadResponse) filteredReadResponse).getPlcResponseItem(tagName)); - } - // In all other cases forward the initial error to the final output. - else { - values.put(tagName, new DefaultPlcResponseItem<>(readRequest.getTagResponseCode(tagName), null)); - } - } - return new DefaultPlcReadResponse(readRequest, values); - }); - } - - protected CompletableFuture internalRead(PlcReadRequest readRequest) { - if(optimizer != null) { - return optimizer.optimizedRead(readRequest, protocol); - } - return protocol.read(readRequest); - } - - @Override - public CompletableFuture write(PlcWriteRequest writeRequest) { - PlcWriteRequest filteredWriteRequest = getFilteredWriteRequest((DefaultPlcWriteRequest) writeRequest); - return internalWrite(filteredWriteRequest) - .thenApply(filteredWriteResponse -> { - // Shortcut for the case that all tags were valid. - if(writeRequest.getNumberOfTags() == filteredWriteRequest.getNumberOfTags()) { - return filteredWriteResponse; - } - - Map values = new HashMap<>(); - for (String tagName : writeRequest.getTagNames()) { - // If the tag was correct, then we expect a response in the response. - if(filteredWriteRequest.getTagResponseCode(tagName) != null) { - values.put(tagName, filteredWriteResponse.getResponseCode(tagName)); - } - // In all other cases forward the initial error to the final output. - else { - values.put(tagName, writeRequest.getTagResponseCode(tagName)); - } - } - return new DefaultPlcWriteResponse(writeRequest, values); - }); - } - - protected CompletableFuture internalWrite(PlcWriteRequest writeRequest) { - if(optimizer != null) { - return optimizer.optimizedWrite(writeRequest, protocol); - } - return protocol.write(writeRequest); - } - - @Override - public CompletableFuture subscribe(PlcSubscriptionRequest subscriptionRequest) { - PlcSubscriptionRequest filteredSubscriptionRequest = getFilteredSubscriptionRequest((DefaultPlcSubscriptionRequest) subscriptionRequest); - return internalSubscribe(filteredSubscriptionRequest) - .thenApply(filteredSubscriptionResponse -> { - // Shortcut for the case that all tags were valid. - if(subscriptionRequest.getNumberOfTags() == filteredSubscriptionRequest.getNumberOfTags()) { - return filteredSubscriptionResponse; - } - - Map> values = new HashMap<>(); - for (String tagName : subscriptionRequest.getTagNames()) { - // If the tag was correct, then we expect a response in the response. - if(filteredSubscriptionRequest.getTagResponseCode(tagName) != null) { - values.put(tagName, new DefaultPlcResponseItem<>(filteredSubscriptionRequest.getTagResponseCode(tagName), filteredSubscriptionResponse.getSubscriptionHandle(tagName))); - } - // In all other cases forward the initial error to the final output. - else { - values.put(tagName, new DefaultPlcResponseItem<>(subscriptionRequest.getTagResponseCode(tagName), null)); - } - } - return new DefaultPlcSubscriptionResponse(subscriptionRequest, values); - }); - } - - public CompletableFuture internalSubscribe(PlcSubscriptionRequest subscriptionRequest) { - if(optimizer != null) { - return optimizer.optimizedSubscribe(subscriptionRequest, protocol); - } - return protocol.subscribe(subscriptionRequest); - } - - /** - * No need to do the whole innerUnsubscribe thing here, as the request only contains handles - * returned by the previous subscription request. So we've already filtered out the invalid - * tags. - * @param unsubscriptionRequest unsubscription request containing at least one unsubscription request item. - * @return future for the response. - */ - @Override - public CompletableFuture unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest) { - if(optimizer != null) { - return optimizer.optimizedUnsubscribe(unsubscriptionRequest, protocol); - } - return protocol.unsubscribe(unsubscriptionRequest); - } - - @Override - public PlcConsumerRegistration register(Consumer consumer, Collection handles) { - throw new NotImplementedException(""); - } - - @Override - public void unregister(PlcConsumerRegistration registration) { - throw new NotImplementedException(""); - } - - @Override - public CompletableFuture browse(PlcBrowseRequest browseRequest) { - return protocol.browse(browseRequest); - } - - @Override - public CompletableFuture browseWithInterceptor(PlcBrowseRequest browseRequest, PlcBrowseRequestInterceptor interceptor) { - return protocol.browseWithInterceptor(browseRequest, interceptor); - } - - @Override - public Optional parseTagAddress(String tagAddress) { - PlcTag plcTag; - try { - plcTag = tagHandler.parseTag(tagAddress); - } catch (Exception e) { - throw new PlcRuntimeException("Error parsing tag address: " + tagAddress, e); - } - return Optional.ofNullable(plcTag); - } - - @Override - public Optional parseTagValue(PlcTag tag, Object... values) { - PlcValue plcValue; - try { - plcValue = valueHandler.newPlcValue(tag, values); - } catch (Exception e) { - throw new PlcRuntimeException("Error parsing tag value " + tag, e); - } - return Optional.of(plcValue); - } - - protected PlcReadRequest getFilteredReadRequest(DefaultPlcReadRequest readRequest) { - LinkedHashMap> filteredTags = new LinkedHashMap<>(); - for (String tagName : readRequest.getTagNames()) { - if(readRequest.getTagResponseCode(tagName) == PlcResponseCode.OK) { - filteredTags.put(tagName, readRequest.getTagItem(tagName)); - } - } - return new DefaultPlcReadRequest(readRequest.getReader(), filteredTags); - } - - protected PlcWriteRequest getFilteredWriteRequest(DefaultPlcWriteRequest writeRequest) { - LinkedHashMap> filteredTags = new LinkedHashMap<>(); - for (String tagName : writeRequest.getTagNames()) { - if(writeRequest.getTagResponseCode(tagName) == PlcResponseCode.OK) { - filteredTags.put(tagName, writeRequest.getTagValueItem(tagName)); - } - } - return new DefaultPlcWriteRequest(writeRequest.getWriter(), filteredTags); - } - - protected PlcSubscriptionRequest getFilteredSubscriptionRequest(DefaultPlcSubscriptionRequest subscriptionRequest) { - LinkedHashMap> filteredTags = new LinkedHashMap<>(); - LinkedHashMap> filteredConsumers = new LinkedHashMap<>(); - for (String tagName : subscriptionRequest.getTagNames()) { - if(subscriptionRequest.getTagResponseCode(tagName) == PlcResponseCode.OK) { - filteredTags.put(tagName, new DefaultPlcTagItem<>(subscriptionRequest.getTag(tagName))); - if(subscriptionRequest.getTagConsumer(tagName) != null) { - filteredConsumers.put(tagName, subscriptionRequest.getTagConsumer(tagName)); - } - } - } - return new DefaultPlcSubscriptionRequest(subscriptionRequest.getSubscriber(), - filteredTags, subscriptionRequest.getConsumer(), filteredConsumers); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelExposingConnection.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelExposingConnection.java deleted file mode 100644 index aa97fbf8b44..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelExposingConnection.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import io.netty.channel.Channel; - -public interface ChannelExposingConnection { - - Channel getChannel(); - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelFactory.java deleted file mode 100644 index cd034bda35d..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/ChannelFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelPipeline; -import org.apache.plc4x.java.api.exceptions.PlcConnectionException; - -public interface ChannelFactory { - - Channel createChannel(ChannelHandler channelHandler) throws PlcConnectionException; - - boolean isPassive(); - - /** Possibility to add an initial Layer to the Pipeline */ - default void initializePipeline(ChannelPipeline pipeline) { - // Intentionally do Nothing - } - - default void closeEventLoopForChannel(Channel channel) { - // By default do nothing for compatibility - // Extending classes should implement their logic here - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/CustomProtocolStackConfigurer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/CustomProtocolStackConfigurer.java deleted file mode 100644 index c61c25e7df1..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/CustomProtocolStackConfigurer.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * 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. - */ - -package org.apache.plc4x.java.spi.connection; - -import static org.apache.plc4x.java.spi.configuration.ConfigurationFactory.*; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelPipeline; -import io.netty.handler.codec.MessageToMessageCodec; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration; -import org.apache.plc4x.java.api.listener.EventListener; -import org.apache.plc4x.java.spi.EventListenerMessageCodec; -import org.apache.plc4x.java.spi.Plc4xNettyWrapper; -import org.apache.plc4x.java.spi.Plc4xProtocolBase; -import org.apache.plc4x.java.spi.context.DriverContext; -import org.apache.plc4x.java.spi.generation.ByteOrder; -import org.apache.plc4x.java.spi.generation.Message; -import org.apache.plc4x.java.spi.generation.MessageInput; -import org.apache.plc4x.java.spi.netty.NettyHashTimerTimeoutManager; - -import java.util.List; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.ToIntFunction; - -/** - * Builds a Protocol Stack. - */ -public class CustomProtocolStackConfigurer implements ProtocolStackConfigurer { - - private final Class basePacketClass; - private final ByteOrder byteOrder; - private final Function> protocol; - private final Function driverContext; - private final Function> protocolIO; - private final Function> packetSizeEstimator; - private final Function> corruptPacketRemover; - private final MessageToMessageCodec encryptionHandler; - - private final Object[] parserArgs; - - public static CustomProtocolStackBuilder builder(Class basePacketClass, Function> messageInput) { - return new CustomProtocolStackBuilder<>(basePacketClass, messageInput); - } - - /** Only accessible via Builder */ - CustomProtocolStackConfigurer(Class basePacketClass, - ByteOrder byteOrder, - Object[] parserArgs, - Function> protocol, - Function driverContext, - Function> protocolIO, - Function> packetSizeEstimator, - Function> corruptPacketRemover, - MessageToMessageCodec encryptionHandler) { - this.basePacketClass = basePacketClass; - this.byteOrder = byteOrder; - this.parserArgs = parserArgs; - this.protocol = protocol; - this.driverContext = driverContext; - this.protocolIO = protocolIO; - this.packetSizeEstimator = packetSizeEstimator; - this.corruptPacketRemover = corruptPacketRemover; - this.encryptionHandler = encryptionHandler; - } - - private ChannelHandler getMessageCodec(PlcConnectionConfiguration configuration) { - return new GeneratedProtocolMessageCodec<>(basePacketClass, protocolIO.apply(configuration), byteOrder, - packetSizeEstimator == null ? null : packetSizeEstimator.apply(configuration), - corruptPacketRemover == null ? null : corruptPacketRemover.apply(configuration)); - } - - /** Applies the given Stack to the Pipeline */ - @Override - public Plc4xProtocolBase configurePipeline(PlcConnectionConfiguration configuration, ChannelPipeline pipeline, - PlcAuthentication authentication, boolean passive, - List listeners) { - if (this.encryptionHandler != null) { - pipeline.addLast(this.encryptionHandler); - } - pipeline.addLast(getMessageCodec(configuration)); - Plc4xProtocolBase protocol = configure(configuration, this.protocol.apply(configuration)); - DriverContext driverContext = this.driverContext.apply(configuration); - if (driverContext != null) { - protocol.setDriverContext(driverContext); - } - pipeline.addLast(new EventListenerMessageCodec(listeners)); - Plc4xNettyWrapper context = new Plc4xNettyWrapper<>(new NettyHashTimerTimeoutManager(), pipeline, passive, protocol, authentication, basePacketClass); - pipeline.addLast(context); - return protocol; - } - - /** - * Used to Build Instances of {@link SingleProtocolStackConfigurer}. - * - * @param Type of Created Message that is Exchanged. - */ - public static final class CustomProtocolStackBuilder { - - private final Class basePacketClass; - private final Function> messageInput; - private Function driverContext; - private ByteOrder byteOrder = ByteOrder.BIG_ENDIAN; - private Object[] parserArgs; - private Function> protocol; - private Function> packetSizeEstimator; - private Function> corruptPacketRemover; - private MessageToMessageCodec encryptionHandler; - - public CustomProtocolStackBuilder(Class basePacketClass, Function> messageInput) { - this.basePacketClass = basePacketClass; - this.messageInput = messageInput; - } - - public CustomProtocolStackBuilder withDriverContext(Function driverContextClass) { - this.driverContext = driverContextClass; - return this; - } - - public CustomProtocolStackBuilder byteOrder(ByteOrder byteOrder) { - this.byteOrder = byteOrder; - return this; - } - - public CustomProtocolStackBuilder bigEndian() { - this.byteOrder = ByteOrder.BIG_ENDIAN; - return this; - } - - public CustomProtocolStackBuilder littleEndian() { - this.byteOrder = ByteOrder.LITTLE_ENDIAN; - return this; - } - - public CustomProtocolStackBuilder withParserArgs(Object... parserArgs) { - this.parserArgs = parserArgs; - return this; - } - - public CustomProtocolStackBuilder withProtocol(Function> protocol) { - this.protocol = protocol; - return this; - } - - public CustomProtocolStackBuilder withPacketSizeEstimator(Function> packetSizeEstimator) { - this.packetSizeEstimator = packetSizeEstimator; - return this; - } - - public CustomProtocolStackBuilder withCorruptPacketRemover(Function> corruptPacketRemover) { - this.corruptPacketRemover = corruptPacketRemover; - return this; - } - - public CustomProtocolStackBuilder withEncryptionHandler(MessageToMessageCodec encryptionHandler) { - this.encryptionHandler = encryptionHandler; - return this; - } - - public CustomProtocolStackConfigurer build() { - assert this.protocol != null; - return new CustomProtocolStackConfigurer<>( - basePacketClass, byteOrder, parserArgs, protocol, driverContext, messageInput, packetSizeEstimator, - corruptPacketRemover, encryptionHandler); - } - - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java deleted file mode 100644 index de73b833851..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/DefaultNettyPlcConnection.java +++ /dev/null @@ -1,304 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import io.netty.channel.*; -import java.util.concurrent.RejectedExecutionException; -import org.apache.plc4x.java.api.EventPlcConnection; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration; -import org.apache.plc4x.java.api.exceptions.PlcConnectionException; -import org.apache.plc4x.java.api.exceptions.PlcIoException; -import org.apache.plc4x.java.api.listener.ConnectionStateListener; -import org.apache.plc4x.java.api.listener.EventListener; -import org.apache.plc4x.java.api.messages.PlcPingResponse; -import org.apache.plc4x.java.spi.configuration.ConfigurationFactory; -import org.apache.plc4x.java.spi.events.*; -import org.apache.plc4x.java.spi.messages.DefaultPlcPingRequest; -import org.apache.plc4x.java.spi.optimizer.BaseOptimizer; -import org.apache.plc4x.java.spi.values.PlcValueHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.stream.Stream; - -public class DefaultNettyPlcConnection extends AbstractPlcConnection implements ChannelExposingConnection, EventPlcConnection { - - protected final static long DEFAULT_DISCONNECT_WAIT_TIME = 10000L; - private static final Logger logger = LoggerFactory.getLogger(DefaultNettyPlcConnection.class); - - protected final PlcConnectionConfiguration configuration; - protected final ChannelFactory channelFactory; - protected final boolean fireDiscoverEvent; - protected final boolean awaitSessionSetupComplete; - protected final boolean awaitSessionDisconnectComplete; - protected final boolean awaitSessionDiscoverComplete; - protected final ProtocolStackConfigurer stackConfigurer; - protected final List listeners = new CopyOnWriteArrayList<>(); - protected final CompletableFuture sessionDisconnectCompleteFuture = new CompletableFuture<>(); - - protected Channel channel; - protected boolean connected; - - public DefaultNettyPlcConnection(boolean canPing, - boolean canRead, - boolean canWrite, - boolean canSubscribe, - boolean canBrowse, - PlcValueHandler valueHandler, - PlcConnectionConfiguration configuration, - ChannelFactory channelFactory, - boolean fireDiscoverEvent, - boolean awaitSessionSetupComplete, - boolean awaitSessionDisconnectComplete, - boolean awaitSessionDiscoverComplete, - ProtocolStackConfigurer stackConfigurer, - BaseOptimizer optimizer, - PlcAuthentication authentication) { - super(canPing, canRead, canWrite, canSubscribe, canBrowse, valueHandler, optimizer, authentication); - this.configuration = configuration; - this.channelFactory = channelFactory; - this.fireDiscoverEvent = fireDiscoverEvent; - this.awaitSessionSetupComplete = awaitSessionSetupComplete; - //Used to signal that a disconnect has completed while closing a connection. - this.awaitSessionDisconnectComplete = awaitSessionDisconnectComplete; - //Used to signal that discovery has been completed - this.awaitSessionDiscoverComplete = awaitSessionDiscoverComplete; - this.stackConfigurer = stackConfigurer; - - this.connected = false; - } - - @Override - public void connect() throws PlcConnectionException { - try { - // As we don't just want to wait till the connection is established, - // define a future we can use to signal back that the s7 session is - // finished initializing. - CompletableFuture sessionSetupCompleteFuture = new CompletableFuture<>(); - CompletableFuture sessionDiscoveredCompleteFuture = new CompletableFuture<>(); - - if (channelFactory == null) { - throw new PlcConnectionException("No channel factory provided"); - } - - // Inject the configuration - ConfigurationFactory.configure(configuration, channelFactory); - - // Have the channel factory create a new channel instance. - // TODO: Why is this code necessary? Discovery should be an API function that is - // explicitly called independently from the connection establishment. - if (fireDiscoverEvent) { - channel = channelFactory.createChannel(getChannelHandler(sessionSetupCompleteFuture, sessionDisconnectCompleteFuture, sessionDiscoveredCompleteFuture)); - channel.closeFuture().addListener(future -> { - if (!sessionDiscoveredCompleteFuture.isDone()) { - //Do Nothing - try { - sessionDiscoveredCompleteFuture.complete(null); - } catch (Exception e) { - //Do Nothing - } - - } - }); - channel.pipeline().fireUserEventTriggered(new DiscoverEvent()); - } - if (awaitSessionDiscoverComplete) { - // Wait till the connection is established. - sessionDiscoveredCompleteFuture.get(); - } - if (fireDiscoverEvent) { - // clean up resources we created earlier, even if it didn't complete till now (asynchronously) - close(); - } - - channel = channelFactory.createChannel(getChannelHandler(sessionSetupCompleteFuture, sessionDisconnectCompleteFuture, sessionDiscoveredCompleteFuture)); - channel.closeFuture().addListener(future -> { - if (!sessionSetupCompleteFuture.isDone()) { - sessionSetupCompleteFuture.completeExceptionally( - new PlcIoException("Connection terminated by remote")); - } - }); - // Send an event to the pipeline telling the Protocol filters what's going on. - sendChannelCreatedEvent(); - - // Wait till the connection is established. - if (awaitSessionSetupComplete) { - sessionSetupCompleteFuture.get(); - } - - // Set the connection to "connected" - connected = true; - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new PlcConnectionException(e); - } catch (ExecutionException e) { - throw new PlcConnectionException(e); - } - } - - /** - * Close the connection by firstly calling disconnect and waiting for a DisconnectedEvent occurs and then calling - * Close() to finish up any other clean up. - * - * @throws PlcConnectionException when a error occurs while closing - */ - @Override - public void close() throws PlcConnectionException { - if(channel == null) { - return; - } - - logger.debug("Closing connection to PLC, await for disconnect = {}", awaitSessionDisconnectComplete); - channel.pipeline().fireUserEventTriggered(new DisconnectEvent()); - try { - if (awaitSessionDisconnectComplete) { - sessionDisconnectCompleteFuture.get(DEFAULT_DISCONNECT_WAIT_TIME, TimeUnit.MILLISECONDS); - } - } catch (Exception e) { - logger.error("Timeout while trying to close connection"); - } - - // The channel might have already been closed by the remote end. - if (channel.isOpen()) { - try { - channel.pipeline().fireUserEventTriggered(new CloseConnectionEvent()); - channel.close().awaitUninterruptibly(); - } catch (RejectedExecutionException ex) { - if (channel.isOpen()) { - throw ex; - } - } - } - - if (!sessionDisconnectCompleteFuture.isDone()) { - sessionDisconnectCompleteFuture.complete(null); - } - - // Shutdown the Worker Group - channelFactory.closeEventLoopForChannel(channel); - - channel = null; - connected = false; - } - - @Override - public CompletableFuture ping() { - return new DefaultPlcPingRequest(this).execute(); - } - - /** - * Check if the communication channel is active (channel.isActive()) and the driver for a given protocol - * has finished establishing the connection. - */ - @Override - public boolean isConnected() { - return connected && channel.isActive(); - } - - @Override - public Channel getChannel() { - return channel; - } - - public ChannelHandler getChannelHandler(CompletableFuture sessionSetupCompleteFuture, CompletableFuture sessionDisconnectCompleteFuture, CompletableFuture sessionDiscoverCompleteFuture) { - if (stackConfigurer == null) { - throw new IllegalStateException("No Protocol Stack Configurer is given!"); - } - return new ChannelInitializer<>() { - @Override - protected void initChannel(Channel channel) { - // Build the protocol stack for communicating with desired protocol. - ChannelPipeline pipeline = channel.pipeline(); - pipeline.addLast(new ChannelInboundHandlerAdapter() { - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - Stream eventListeners = listeners.stream().filter(ConnectionStateListener.class::isInstance) - .map(ConnectionStateListener.class::cast); - if (evt instanceof ConnectedEvent) { - sessionSetupCompleteFuture.complete(null); - eventListeners.forEach(ConnectionStateListener::connected); - } else if (evt instanceof DisconnectedEvent) { - sessionDisconnectCompleteFuture.complete(null); - eventListeners.forEach(ConnectionStateListener::disconnected); - // Fix for https://github.com/apache/plc4x/issues/801 - super.userEventTriggered(ctx, evt); - } else if (evt instanceof DiscoveredEvent) { - sessionDiscoverCompleteFuture.complete(((DiscoveredEvent) evt).getConfiguration()); - } else if (evt instanceof ConnectEvent || evt instanceof DiscoverEvent) { - // Fix for https://github.com/apache/plc4x/issues/801 - if (!sessionSetupCompleteFuture.isCompletedExceptionally()) { - if (awaitSessionSetupComplete) { - setupProtocol(pipeline); - } - super.userEventTriggered(ctx, evt); - } - } else { - super.userEventTriggered(ctx, evt); - } - } - }); - // If any exception goes through the pipeline unhandled, close the connection. - pipeline.addLast( - new ChannelInboundHandlerAdapter() { - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws PlcConnectionException { - logger.error("unknown error, close the connection", cause); - close(); - } - } - ); - // Initialize via Transport Layer - channelFactory.initializePipeline(pipeline); - // Initialize Protocol Layer - // Fix for https://github.com/apache/plc4x/issues/801 - if (!awaitSessionSetupComplete) { - setupProtocol(pipeline); - } - } - }; - } - - private void setupProtocol(ChannelPipeline pipeline) { - setProtocol(stackConfigurer.configurePipeline(configuration, pipeline, getAuthentication(), - channelFactory.isPassive(), listeners)); - } - - protected void sendChannelCreatedEvent() { - logger.trace("Channel was created, firing ChannelCreated Event"); - // Send an event to the pipeline telling the Protocol filters what's going on. - channel.pipeline().fireUserEventTriggered(new ConnectEvent()); - } - - @Override - public void addEventListener(EventListener listener) { - listeners.add(listener); - } - - @Override - public void removeEventListener(EventListener listener) { - listeners.remove(listener); - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/EncryptionHandler.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/EncryptionHandler.java deleted file mode 100644 index 261414083b0..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/EncryptionHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageCodec; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class EncryptionHandler extends MessageToMessageCodec { - - private static final Logger logger = LoggerFactory.getLogger(DefaultNettyPlcConnection.class); - - public EncryptionHandler() { - super(ByteBuf.class, ByteBuf.class); - } - - @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf in, List out) { - logger.debug("Encrypting outgoing message"); - in.retain(); - encrypt(ctx, in, out); - out.add(in); - } - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { - logger.debug("Received Incoming message and decrypting"); - in.retain(); - decrypt(ctx, in, out); - out.add(in); - } - - /** - * Overridable function used to encrypt an outgoing message. - * - * @return ByteBuf the encrypted buffer should be returned. - */ - protected ByteBuf encrypt(ChannelHandlerContext ctx, ByteBuf in, List out) { - return in; - } - - /** - * Overridable function used to decrypt the incoming message. - * - * @return ByteBuf the decrypted buffer should be returned. - */ - protected ByteBuf decrypt(ChannelHandlerContext ctx, ByteBuf in, List out) { - return in; - } - -} diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/GeneratedDriverBase.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/GeneratedDriverBase.java deleted file mode 100644 index 959b73de165..00000000000 --- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/connection/GeneratedDriverBase.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * 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. - */ -package org.apache.plc4x.java.spi.connection; - -import org.apache.plc4x.java.api.PlcConnection; -import org.apache.plc4x.java.api.PlcDriver; -import org.apache.plc4x.java.api.authentication.PlcAuthentication; -import org.apache.plc4x.java.spi.configuration.PlcConfiguration; -import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration; -import org.apache.plc4x.java.spi.configuration.PlcTransportConfiguration; -import org.apache.plc4x.java.api.exceptions.PlcConnectionException; -import org.apache.plc4x.java.api.metadata.Option; -import org.apache.plc4x.java.api.metadata.OptionMetadata; -import org.apache.plc4x.java.api.types.OptionType; -import org.apache.plc4x.java.api.metadata.PlcDriverMetadata; -import org.apache.plc4x.java.spi.configuration.ConfigurationFactory; -import org.apache.plc4x.java.spi.configuration.annotations.*; -import org.apache.plc4x.java.spi.configuration.annotations.defaults.*; -import org.apache.plc4x.java.spi.generation.Message; -import org.apache.plc4x.java.spi.metadata.DefaultOption; -import org.apache.plc4x.java.spi.metadata.DefaultOptionMetadata; -import org.apache.plc4x.java.spi.optimizer.BaseOptimizer; -import org.apache.plc4x.java.spi.transport.Transport; -import org.apache.plc4x.java.spi.values.DefaultPlcValueHandler; -import org.apache.plc4x.java.spi.values.PlcValueHandler; - -import java.lang.reflect.Field; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import static org.apache.plc4x.java.spi.configuration.ConfigurationFactory.configure; - -public abstract class GeneratedDriverBase implements PlcDriver { - - public static final String PROPERTY_PLC4X_FORCE_FIRE_DISCOVER_EVENT = "PLC4X_FORCE_FIRE_DISCOVER_EVENT"; - public static final String PROPERTY_PLC4X_FORCE_AWAIT_SETUP_COMPLETE = "PLC4X_FORCE_AWAIT_SETUP_COMPLETE"; - public static final String PROPERTY_PLC4X_FORCE_AWAIT_DISCONNECT_COMPLETE = "PLC4X_FORCE_AWAIT_DISCONNECT_COMPLETE"; - public static final String PROPERTY_PLC4X_FORCE_AWAIT_DISCOVER_COMPLETE = "PLC4X_FORCE_AWAIT_DISCOVER_COMPLETE"; - - public static final Pattern URI_PATTERN = Pattern.compile( - "^(?[a-z0-9\\-]*)(:(?[a-z0-9]*))?://(?[^?]*)(\\?(?.*))?"); - - /** - * Configuration class for configuration introspection - * - * @return the configuration class - */ - protected abstract Class getConfigurationClass(); - - protected Optional> getTransportConfigurationClass(String transportCode) { - return Optional.empty(); - } - - protected Optional getDefaultTransportCode() { - return Optional.empty(); - } - - protected List getSupportedTransportCodes() { - return Collections.emptyList(); - } - - @Override - public PlcDriverMetadata getMetadata() { - return new PlcDriverMetadata() { - @Override - public Optional getDefaultTransportCode() { - return GeneratedDriverBase.this.getDefaultTransportCode(); - } - - @Override - public List getSupportedTransportCodes() { - List supportedTransportCodes = GeneratedDriverBase.this.getSupportedTransportCodes(); - if (supportedTransportCodes.isEmpty() && (getDefaultTransportCode().isPresent())) { - return Collections.singletonList(getDefaultTransportCode().get()); - } - return GeneratedDriverBase.this.getSupportedTransportCodes(); - } - - @Override - public Optional getProtocolConfigurationOptionMetadata() { - var clazz = getConfigurationClass(); - if (clazz == null) { - return Optional.empty(); - } - var options = getOptions(clazz); - return Optional.of(new DefaultOptionMetadata(options)); - } - - @Override - public Optional getTransportConfigurationOptionMetadata(String transportCode) { - var clazzOption = resolveTransportConfigurationClass(transportCode); - if (clazzOption.isEmpty()) { - return Optional.empty(); - } - var clazz = clazzOption.get(); - var options = getOptions(clazz); - return Optional.of(new DefaultOptionMetadata(options)); - } - - private List