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/08 08:00:03 UTC

[incubator-plc4x] 02/02: + extracted getByteBuf to own supplier method. + included buildByteBuff into ByteReadable

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 7d2458d1adf1c211d0e250be42ab2c4f16fec46e
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Mar 8 08:59:57 2018 +0100

    + extracted getByteBuf to own supplier method.
    + included buildByteBuff into ByteReadable
---
 .../java/ads/api/commands/types/AdsNotificationSample.java |  1 -
 .../plc4x/java/ads/api/commands/types/AdsStampHeader.java  |  1 -
 .../org/apache/plc4x/java/ads/api/generic/AMSHeader.java   |  1 -
 .../apache/plc4x/java/ads/api/generic/AMSTCPHeader.java    |  1 -
 .../apache/plc4x/java/ads/api/generic/AMSTCPPacket.java    |  1 -
 .../util/{ByteReadableUtils.java => ByteBufSupplier.java}  | 14 +++-----------
 .../org/apache/plc4x/java/ads/api/util/ByteReadable.java   | 11 +++++++----
 7 files changed, 10 insertions(+), 20 deletions(-)

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 325b6e3..b4040cb 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
@@ -23,7 +23,6 @@ import org.apache.plc4x.java.ads.api.util.ByteReadable;
 import org.apache.plc4x.java.ads.api.util.LengthSupplier;
 
 import static java.util.Objects.requireNonNull;
-import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 public class AdsNotificationSample implements ByteReadable {
 
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 2c9b56b..8a64a92 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
@@ -24,7 +24,6 @@ import org.apache.plc4x.java.ads.api.util.ByteReadable;
 import java.util.List;
 
 import static java.util.Objects.requireNonNull;
-import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 public class AdsStampHeader implements ByteReadable {
 
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSHeader.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSHeader.java
index 72bb6f0..2d6249c 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSHeader.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSHeader.java
@@ -24,7 +24,6 @@ import org.apache.plc4x.java.ads.api.util.ByteReadable;
 import org.apache.plc4x.java.ads.api.util.LengthSupplier;
 
 import static java.util.Objects.requireNonNull;
-import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 /**
  * AMS Header	32 bytes	The AMS/TCP-Header contains the addresses of the transmitter and receiver. In addition the AMS error code , the ADS command Id and some other information.
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 d7d7e0a..8210203 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
@@ -25,7 +25,6 @@ import org.apache.plc4x.java.ads.api.util.ByteValue;
 import org.apache.plc4x.java.ads.api.util.LengthSupplier;
 
 import static java.util.Objects.requireNonNull;
-import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 /**
  * AMS/TCP Header	6 bytes	contains the tcpLength of the data packet.
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPPacket.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPPacket.java
index cb1bafd..d9b2626 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPPacket.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/generic/AMSTCPPacket.java
@@ -24,7 +24,6 @@ import org.apache.plc4x.java.ads.api.generic.types.*;
 import org.apache.plc4x.java.ads.api.util.ByteReadable;
 
 import static java.util.Objects.requireNonNull;
-import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
 
 public abstract class AMSTCPPacket implements ByteReadable {
     private final AMSTCPHeader amsTcpHeader;
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadableUtils.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteBufSupplier.java
similarity index 70%
rename from plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadableUtils.java
rename to plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteBufSupplier.java
index fc9898b..017ffc8 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadableUtils.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteBufSupplier.java
@@ -19,17 +19,9 @@
 package org.apache.plc4x.java.ads.api.util;
 
 import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 
-import java.util.Arrays;
+@FunctionalInterface
+public interface ByteBufSupplier {
 
-public class ByteReadableUtils {
-
-    private ByteReadableUtils() {
-        // Singleton
-    }
-
-    public static ByteBuf buildByteBuff(ByteReadable... byteReadables) {
-        return Unpooled.wrappedBuffer(Arrays.stream(byteReadables).map(ByteReadable::getByteBuf).toArray(ByteBuf[]::new));
-    }
+    ByteBuf getByteBuf();
 }
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 e909b6e..f3eaa07 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
@@ -19,13 +19,14 @@
 package org.apache.plc4x.java.ads.api.util;
 
 import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.apache.commons.io.HexDump;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.util.Arrays;
 
-@FunctionalInterface
-public interface ByteReadable extends LengthSupplier {
+public interface ByteReadable extends ByteBufSupplier, LengthSupplier {
 
     default byte[] getBytes() {
         ByteBuf byteBuf = getByteBuf();
@@ -34,13 +35,15 @@ public interface ByteReadable extends LengthSupplier {
         return result;
     }
 
-    ByteBuf getByteBuf();
-
     @Override
     default long getCalculatedLength() {
         return getByteBuf().readableBytes();
     }
 
+    default ByteBuf buildByteBuff(ByteReadable... byteReadables) {
+        return Unpooled.wrappedBuffer(Arrays.stream(byteReadables).map(ByteReadable::getByteBuf).toArray(ByteBuf[]::new));
+    }
+
     default String dump() throws IOException {
         try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
             HexDump.dump(getBytes(), 0, byteArrayOutputStream, 0);

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