You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/06/13 14:29:15 UTC
[plc4x] branch develop updated: feat(codegen/plc4go): added an indirection through the write buffer for complex types.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 77ff058013 feat(codegen/plc4go): added an indirection through the write buffer for complex types.
77ff058013 is described below
commit 77ff05801368faceb21bde5784f8e509241c1f1d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Jun 13 16:29:01 2022 +0200
feat(codegen/plc4go): added an indirection through the write buffer for complex types.
---
.../java/spi/codegen/io/DataWriterComplexDefault.java | 5 ++---
.../org/apache/plc4x/java/spi/generation/WriteBuffer.java | 14 ++++++++++++++
2 files changed, 16 insertions(+), 3 deletions(-)
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
index b60970fb29..0f703c4c63 100644
--- 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
@@ -60,11 +60,10 @@ public class DataWriterComplexDefault<T extends Message> implements DataWriterCo
if (hasLogicalName) {
writeBuffer.pushContext(logicalName);
}
- if (value != null) {
- value.serialize(writeBuffer);
- } else {
+ if (value == null) {
LOGGER.warn("Trying to serialize null value for {}", logicalName);
}
+ writeBuffer.writeSerializable(value);
if (hasLogicalName) {
writeBuffer.popContext(logicalName);
}
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
index 2f63e8c874..07b63a28ee 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
@@ -19,6 +19,7 @@
package org.apache.plc4x.java.spi.generation;
import org.apache.plc4x.java.spi.codegen.io.ByteOrderAware;
+import org.apache.plc4x.java.spi.utils.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -135,5 +136,18 @@ public interface WriteBuffer extends ByteOrderAware, PositionAware {
writeString("", bitLength, encoding, value);
}
+ /**
+ * this method can be used to influence serializing (e.g. intercept whole types and render them in a simplified form)
+ *
+ * @param value the value to be serialized
+ * @throws SerializationException if something goes wrong
+ */
+ default void writeSerializable(Serializable value) throws SerializationException {
+ if (value == null) {
+ return;
+ }
+ value.serialize(this);
+ }
+
void popContext(String logicalName, WithWriterArgs... writerArgs);
}