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/17 16:18:55 UTC

[incubator-plc4x] branch master updated: rename Length in generic Types to TcpLength to avoid confusion with command length type

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


The following commit(s) were added to refs/heads/master by this push:
     new fae5915  rename Length in generic Types to TcpLength to avoid confusion with command length type
fae5915 is described below

commit fae5915f9c08effd9a6df55839562311304a0087
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sat Feb 17 17:18:50 2018 +0100

    rename Length in generic Types to TcpLength to avoid confusion with command
    length type
---
 .../plc4x/java/ads/api/generic/AMSTCPHeader.java   | 25 +++++++++----------
 .../plc4x/java/ads/api/generic/types/Command.java  |  1 +
 .../generic/types/{Length.java => TcpLength.java}  | 28 +++++++++++-----------
 .../plc4x/java/ads/api/util/ByteReadable.java      |  1 +
 .../apache/plc4x/java/ads/netty/ADSProtocol.java   |  3 +--
 .../types/GenericTypesFactoryMethodTest.java       |  2 +-
 .../types/{LengthTest.java => TcpLengthTest.java}  | 20 ++++++++--------
 7 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPHeader.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPHeader.java
index 1a1d749..5023d30 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPHeader.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPHeader.java
@@ -19,7 +19,7 @@
 package org.apache.plc4x.java.ads.api.generic;
 
 import io.netty.buffer.ByteBuf;
-import org.apache.plc4x.java.ads.api.generic.types.Length;
+import org.apache.plc4x.java.ads.api.generic.types.TcpLength;
 import org.apache.plc4x.java.ads.api.util.ByteReadable;
 import org.apache.plc4x.java.ads.api.util.ByteValue;
 import org.apache.plc4x.java.ads.api.util.LengthSupplier;
@@ -28,13 +28,13 @@ import static java.util.Objects.requireNonNull;
 import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 /**
- * AMS/TCP Header	6 bytes	contains the length of the data packet.
+ * AMS/TCP Header	6 bytes	contains the tcpLength of the data packet.
  */
 public class AMSTCPHeader implements ByteReadable {
 
     private final Reserved reserved;
 
-    private final Length length;
+    private final TcpLength tcpLength;
 
     ////
     // Used when fields should be calculated. TODO: check if we better work with a subclass.
@@ -43,30 +43,30 @@ public class AMSTCPHeader implements ByteReadable {
     //
     ///
 
-    private AMSTCPHeader(Length length) {
+    private AMSTCPHeader(TcpLength tcpLength) {
         this.reserved = requireNonNull(Reserved.CONSTANT);
-        this.length = requireNonNull(length);
+        this.tcpLength = requireNonNull(tcpLength);
         lengthSuppliers = null;
         calculated = false;
     }
 
     private AMSTCPHeader(LengthSupplier... lengthSuppliers) {
         this.reserved = requireNonNull(Reserved.CONSTANT);
-        this.length = null;
+        this.tcpLength = null;
         this.lengthSuppliers = requireNonNull(lengthSuppliers);
         calculated = true;
     }
 
     public static AMSTCPHeader of(long length) {
-        return new AMSTCPHeader(Length.of(length));
+        return new AMSTCPHeader(TcpLength.of(length));
     }
 
     public static AMSTCPHeader of(LengthSupplier... lengthSuppliers) {
         return new AMSTCPHeader(lengthSuppliers);
     }
 
-    public Length getLength() {
-        return length;
+    public TcpLength getTcpLength() {
+        return tcpLength;
     }
 
     public LengthSupplier[] getLengthSuppliers() {
@@ -79,7 +79,7 @@ public class AMSTCPHeader implements ByteReadable {
 
     @Override
     public ByteBuf getByteBuf() {
-        return buildByteBuff(reserved, calculated ? Length.of(getCalculatedLength()) : length);
+        return buildByteBuff(reserved, calculated ? TcpLength.of(getCalculatedLength()) : tcpLength);
     }
 
     /**
@@ -98,6 +98,7 @@ public class AMSTCPHeader implements ByteReadable {
         }
     }
 
+    @Override
     public long getCalculatedLength() {
         if (calculated) {
             long aggregateLength = 0;
@@ -106,7 +107,7 @@ public class AMSTCPHeader implements ByteReadable {
             }
             return aggregateLength;
         } else {
-            return length.getAsLong();
+            return tcpLength.getAsLong();
         }
     }
 
@@ -114,7 +115,7 @@ public class AMSTCPHeader implements ByteReadable {
     public String toString() {
         return "AMSTCPHeader{" +
             "reserved=" + reserved +
-            ", length=" + (calculated ? Length.of(getCalculatedLength()) : length) +
+            ", tcpLength=" + (calculated ? TcpLength.of(getCalculatedLength()) : tcpLength) +
             '}';
     }
 }
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 48f8592..f7ce3d1 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
@@ -74,6 +74,7 @@ public enum Command implements ByteReadable {
         return value;
     }
 
+    @Override
     public ByteBuf getByteBuf() {
         if (this == UNKNOWN) {
             throw new IllegalStateException("Unknown enum can't be serialized");
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/TcpLength.java
similarity index 65%
rename from plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/Length.java
rename to plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/types/TcpLength.java
index 48075a6..8eaf938 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/TcpLength.java
@@ -21,41 +21,41 @@ package org.apache.plc4x.java.ads.api.generic.types;
 import io.netty.buffer.ByteBuf;
 import org.apache.plc4x.java.ads.api.util.UnsignedIntLEByteValue;
 
-public class Length extends UnsignedIntLEByteValue {
+public class TcpLength extends UnsignedIntLEByteValue {
 
     public static final int NUM_BYTES = UnsignedIntLEByteValue.UNSIGNED_INT_LE_NUM_BYTES;
 
-    public static final Length NONE = of(0);
+    public static final TcpLength NONE = of(0);
 
-    private Length(byte... values) {
+    private TcpLength(byte... values) {
         super(values);
     }
 
-    private Length(long value) {
+    private TcpLength(long value) {
         super(value);
     }
 
-    private Length(String length) {
+    private TcpLength(String length) {
         super(length);
     }
 
-    private Length(ByteBuf byteBuf) {
+    private TcpLength(ByteBuf byteBuf) {
         super(byteBuf);
     }
 
-    public static Length of(byte... values) {
-        return new Length(values);
+    public static TcpLength of(byte... values) {
+        return new TcpLength(values);
     }
 
-    public static Length of(long value) {
-        return new Length(value);
+    public static TcpLength of(long value) {
+        return new TcpLength(value);
     }
 
-    public static Length of(String length) {
-        return new Length(length);
+    public static TcpLength of(String length) {
+        return new TcpLength(length);
     }
 
-    public static Length of(ByteBuf byteBuf) {
-        return new Length(byteBuf);
+    public static TcpLength of(ByteBuf byteBuf) {
+        return new TcpLength(byteBuf);
     }
 }
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadable.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadable.java
index 0d9ac81..a1170a0 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadable.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadable.java
@@ -36,6 +36,7 @@ public interface ByteReadable extends LengthSupplier {
 
     ByteBuf getByteBuf();
 
+    @Override
     default long getCalculatedLength() {
         return getBytes().length;
     }
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 f07fb18..a628cdd 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
@@ -23,7 +23,6 @@ import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.MessageToMessageCodec;
 import org.apache.plc4x.java.ads.api.commands.*;
 import org.apache.plc4x.java.ads.api.commands.types.*;
-import org.apache.plc4x.java.ads.api.commands.types.Length;
 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.AMSTCPPacket;
@@ -62,7 +61,7 @@ public class ADSProtocol extends MessageToMessageCodec<ByteBuf, AMSTCPPacket> {
     protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> out) throws Exception {
         // Reserved
         byteBuf.skipBytes(AMSTCPHeader.Reserved.NUM_BYTES);
-        long packetLength = byteBuf.readUnsignedIntLE();
+        TcpLength packetLength = TcpLength.of(byteBuf);
         AMSNetId targetAmsNetId = AMSNetId.of(byteBuf);
         AMSPort targetAmsPort = AMSPort.of(byteBuf);
         AMSNetId sourceAmsNetId = AMSNetId.of(byteBuf);
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
index 90c288a..b3c3b14 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/GenericTypesFactoryMethodTest.java
@@ -48,7 +48,7 @@ public class GenericTypesFactoryMethodTest {
             Command.class,
             DataLength.class,
             Invoke.class,
-            Length.class,
+            TcpLength.class,
             State.class
         ).map(clazz -> new Object[]{clazz}).collect(Collectors.toList());
     }
diff --git a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/TcpLengthTest.java
similarity index 65%
rename from plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java
rename to plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/TcpLengthTest.java
index 3f9ded4..30b2528 100644
--- a/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/LengthTest.java
+++ b/plc4j/protocols/ads/src/test/java/org/apache/plc4x/java/ads/api/generic/types/TcpLengthTest.java
@@ -26,34 +26,34 @@ import static org.apache.plc4x.java.ads.util.Junit5Backport.assertThrows;
 import static org.junit.Assert.assertEquals;
 
 
-public class LengthTest {
+public class TcpLengthTest {
     private final byte NULL_BYTE = 0x0;
 
     @Test
     public void ofBytes() {
-        assertEquals("0", Length.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString());
-        assertThrows(IllegalArgumentException.class, () -> Length.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE));
+        assertEquals("0", TcpLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE).toString());
+        assertThrows(IllegalArgumentException.class, () -> TcpLength.of(NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE, NULL_BYTE));
     }
 
     @Test
     public void ofLong() {
-        assertByte(Length.of(1), "0x01000000");
-        assertByte(Length.of(65535), "0xffff0000");
-        assertThrows(IllegalArgumentException.class, () -> Length.of(-1));
-        assertThrows(IllegalArgumentException.class, () -> Length.of(4294967296L));
+        assertByte(TcpLength.of(1), "0x01000000");
+        assertByte(TcpLength.of(65535), "0xffff0000");
+        assertThrows(IllegalArgumentException.class, () -> TcpLength.of(-1));
+        assertThrows(IllegalArgumentException.class, () -> TcpLength.of(4294967296L));
     }
 
     @Test
     public void ofString() {
-        assertByte(Length.of("1"), "0x01000000");
+        assertByte(TcpLength.of("1"), "0x01000000");
     }
 
     @Test
     public void testToString() {
-        assertEquals(Length.of("1").toString(), "1");
+        assertEquals(TcpLength.of("1").toString(), "1");
     }
 
-    private void assertByte(Length actual, String expected) {
+    private void assertByte(TcpLength actual, String expected) {
         assertEquals(expected, "0x" + Hex.encodeHexString(actual.getBytes()));
     }
 

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