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/07 15:55:49 UTC

[incubator-plc4x] branch feature/Beckhoff_ADS_protocol updated: refactored common code

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 444e16a  refactored common code
444e16a is described below

commit 444e16a8be7e32e2d88542e58ccc5b19b8dc55c8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Feb 7 16:55:45 2018 +0100

    refactored common code
---
 .../java/ads/api/commands/types/ADSState.java      |   6 +
 .../api/commands/types/AdsNotificationSample.java  |   2 +-
 .../ads/api/commands/types/AdsStampHeader.java     |   2 +-
 .../java/ads/api/commands/types/CycleTime.java     |  27 ++-
 .../plc4x/java/ads/api/commands/types/Device.java  |   5 +
 .../java/ads/api/commands/types/DeviceState.java   |   5 +
 .../java/ads/api/commands/types/IndexGroup.java    |  27 ++-
 .../java/ads/api/commands/types/IndexOffset.java   |  27 ++-
 .../plc4x/java/ads/api/commands/types/Length.java  |  42 ++---
 .../java/ads/api/commands/types/MajorVersion.java  |   5 +
 .../java/ads/api/commands/types/MaxDelay.java      |  27 ++-
 .../java/ads/api/commands/types/MinorVersion.java  |   5 +
 .../ads/api/commands/types/NotificationHandle.java |  27 ++-
 .../java/ads/api/commands/types/ReadLength.java    |  43 +++--
 .../plc4x/java/ads/api/commands/types/Result.java  |  27 ++-
 .../java/ads/api/commands/types/SampleSize.java    |  43 +++--
 .../plc4x/java/ads/api/commands/types/Samples.java |  41 +++--
 .../plc4x/java/ads/api/commands/types/Stamps.java  |  34 ++--
 .../java/ads/api/commands/types/TimeStamp.java     |   5 +
 .../ads/api/commands/types/TransmissionMode.java   |  27 ++-
 .../plc4x/java/ads/api/commands/types/Version.java |   5 +
 .../java/ads/api/commands/types/WriteLength.java   |  41 +++--
 .../plc4x/java/ads/api/generic/types/AMSError.java |  29 +++-
 .../plc4x/java/ads/api/generic/types/AMSNetId.java |   5 +
 .../plc4x/java/ads/api/generic/types/AMSPort.java  |   5 +
 .../plc4x/java/ads/api/generic/types/Command.java  |  19 ++-
 .../java/ads/api/generic/types/DataLength.java     |  35 ++--
 .../plc4x/java/ads/api/generic/types/Invoke.java   |  29 +++-
 .../plc4x/java/ads/api/generic/types/Length.java   |  37 ++--
 .../plc4x/java/ads/api/generic/types/State.java    |  22 ++-
 .../UnsignedIntLEByteValue.java}                   |  44 +++--
 .../apache/plc4x/java/ads/netty/ADSProtocol.java   | 190 ++++++++++-----------
 32 files changed, 559 insertions(+), 329 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ADSState.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ADSState.java
index 4f4e3bf..86e2354 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ADSState.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ADSState.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class ADSState extends ByteValue {
@@ -32,4 +33,9 @@ public class ADSState extends ByteValue {
     public static ADSState of(byte... values) {
         return new ADSState(values);
     }
+
+    public static ADSState of(ByteBuf byteBuf) {
+        // TODO: could be transformed to readUnsignedShortLE someday
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSample.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSample.java
index 7b86b05..ce2cd2f 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSample.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsNotificationSample.java
@@ -38,7 +38,7 @@ public class AdsNotificationSample implements ByteReadable {
      */
     private final Data data;
 
-    AdsNotificationSample(NotificationHandle notificationHandle, SampleSize sampleSize, Data data) {
+    protected AdsNotificationSample(NotificationHandle notificationHandle, SampleSize sampleSize, Data data) {
         this.notificationHandle = notificationHandle;
         this.sampleSize = sampleSize;
         this.data = data;
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeader.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeader.java
index c282df7..ab7edf7 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeader.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/AdsStampHeader.java
@@ -40,7 +40,7 @@ public class AdsStampHeader implements ByteReadable {
      */
     private final List<AdsNotificationSample> adsNotificationSamples;
 
-    AdsStampHeader(TimeStamp timeStamp, Samples samples, List<AdsNotificationSample> adsNotificationSamples) {
+    protected AdsStampHeader(TimeStamp timeStamp, Samples samples, List<AdsNotificationSample> adsNotificationSamples) {
         this.timeStamp = timeStamp;
         this.samples = samples;
         this.adsNotificationSamples = adsNotificationSamples;
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/CycleTime.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/CycleTime.java
index 139c546..43fcb66 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/CycleTime.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/CycleTime.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class CycleTime extends ByteValue {
+public class CycleTime extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    CycleTime(byte... value) {
+    protected CycleTime(byte... values) {
+        super(values);
+    }
+
+    protected CycleTime(long value) {
         super(value);
-        assertLength(NUM_BYTES);
+    }
+
+    protected CycleTime(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static CycleTime of(byte... values) {
         return new CycleTime(values);
     }
+
+    public static CycleTime of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new CycleTime(errorCode);
+    }
+
+    public static CycleTime of(ByteBuf byteBuf) {
+        return new CycleTime(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
index 0a18907..f174df3 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Device.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class Device extends ByteValue {
@@ -32,4 +33,8 @@ public class Device extends ByteValue {
     public static Device of(byte... values) {
         return new Device(values);
     }
+
+    public static Device of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/DeviceState.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/DeviceState.java
index 397ccee..5e8b64f 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/DeviceState.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/DeviceState.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class DeviceState extends ByteValue {
@@ -32,4 +33,8 @@ public class DeviceState extends ByteValue {
     public static DeviceState of(byte... values) {
         return new DeviceState(values);
     }
+
+    public static DeviceState of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexGroup.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexGroup.java
index 619284d..b162ae9 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexGroup.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexGroup.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class IndexGroup extends ByteValue {
+public class IndexGroup extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    IndexGroup(byte... value) {
+    protected IndexGroup(byte... values) {
+        super(values);
+    }
+
+    protected IndexGroup(long value) {
         super(value);
-        assertLength(NUM_BYTES);
+    }
+
+    protected IndexGroup(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static IndexGroup of(byte... values) {
         return new IndexGroup(values);
     }
+
+    public static IndexGroup of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new IndexGroup(errorCode);
+    }
+
+    public static IndexGroup of(ByteBuf byteBuf) {
+        return new IndexGroup(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexOffset.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexOffset.java
index 73d21fb..f94a82e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexOffset.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/IndexOffset.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class IndexOffset extends ByteValue {
+public class IndexOffset extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    IndexOffset(byte... value) {
+    protected IndexOffset(byte... values) {
+        super(values);
+    }
+
+    protected IndexOffset(long value) {
         super(value);
-        assertLength(NUM_BYTES);
+    }
+
+    protected IndexOffset(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static IndexOffset of(byte... values) {
         return new IndexOffset(values);
     }
+
+    public static IndexOffset of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new IndexOffset(errorCode);
+    }
+
+    public static IndexOffset of(ByteBuf byteBuf) {
+        return new IndexOffset(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
index a68fe8d..7ce8239 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Length.java
@@ -18,40 +18,40 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class Length extends UnsignedIntLEByteValue {
 
-public class Length extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
-
-    Length(byte... values) {
+    protected Length(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
     }
 
-    public static Length of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new Length(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected Length(long value) {
+        super(value);
     }
 
-    public static Length of(String length) {
-        return of(Long.parseLong(length));
+    protected Length(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Length of(byte... values) {
         return new Length(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static Length of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Length(errorCode);
+    }
+
+    public static Length of(ByteBuf byteBuf) {
+        return new Length(byteBuf);
     }
+
+    public static Length of(String length) {
+        return of(Long.parseLong(length));
+    }
+
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
index d6f0a0d..59926e7 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MajorVersion.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class MajorVersion extends ByteValue {
@@ -32,4 +33,8 @@ public class MajorVersion extends ByteValue {
     public static MajorVersion of(byte... values) {
         return new MajorVersion(values);
     }
+
+    public static MajorVersion of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MaxDelay.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MaxDelay.java
index a5472b4..582a971 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MaxDelay.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MaxDelay.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class MaxDelay extends ByteValue {
+public class MaxDelay extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    MaxDelay(byte... values) {
+    protected MaxDelay(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected MaxDelay(long value) {
+        super(value);
+    }
+
+    protected MaxDelay(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static MaxDelay of(byte... values) {
         return new MaxDelay(values);
     }
+
+    public static MaxDelay of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new MaxDelay(errorCode);
+    }
+
+    public static MaxDelay of(ByteBuf byteBuf) {
+        return new MaxDelay(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
index f12faa3..180640c 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/MinorVersion.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class MinorVersion extends ByteValue {
@@ -32,4 +33,8 @@ public class MinorVersion extends ByteValue {
     public static MinorVersion of(byte... values) {
         return new MinorVersion(values);
     }
+
+    public static MinorVersion of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/NotificationHandle.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/NotificationHandle.java
index 643d99f..cc35db1 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/NotificationHandle.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/NotificationHandle.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class NotificationHandle extends ByteValue {
+public class NotificationHandle extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    NotificationHandle(byte... values) {
+    protected NotificationHandle(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected NotificationHandle(long value) {
+        super(value);
+    }
+
+    protected NotificationHandle(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static NotificationHandle of(byte... values) {
         return new NotificationHandle(values);
     }
+
+    public static NotificationHandle of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new NotificationHandle(errorCode);
+    }
+
+    public static NotificationHandle of(ByteBuf byteBuf) {
+        return new NotificationHandle(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
index 679e33a..3421f4a 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
@@ -18,40 +18,39 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class ReadLength extends UnsignedIntLEByteValue {
 
-public class ReadLength extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
-
-    ReadLength(byte... value) {
-        super(value);
-        assertLength(NUM_BYTES);
+    protected ReadLength(byte... values) {
+        super(values);
     }
 
-    public static ReadLength of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new ReadLength(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected ReadLength(long value) {
+        super(value);
     }
 
-    public static ReadLength of(String length) {
-        return of(Long.parseLong(length));
+    protected ReadLength(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static ReadLength of(byte... values) {
         return new ReadLength(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static ReadLength of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new ReadLength(errorCode);
+    }
+
+    public static ReadLength of(ByteBuf byteBuf) {
+        return new ReadLength(byteBuf);
+    }
+
+    public static ReadLength of(String length) {
+        return of(Long.parseLong(length));
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Result.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Result.java
index 5fc9fbc..402bca5 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Result.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Result.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class Result extends ByteValue {
+public class Result extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    Result(byte... values) {
+    protected Result(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected Result(long value) {
+        super(value);
+    }
+
+    protected Result(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Result of(byte... values) {
         return new Result(values);
     }
+
+    public static Result of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Result(errorCode);
+    }
+
+    public static Result of(ByteBuf byteBuf) {
+        return new Result(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
index 7f2f272..ddb9d1b 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/SampleSize.java
@@ -18,40 +18,39 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class SampleSize extends UnsignedIntLEByteValue {
 
-public class SampleSize extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
-
-    SampleSize(byte... value) {
-        super(value);
-        assertLength(NUM_BYTES);
+    protected SampleSize(byte... values) {
+        super(values);
     }
 
-    public static SampleSize of(long sampleSize) {
-        checkUnsignedBounds(sampleSize, NUM_BYTES);
-        return new SampleSize(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (sampleSize & 0xff))
-            .put((byte) (sampleSize >> 8 & 0xff))
-            .put((byte) (sampleSize >> 16 & 0xff))
-            .put((byte) (sampleSize >> 24 & 0xff))
-            .array());
+    protected SampleSize(long value) {
+        super(value);
     }
 
-    public static SampleSize of(String sampleSize) {
-        return of(Long.parseLong(sampleSize));
+    protected SampleSize(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static SampleSize of(byte... values) {
         return new SampleSize(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static SampleSize of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new SampleSize(errorCode);
+    }
+
+    public static SampleSize of(ByteBuf byteBuf) {
+        return new SampleSize(byteBuf);
+    }
+
+    public static SampleSize of(String size) {
+        return of(Long.parseLong(size));
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
index e2d9269..a586026 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Samples.java
@@ -18,40 +18,39 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class Samples extends UnsignedIntLEByteValue {
 
-public class Samples extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
-
-    Samples(byte... values) {
+    protected Samples(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
     }
 
-    public static Samples of(long numberOfSamples) {
-        checkUnsignedBounds(numberOfSamples, NUM_BYTES);
-        return new Samples(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (numberOfSamples & 0xff))
-            .put((byte) (numberOfSamples >> 8 & 0xff))
-            .put((byte) (numberOfSamples >> 16 & 0xff))
-            .put((byte) (numberOfSamples >> 24 & 0xff))
-            .array());
+    protected Samples(long value) {
+        super(value);
     }
 
-    public static Samples of(String numberOfSamples) {
-        return of(Long.parseLong(numberOfSamples));
+    protected Samples(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Samples of(byte... values) {
         return new Samples(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static Samples of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Samples(errorCode);
+    }
+
+    public static Samples of(ByteBuf byteBuf) {
+        return new Samples(byteBuf);
+    }
+
+    public static Samples of(String size) {
+        return of(Long.parseLong(size));
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Stamps.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Stamps.java
index 475ef3c..86c658a 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Stamps.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Stamps.java
@@ -18,31 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class Stamps extends UnsignedIntLEByteValue {
 
-public class Stamps extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
+    protected Stamps(byte... values) {
+        super(values);
+    }
 
-    Stamps(byte... value) {
+    protected Stamps(long value) {
         super(value);
-        assertLength(NUM_BYTES);
     }
 
-    public static Stamps of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new Stamps(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected Stamps(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Stamps of(byte... values) {
         return new Stamps(values);
     }
+
+    public static Stamps of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Stamps(errorCode);
+    }
+
+    public static Stamps of(ByteBuf byteBuf) {
+        return new Stamps(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
index 3ce38d7..a7e49e2 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TimeStamp.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class TimeStamp extends ByteValue {
@@ -32,4 +33,8 @@ public class TimeStamp extends ByteValue {
     public static TimeStamp of(byte... values) {
         return new TimeStamp(values);
     }
+
+    public static TimeStamp of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TransmissionMode.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TransmissionMode.java
index 5aa16f7..923e0f3 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TransmissionMode.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/TransmissionMode.java
@@ -18,18 +18,35 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class TransmissionMode extends ByteValue {
+public class TransmissionMode extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    TransmissionMode(byte... values) {
+    protected TransmissionMode(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected TransmissionMode(long value) {
+        super(value);
+    }
+
+    protected TransmissionMode(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static TransmissionMode of(byte... values) {
         return new TransmissionMode(values);
     }
+
+    public static TransmissionMode of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new TransmissionMode(errorCode);
+    }
+
+    public static TransmissionMode of(ByteBuf byteBuf) {
+        return new TransmissionMode(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
index 6fa98eb..8518fdf 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/Version.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 public class Version extends ByteValue {
@@ -32,4 +33,8 @@ public class Version extends ByteValue {
     public static Version of(byte... values) {
         return new Version(values);
     }
+
+    public static Version of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
index 2ca0206..2df1cd3 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/WriteLength.java
@@ -18,40 +18,39 @@
  */
 package org.apache.plc4x.java.ads.api.commands.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class WriteLength extends UnsignedIntLEByteValue {
 
-public class WriteLength extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
-
-    WriteLength(byte... values) {
+    protected WriteLength(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
     }
 
-    public static WriteLength of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new WriteLength(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected WriteLength(long value) {
+        super(value);
     }
 
-    public static WriteLength of(String writeLength) {
-        return of(Long.parseLong(writeLength));
+    protected WriteLength(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static WriteLength of(byte... values) {
         return new WriteLength(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static WriteLength of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new WriteLength(errorCode);
+    }
+
+    public static WriteLength of(ByteBuf byteBuf) {
+        return new WriteLength(byteBuf);
+    }
+
+    public static WriteLength of(String length) {
+        return of(Long.valueOf(length));
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
index 7c01eb1..672b34e 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSError.java
@@ -18,20 +18,37 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class AMSError extends ByteValue {
+public class AMSError extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final AMSError NONE = of((byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00);
+    public static final AMSError NONE = of(0);
 
-    AMSError(byte... values) {
+    protected AMSError(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected AMSError(long value) {
+        super(value);
+    }
+
+    protected AMSError(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static AMSError of(byte... values) {
         return new AMSError(values);
     }
+
+    public static AMSError of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new AMSError(errorCode);
+    }
+
+    public static AMSError of(ByteBuf byteBuf) {
+        return new AMSError(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
index 0c5917f..7e4b5a5 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSNetId.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
@@ -64,6 +65,10 @@ public class AMSNetId extends ByteValue {
         return new AMSNetId(bytes);
     }
 
+    public static AMSNetId of(ByteBuf byteBuf) {
+        return of(byteBuf.readBytes(NUM_BYTES).array());
+    }
+
     @Override
     public String toString() {
         byte[] bytes = getBytes();
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
index ee14b83..45ee7d5 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/AMSPort.java
@@ -18,6 +18,7 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
+import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 
 import java.nio.ByteBuffer;
@@ -54,6 +55,10 @@ public class AMSPort extends ByteValue {
         return of(Integer.parseInt(port));
     }
 
+    public static AMSPort of(ByteBuf byteBuf) {
+        return of(byteBuf.readUnsignedShortLE());
+    }
+
     @Override
     public String toString() {
         return "" + (getBytes()[1] << 8 | getBytes()[0]);
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 609939b..988f1d9 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
@@ -46,13 +46,17 @@ public enum Command implements ByteReadable {
 
     final byte[] value;
 
+    final int intValue;
+
     Command() {
         // Only used for unkown enum
         value = new byte[0];
+        intValue = 0;
     }
 
     Command(int value) {
         ByteValue.checkUnsignedBounds(value, NUM_BYTES);
+        this.intValue = value;
         this.value = ByteBuffer.allocate(NUM_BYTES)
             // LE
             .put((byte) (value & 0xff))
@@ -75,7 +79,6 @@ public enum Command implements ByteReadable {
         return Unpooled.buffer().writeBytes(value);
     }
 
-    // TODO: improve by accepting int
     public static Command of(byte... bytes) {
         // TODO: improve by using a map
         for (Command command : values()) {
@@ -85,4 +88,18 @@ public enum Command implements ByteReadable {
         }
         return UNKNOWN;
     }
+
+    public static Command of(int intValue) {
+        // TODO: improve by using a map
+        for (Command command : values()) {
+            if (command.intValue == intValue) {
+                return command;
+            }
+        }
+        return UNKNOWN;
+    }
+
+    public static Command of(ByteBuf byteBuf) {
+        return of(byteBuf.readUnsignedShortLE());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
index 35dcac2..2b88ed9 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/DataLength.java
@@ -18,28 +18,23 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class DataLength extends UnsignedIntLEByteValue {
 
-public class DataLength extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
+    protected DataLength(byte... values) {
+        super(values);
+    }
 
-    DataLength(byte... value) {
+    protected DataLength(long value) {
         super(value);
-        assertLength(NUM_BYTES);
     }
 
-    public static DataLength of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new DataLength(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected DataLength(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static DataLength of(String length) {
@@ -50,8 +45,12 @@ public class DataLength extends ByteValue {
         return new DataLength(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static DataLength of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new DataLength(errorCode);
+    }
+
+    public static DataLength of(ByteBuf byteBuf) {
+        return new DataLength(byteBuf);
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Invoke.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Invoke.java
index fb60c07..be89152 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Invoke.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Invoke.java
@@ -18,20 +18,37 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class Invoke extends ByteValue {
+public class Invoke extends UnsignedIntLEByteValue {
 
-    public static final int NUM_BYTES = 4;
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final Invoke NONE = of((byte) 0, (byte) 0, (byte) 0, (byte) 0);
+    public static final Invoke NONE = of(0);
 
-    Invoke(byte... values) {
+    protected Invoke(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
+    }
+
+    protected Invoke(long value) {
+        super(value);
+    }
+
+    protected Invoke(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Invoke of(byte... values) {
         return new Invoke(values);
     }
+
+    public static Invoke of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Invoke(errorCode);
+    }
+
+    public static Invoke of(ByteBuf byteBuf) {
+        return new Invoke(byteBuf);
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
index 28b8e47..6ccef82 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
@@ -18,28 +18,25 @@
  */
 package org.apache.plc4x.java.ads.api.generic.types;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
+import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-import java.nio.ByteBuffer;
+public class Length extends UnsignedIntLEByteValue {
 
-public class Length extends ByteValue {
+    public static final int NUM_BYTES = UnsignedIntLEByteValue.NUM_BYTES;
 
-    public static final int NUM_BYTES = 4;
+    public static final Length NONE = of(0);
 
-    Length(byte... values) {
+    protected Length(byte... values) {
         super(values);
-        assertLength(NUM_BYTES);
     }
 
-    public static Length of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new Length(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    protected Length(long value) {
+        super(value);
+    }
+
+    protected Length(ByteBuf byteBuf) {
+        super(byteBuf);
     }
 
     public static Length of(String length) {
@@ -50,8 +47,12 @@ public class Length extends ByteValue {
         return new Length(values);
     }
 
-    @Override
-    public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+    public static Length of(long errorCode) {
+        checkUnsignedBounds(errorCode, NUM_BYTES);
+        return new Length(errorCode);
+    }
+
+    public static Length of(ByteBuf byteBuf) {
+        return new Length(byteBuf);
     }
 }
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 4505e7c..4250637 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
@@ -53,12 +53,16 @@ public enum State implements ByteReadable {
 
     final byte[] value;
 
+    final int intValue;
+
     State() {
         value = new byte[0];
+        intValue = 0;
     }
 
-    State(long value) {
+    State(int value) {
         ByteValue.checkUnsignedBounds(value, NUM_BYTES);
+        this.intValue = value;
         this.value = ByteBuffer.allocate(NUM_BYTES)
             // LE
             .put((byte) (value & 0xff))
@@ -81,7 +85,6 @@ public enum State implements ByteReadable {
         return Unpooled.buffer().writeBytes(value);
     }
 
-    // TODO: improve by accepting int
     public static State of(byte... bytes) {
         // TODO: improve by using a map
         for (State command : values()) {
@@ -91,4 +94,19 @@ public enum State implements ByteReadable {
         }
         return UNKNOWN;
     }
+
+
+    public static State of(int intValue) {
+        // TODO: improve by using a map
+        for (State state : values()) {
+            if (state.intValue == intValue) {
+                return state;
+            }
+        }
+        return UNKNOWN;
+    }
+
+    public static State of(ByteBuf byteBuf) {
+        return of(byteBuf.readUnsignedShortLE());
+    }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/UnsignedIntLEByteValue.java
similarity index 50%
copy from plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
copy to plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/UnsignedIntLEByteValue.java
index 679e33a..6222766 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/types/ReadLength.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/UnsignedIntLEByteValue.java
@@ -16,42 +16,50 @@
  specific language governing permissions and limitations
  under the License.
  */
-package org.apache.plc4x.java.ads.api.commands.types;
+package org.apache.plc4x.java.ads.api.util;
 
-import org.apache.plc4x.java.ads.api.util.ByteValue;
+import io.netty.buffer.ByteBuf;
 
 import java.nio.ByteBuffer;
 
-public class ReadLength extends ByteValue {
+public abstract class UnsignedIntLEByteValue extends ByteValue {
 
     public static final int NUM_BYTES = 4;
 
-    ReadLength(byte... value) {
+    protected final long longValue;
+
+    public UnsignedIntLEByteValue(byte... value) {
         super(value);
         assertLength(NUM_BYTES);
+        longValue = getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0];
     }
 
-    public static ReadLength of(long length) {
-        checkUnsignedBounds(length, NUM_BYTES);
-        return new ReadLength(ByteBuffer.allocate(NUM_BYTES)
-            // LE
-            .put((byte) (length & 0xff))
-            .put((byte) (length >> 8 & 0xff))
-            .put((byte) (length >> 16 & 0xff))
-            .put((byte) (length >> 24 & 0xff))
-            .array());
+    public UnsignedIntLEByteValue(long value) {
+        super(ofLong(value));
+        checkUnsignedBounds(value, NUM_BYTES);
+        longValue = value;
     }
 
-    public static ReadLength of(String length) {
-        return of(Long.parseLong(length));
+    public UnsignedIntLEByteValue(ByteBuf byteBuf) {
+        this(byteBuf.readUnsignedIntLE());
+    }
+
+    protected static byte[] ofLong(long value) {
+        return ByteBuffer.allocate(NUM_BYTES)
+            // LE
+            .put((byte) (value & 0xff))
+            .put((byte) (value >> 8 & 0xff))
+            .put((byte) (value >> 16 & 0xff))
+            .put((byte) (value >> 24 & 0xff))
+            .array();
     }
 
-    public static ReadLength of(byte... values) {
-        return new ReadLength(values);
+    public long getAsLong() {
+        return longValue;
     }
 
     @Override
     public String toString() {
-        return "" + (getBytes()[3] << 24 | getBytes()[2] << 16 | getBytes()[1] << 8 | getBytes()[0]);
+        return String.valueOf(getAsLong());
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/ADSProtocol.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/ADSProtocol.java
index 215c80f..d28c292 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/ADSProtocol.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/netty/ADSProtocol.java
@@ -28,12 +28,15 @@ import org.apache.plc4x.java.ads.api.generic.AMSHeader;
 import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
 import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
 import org.apache.plc4x.java.ads.api.generic.types.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.*;
 
 public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPaket> {
 
-    // TODO: better track this a layer above as this here might be useless
+    private static final Logger LOGGER = LoggerFactory.getLogger(ADSProtocol.class);
+
     private Map<Invoke, AMSTCPPaket> requests;
 
     public ADSProtocol() {
@@ -56,23 +59,21 @@ public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPaket> {
         // Reserved
         byteBuf.skipBytes(2);
         long packetLength = byteBuf.readUnsignedIntLE();
-        AMSNetId targetAmsNetId = AMSNetId.of(byteBuf.readBytes(6).array());
-        AMSPort targetAmsPort = AMSPort.of(byteBuf.readUnsignedShortLE());
-        AMSNetId sourceAmsNetId = AMSNetId.of(byteBuf.readBytes(6).array());
-        AMSPort sourceAmsPort = AMSPort.of(byteBuf.readUnsignedShortLE());
-        // TODO: could be transformed to readUnsignedShortLE someday
-        Command commandId = Command.of(byteBuf.readBytes(2).array());
-        // TODO: could be transformed to readUnsignedShortLE someday
-        State stateId = State.of(byteBuf.readBytes(2).array());
-        long dataLengthLong = byteBuf.readUnsignedIntLE();
-        DataLength dataLength = DataLength.of(dataLengthLong);
-        AMSError errorCode = AMSError.of(byteBuf.readBytes(4).array());
-        Invoke invoke = Invoke.of(byteBuf.readBytes(4).array());
-        AMSTCPPaket correlatedAmstcpPaket = requests.get(invoke);
-        if (dataLengthLong > Integer.MAX_VALUE) {
-            throw new IllegalStateException("Overflow in datalength: " + dataLengthLong);
+        AMSNetId targetAmsNetId = AMSNetId.of(byteBuf);
+        AMSPort targetAmsPort = AMSPort.of(byteBuf);
+        AMSNetId sourceAmsNetId = AMSNetId.of(byteBuf);
+        AMSPort sourceAmsPort = AMSPort.of(byteBuf);
+        Command commandId = Command.of(byteBuf);
+        State stateId = State.of(byteBuf);
+        DataLength dataLength = DataLength.of(byteBuf);
+        AMSError errorCode = AMSError.of(byteBuf);
+        Invoke invoke = Invoke.of(byteBuf);
+        AMSTCPPaket correlatedAmstcpPacket = requests.get(invoke);
+        LOGGER.debug("Correlated packet received {}", correlatedAmstcpPacket);
+        if (dataLength.getAsLong() > Integer.MAX_VALUE) {
+            throw new IllegalStateException("Overflow in datalength: " + dataLength.getAsLong());
         }
-        ByteBuf commandBuffer = byteBuf.readBytes((int) dataLengthLong);
+        ByteBuf commandBuffer = byteBuf.readBytes((int) dataLength.getAsLong());
         boolean request = false;
         AMSTCPHeader amstcpHeader = AMSTCPHeader.of(packetLength);
         AMSHeader amsHeader = AMSHeader.of(targetAmsNetId, targetAmsPort, sourceAmsNetId, sourceAmsPort, commandId, stateId, dataLength, errorCode, invoke);
@@ -101,45 +102,42 @@ public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPaket> {
                 if (request) {
                     out.add(new ADSReadDeviceInfoRequest(amstcpHeader, amsHeader));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
-                    MajorVersion majorVersion = MajorVersion.of(commandBuffer.readByte());
-                    MinorVersion minorVersion = MinorVersion.of(commandBuffer.readByte());
-                    // TODO: could be transformed to readUnsignedShortLE someday
-                    Version version = Version.of(commandBuffer.readBytes(2).array());
-                    Device device = Device.of(commandBuffer.readBytes(16).array());
+                    Result result = Result.of(commandBuffer);
+                    MajorVersion majorVersion = MajorVersion.of(commandBuffer);
+                    MinorVersion minorVersion = MinorVersion.of(commandBuffer);
+                    Version version = Version.of(commandBuffer);
+                    Device device = Device.of(commandBuffer);
                     out.add(new ADSReadDeviceInfoResponse(amstcpHeader, amsHeader, result, majorVersion, minorVersion, version, device));
                 }
                 break;
             case ADS_Read:
                 if (request) {
-                    IndexGroup indexGroup = IndexGroup.of(commandBuffer.readBytes(4).array());
-                    IndexOffset indexOffset = IndexOffset.of(commandBuffer.readBytes(4).array());
-                    Length length = Length.of(commandBuffer.readBytes(4).array());
+                    IndexGroup indexGroup = IndexGroup.of(commandBuffer);
+                    IndexOffset indexOffset = IndexOffset.of(commandBuffer);
+                    Length length = Length.of(commandBuffer);
                     out.add(new ADSReadRequest(amstcpHeader, amsHeader, indexGroup, indexOffset, length));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
-                    long adsReadLength = byteBuf.readUnsignedIntLE();
-                    Length length = Length.of(adsReadLength);
-                    if (adsReadLength > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + adsReadLength);
+                    Result result = Result.of(commandBuffer);
+                    Length length = Length.of(byteBuf);
+                    if (length.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + length.getAsLong());
                     }
-                    Data data = Data.of(commandBuffer.readBytes((int) adsReadLength).array());
+                    Data data = Data.of(commandBuffer.readBytes((int) length.getAsLong()).array());
                     out.add(new ADSReadResponse(amstcpHeader, amsHeader, result, length, data));
                 }
                 break;
             case ADS_Write:
                 if (request) {
-                    IndexGroup indexGroup = IndexGroup.of(commandBuffer.readBytes(4).array());
-                    IndexOffset indexOffset = IndexOffset.of(commandBuffer.readBytes(4).array());
-                    long adsWriteLength = byteBuf.readUnsignedIntLE();
-                    Length length = Length.of(adsWriteLength);
-                    if (adsWriteLength > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + adsWriteLength);
+                    IndexGroup indexGroup = IndexGroup.of(commandBuffer);
+                    IndexOffset indexOffset = IndexOffset.of(commandBuffer);
+                    Length length = Length.of(byteBuf);
+                    if (length.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + length.getAsLong());
                     }
-                    Data data = Data.of(commandBuffer.readBytes((int) adsWriteLength).array());
+                    Data data = Data.of(commandBuffer.readBytes((int) length.getAsLong()).array());
                     out.add(new ADSWriteRequest(amstcpHeader, amsHeader, indexGroup, indexOffset, length, data));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
+                    Result result = Result.of(commandBuffer);
                     out.add(new ADSWriteResponse(amstcpHeader, amsHeader, result));
                 }
                 break;
@@ -147,81 +145,74 @@ public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPaket> {
                 if (request) {
                     out.add(new ADSReadStateRequest(amstcpHeader, amsHeader));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
+                    Result result = Result.of(commandBuffer);
                     out.add(new ADSReadStateResponse(amstcpHeader, amsHeader, result));
                 }
                 break;
             case ADS_Write_Control:
                 if (request) {
-                    // TODO: could be transformed to readUnsignedShortLE someday
-                    ADSState adsState = ADSState.of(commandBuffer.readBytes(2).array());
-                    // TODO: could be transformed to readUnsignedShortLE someday
-                    DeviceState deviceState = DeviceState.of(commandBuffer.readBytes(2).array());
-                    long adsWriteControlLength = byteBuf.readUnsignedIntLE();
-                    Length length = Length.of(adsWriteControlLength);
-                    if (adsWriteControlLength > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + adsWriteControlLength);
+                    ADSState adsState = ADSState.of(commandBuffer);
+                    DeviceState deviceState = DeviceState.of(commandBuffer);
+                    Length length = Length.of(byteBuf);
+                    if (length.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + length.getAsLong());
                     }
-                    Data data = Data.of(commandBuffer.readBytes((int) adsWriteControlLength).array());
+                    Data data = Data.of(commandBuffer.readBytes((int) length.getAsLong()).array());
                     out.add(new ADSWriteControlRequest(amstcpHeader, amsHeader, adsState, deviceState, length, data));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
+                    Result result = Result.of(commandBuffer);
                     out.add(new ADSWriteControlResponse(amstcpHeader, amsHeader, result));
                 }
                 break;
             case ADS_Add_Device_Notification:
                 if (request) {
-                    IndexGroup indexGroup = IndexGroup.of(commandBuffer.readBytes(4).array());
-                    IndexOffset indexOffset = IndexOffset.of(commandBuffer.readBytes(4).array());
-                    Length length = Length.of(commandBuffer.readUnsignedIntLE());
-                    TransmissionMode transmissionMode = TransmissionMode.of(commandBuffer.readBytes(4).array());
-                    MaxDelay maxDelay = MaxDelay.of(commandBuffer.readBytes(4).array());
-                    CycleTime cycleTime = CycleTime.of(commandBuffer.readBytes(4).array());
+                    IndexGroup indexGroup = IndexGroup.of(commandBuffer);
+                    IndexOffset indexOffset = IndexOffset.of(commandBuffer);
+                    Length length = Length.of(commandBuffer);
+                    TransmissionMode transmissionMode = TransmissionMode.of(commandBuffer);
+                    MaxDelay maxDelay = MaxDelay.of(commandBuffer);
+                    CycleTime cycleTime = CycleTime.of(commandBuffer);
                     out.add(new ADSAddDeviceNotificationRequest(amstcpHeader, amsHeader, indexGroup, indexOffset, length, transmissionMode, maxDelay, cycleTime));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
-                    NotificationHandle notificationHandle = NotificationHandle.of(commandBuffer.readBytes(4).array());
+                    Result result = Result.of(commandBuffer);
+                    NotificationHandle notificationHandle = NotificationHandle.of(commandBuffer);
                     out.add(new ADSAddDeviceNotificationResponse(amstcpHeader, amsHeader, result, notificationHandle));
                 }
                 break;
             case ADS_Delete_Device_Notification:
                 if (request) {
-                    NotificationHandle notificationHandle = NotificationHandle.of(commandBuffer.readBytes(4).array());
+                    NotificationHandle notificationHandle = NotificationHandle.of(commandBuffer);
                     out.add(new ADSDeleteDeviceNotificationRequest(amstcpHeader, amsHeader, notificationHandle));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
+                    Result result = Result.of(commandBuffer);
                     out.add(new ADSDeleteDeviceNotificationResponse(amstcpHeader, amsHeader, result));
                 }
                 break;
             case ADS_Device_Notification:
                 if (request) {
-                    long adsDeviceNotificationLength = commandBuffer.readUnsignedIntLE();
-                    Length length = Length.of(adsDeviceNotificationLength);
-                    if (adsDeviceNotificationLength > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + adsDeviceNotificationLength);
+                    Length length = Length.of(commandBuffer);
+                    if (length.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + length.getAsLong());
                     }
-                    long numberOfStamps = commandBuffer.readUnsignedIntLE();
-                    Stamps stamps = Stamps.of(numberOfStamps);
-                    if (numberOfStamps > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + numberOfStamps);
+                    Stamps stamps = Stamps.of(commandBuffer);
+                    if (stamps.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + stamps.getAsLong());
                     }
-                    ByteBuf adsDeviceNotificationBuffer = commandBuffer.readBytes((int) adsDeviceNotificationLength);
-                    List<AdsStampHeader> adsStampHeaders = new ArrayList<>((int) numberOfStamps);
-                    for (int i = 1; i <= numberOfStamps; i++) {
-                        TimeStamp timeStamp = TimeStamp.of(adsDeviceNotificationBuffer.readBytes(8).array());
-                        long numberOfSamples = adsDeviceNotificationBuffer.readUnsignedIntLE();
-                        Samples samples = Samples.of(numberOfSamples);
+                    ByteBuf adsDeviceNotificationBuffer = commandBuffer.readBytes((int) length.getAsLong());
+                    List<AdsStampHeader> adsStampHeaders = new ArrayList<>((int) stamps.getAsLong());
+                    for (int i = 1; i <= stamps.getAsLong(); i++) {
+                        TimeStamp timeStamp = TimeStamp.of(adsDeviceNotificationBuffer);
+                        Samples samples = Samples.of(adsDeviceNotificationBuffer);
 
                         List<AdsNotificationSample> adsNotificationSamples = new LinkedList<>();
-                        for (int j = 1; j <= numberOfSamples; j++) {
-                            NotificationHandle notificationHandle = NotificationHandle.of(adsDeviceNotificationBuffer.readBytes(4).array());
-                            long sampleSizeLong = adsDeviceNotificationBuffer.readUnsignedIntLE();
-                            SampleSize sampleSize = SampleSize.of(sampleSizeLong);
-                            if (sampleSizeLong > Integer.MAX_VALUE) {
-                                throw new IllegalStateException("Overflow in datalength: " + sampleSizeLong);
+                        for (int j = 1; j <= samples.getAsLong(); j++) {
+                            NotificationHandle notificationHandle = NotificationHandle.of(adsDeviceNotificationBuffer);
+                            SampleSize sampleSize = SampleSize.of(adsDeviceNotificationBuffer);
+                            if (sampleSize.getAsLong() > Integer.MAX_VALUE) {
+                                throw new IllegalStateException("Overflow in datalength: " + sampleSize.getAsLong());
                             }
                             // TODO: do we need a special marker class for: Notice: If your handle becomes invalid, one notification without data will be send once as advice.
-                            Data data = Data.of(adsDeviceNotificationBuffer.readBytes((int) sampleSizeLong).array());
+                            Data data = Data.of(adsDeviceNotificationBuffer.readBytes((int) sampleSize.getAsLong()).array());
                             AdsNotificationSample adsNotificationSample = AdsNotificationSample.of(notificationHandle, sampleSize, data);
                             adsNotificationSamples.add(adsNotificationSample);
 
@@ -236,31 +227,28 @@ public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPaket> {
                 break;
             case ADS_Read_Write:
                 if (request) {
-                    IndexGroup indexGroup = IndexGroup.of(commandBuffer.readBytes(4).array());
-                    IndexOffset indexOffset = IndexOffset.of(commandBuffer.readBytes(4).array());
-                    long readLengthLong = commandBuffer.readUnsignedIntLE();
-                    ReadLength readLength = ReadLength.of(readLengthLong);
-                    if (readLengthLong > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + readLengthLong);
+                    IndexGroup indexGroup = IndexGroup.of(commandBuffer);
+                    IndexOffset indexOffset = IndexOffset.of(commandBuffer);
+                    ReadLength readLength = ReadLength.of(commandBuffer);
+                    if (readLength.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + readLength.getAsLong());
                     }
-                    long writeLengthLong = commandBuffer.readUnsignedIntLE();
-                    WriteLength writeLength = WriteLength.of(writeLengthLong);
-                    if (writeLengthLong > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + writeLengthLong);
+                    WriteLength writeLength = WriteLength.of(commandBuffer);
+                    if (writeLength.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + writeLength.getAsLong());
                     }
-                    if (readLengthLong + writeLengthLong > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + readLengthLong + writeLengthLong);
+                    if (readLength.getAsLong() + writeLength.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + readLength.getAsLong() + writeLength.getAsLong());
                     }
-                    Data data = Data.of(commandBuffer.readBytes((int) (readLengthLong + writeLengthLong)).array());
+                    Data data = Data.of(commandBuffer.readBytes((int) (readLength.getAsLong() + writeLength.getAsLong())).array());
                     out.add(new ADSReadWriteRequest(amstcpHeader, amsHeader, indexGroup, indexOffset, readLength, writeLength, data));
                 } else {
-                    Result result = Result.of(commandBuffer.readBytes(4).array());
-                    long adsReadLength = byteBuf.readUnsignedIntLE();
-                    Length length = Length.of(adsReadLength);
-                    if (adsReadLength > Integer.MAX_VALUE) {
-                        throw new IllegalStateException("Overflow in datalength: " + adsReadLength);
+                    Result result = Result.of(commandBuffer);
+                    Length length = Length.of(commandBuffer);
+                    if (length.getAsLong() > Integer.MAX_VALUE) {
+                        throw new IllegalStateException("Overflow in datalength: " + length.getAsLong());
                     }
-                    Data data = Data.of(commandBuffer.readBytes((int) adsReadLength).array());
+                    Data data = Data.of(commandBuffer.readBytes((int) length.getAsLong()).array());
                     out.add(new ADSReadWriteResponse(amstcpHeader, amsHeader, result, length, data));
                 }
                 break;

-- 
To stop receiving notification emails like this one, please contact
sruehl@apache.org.