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/03/15 15:38:33 UTC
[incubator-plc4x] 01/05: added length constraint for UserData on
serial communication
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit ee30eef068057a4bf3b0104157525ca23701b82b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Mar 15 15:27:30 2018 +0100
added length constraint for UserData on serial communication
---
.../org/apache/plc4x/java/ads/api/serial/types/UserData.java | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/serial/types/UserData.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/serial/types/UserData.java
index 5a54490..cf65dd7 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/serial/types/UserData.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/serial/types/UserData.java
@@ -27,14 +27,24 @@ import static java.util.Objects.requireNonNull;
public class UserData extends ByteValue {
+ public static final int MAX_LENGTH = 255;
+
public static final UserData EMPTY = UserData.of();
private UserData(byte... values) {
super(values);
+ assertMaxLength();
}
public UserData(ByteBuf byteBuf) {
super(byteBuf);
+ assertMaxLength();
+ }
+
+ protected void assertMaxLength() {
+ if (value.length > MAX_LENGTH) {
+ throw new IllegalArgumentException("Max length " + MAX_LENGTH + " bytes exceeded by " + (value.length - MAX_LENGTH) + " bytes");
+ }
}
public static UserData of(byte... values) {
@@ -52,7 +62,7 @@ public class UserData extends ByteValue {
}
public static UserData of(ByteBuf byteBuf) {
- return new UserData(byteBuf);
+ return new UserData(byteBuf);
}
@Override
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.