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 2018/02/02 16:16:51 UTC
[incubator-plc4x] branch feature/Beckhoff_ADS_protocol updated:
avoid serialisation of Unknown enums
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch feature/Beckhoff_ADS_protocol
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
The following commit(s) were added to refs/heads/feature/Beckhoff_ADS_protocol by this push:
new 6cd273a avoid serialisation of Unknown enums
6cd273a is described below
commit 6cd273a16980518de87527717e42326d427b147b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Feb 2 17:16:47 2018 +0100
avoid serialisation of Unknown enums
---
.../apache/plc4x/java/ads/api/generic/types/Command.java | 13 ++++++++++++-
.../org/apache/plc4x/java/ads/api/generic/types/State.java | 12 +++++++++++-
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
index 1d5db8a..f831a61 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Command.java
@@ -39,12 +39,17 @@ public enum Command implements ByteReadable {
/**
* Other commands are not defined or are used internally. Therefore the Command Id is only allowed to contain the above enumerated values!
*/
- UNKNOWN(0xffff_ffff);
+ UNKNOWN();
public static final int NUM_BYTES = 4;
final byte[] value;
+ Command() {
+ // Only used for unkown enum
+ value = new byte[0];
+ }
+
Command(long value) {
ByteValue.checkUnsignedBounds(value, NUM_BYTES);
this.value = ByteBuffer.allocate(NUM_BYTES)
@@ -57,10 +62,16 @@ public enum Command implements ByteReadable {
@Override
public byte[] getBytes() {
+ if (this == UNKNOWN) {
+ throw new IllegalStateException("Unknown enum can't be serialized");
+ }
return value;
}
public ByteBuf getByteBuf() {
+ if (this == UNKNOWN) {
+ throw new IllegalStateException("Unknown enum can't be serialized");
+ }
return Unpooled.buffer().writeBytes(value);
}
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
index 30c93f6..bb444c2 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/State.java
@@ -46,12 +46,16 @@ public enum State implements ByteReadable {
ADS_RESPONSE_TCP(0x0005),
ADS_REQUEST_UDP(0x0044),
ADS_RESPONSE_UDP(0x0045),
- UNKNOWN(0xffff);
+ UNKNOWN();
public static final int NUM_BYTES = 4;
final byte[] value;
+ State() {
+ value = new byte[0];
+ }
+
State(long value) {
ByteValue.checkUnsignedBounds(value, NUM_BYTES);
this.value = ByteBuffer.allocate(NUM_BYTES)
@@ -64,10 +68,16 @@ public enum State implements ByteReadable {
@Override
public byte[] getBytes() {
+ if (this == UNKNOWN) {
+ throw new IllegalStateException("Unknown enum can't be serialized");
+ }
return value;
}
public ByteBuf getByteBuf() {
+ if (this == UNKNOWN) {
+ throw new IllegalStateException("Unknown enum can't be serialized");
+ }
return Unpooled.buffer().writeBytes(value);
}
}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.