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:02 UTC
[incubator-plc4x] 01/02: Revert "increase performance by
eliminating loops for building."
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 b02b0a115dc6d6776b2a8a2933edda265141ba7b
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Mar 8 08:45:34 2018 +0100
Revert "increase performance by eliminating loops for building."
This reverts commit e07180c
---
.../commands/ADSAddDeviceNotificationRequest.java | 10 +------
.../commands/ADSAddDeviceNotificationResponse.java | 5 +---
.../ADSDeleteDeviceNotificationRequest.java | 4 +--
.../ADSDeleteDeviceNotificationResponse.java | 4 +--
.../api/commands/ADSDeviceNotificationRequest.java | 9 ++----
.../api/commands/ADSReadDeviceInfoResponse.java | 10 ++-----
.../java/ads/api/commands/ADSReadRequest.java | 8 ++---
.../java/ads/api/commands/ADSReadResponse.java | 8 ++---
.../ads/api/commands/ADSReadStateResponse.java | 4 +--
.../java/ads/api/commands/ADSReadWriteRequest.java | 8 +----
.../ads/api/commands/ADSReadWriteResponse.java | 6 +---
.../ads/api/commands/ADSWriteControlRequest.java | 7 +----
.../ads/api/commands/ADSWriteControlResponse.java | 4 +--
.../java/ads/api/commands/ADSWriteRequest.java | 7 +----
.../java/ads/api/commands/ADSWriteResponse.java | 2 +-
.../api/commands/types/AdsNotificationSample.java | 8 ++---
.../ads/api/commands/types/AdsStampHeader.java | 10 ++-----
.../plc4x/java/ads/api/generic/AMSHeader.java | 22 +++++++-------
.../plc4x/java/ads/api/generic/AMSTCPHeader.java | 4 +--
.../plc4x/java/ads/api/generic/AMSTCPPacket.java | 8 ++---
.../plc4x/java/ads/api/util/ByteReadableUtils.java | 35 ++++++++++++++++++++++
21 files changed, 76 insertions(+), 107 deletions(-)
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationRequest.java
index 3a03b11..7e96a3c 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationRequest.java
@@ -100,15 +100,7 @@ public class ADSAddDeviceNotificationRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- indexGroup.getByteBuf(),
- indexOffset.getByteBuf(),
- length.getByteBuf(),
- transmissionMode.getByteBuf(),
- maxDelay.getByteBuf(),
- cycleTime.getByteBuf(),
- reserved.getByteBuf()
- );
+ return buildADSData(indexGroup, indexOffset, length, transmissionMode, maxDelay, cycleTime, reserved);
}
public static ADSAddDeviceNotificationRequest of(AMSTCPHeader amstcpHeader, AMSHeader amsHeader, IndexGroup indexGroup, IndexOffset indexOffset, Length length, TransmissionMode transmissionMode, MaxDelay maxDelay, CycleTime cycleTime) {
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationResponse.java
index c0b650e..db59dd6 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSAddDeviceNotificationResponse.java
@@ -76,10 +76,7 @@ public class ADSAddDeviceNotificationResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf(),
- notificationHandle.getByteBuf()
- );
+ return buildADSData(result, notificationHandle);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationRequest.java
index a0b4b84..44f0258 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationRequest.java
@@ -73,9 +73,7 @@ public class ADSDeleteDeviceNotificationRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- notificationHandle.getByteBuf()
- );
+ return buildADSData(notificationHandle);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationResponse.java
index fe03098..14de8ff 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeleteDeviceNotificationResponse.java
@@ -64,9 +64,7 @@ public class ADSDeleteDeviceNotificationResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf()
- );
+ return buildADSData(result);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeviceNotificationRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeviceNotificationRequest.java
index e4e70a1..24fa24b 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeviceNotificationRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSDeviceNotificationRequest.java
@@ -18,7 +18,6 @@
*/
package org.apache.plc4x.java.ads.api.commands;
-import io.netty.buffer.ByteBuf;
import org.apache.plc4x.java.ads.api.commands.types.AdsStampHeader;
import org.apache.plc4x.java.ads.api.commands.types.Length;
import org.apache.plc4x.java.ads.api.commands.types.Stamps;
@@ -34,7 +33,6 @@ import org.apache.plc4x.java.ads.api.util.LengthSupplier;
import java.util.List;
-import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.Objects.requireNonNull;
/**
@@ -120,10 +118,7 @@ public class ADSDeviceNotificationRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- getLength().getByteBuf(),
- stamps.getByteBuf(),
- wrappedBuffer(adsStampHeaders.stream().map(ByteReadable::getByteBuf).toArray(ByteBuf[]::new)));
+ return buildADSData(getLength(), stamps, buildADSData(adsStampHeaders.toArray(new ByteReadable[adsStampHeaders.size()])));
}
@Override
@@ -141,7 +136,7 @@ public class ADSDeviceNotificationRequest extends ADSAbstractRequest {
return false;
if (!stamps.equals(that.stamps))
return false;
-
+
return adsStampHeaders.equals(that.adsStampHeaders);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadDeviceInfoResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadDeviceInfoResponse.java
index baed360..3f11b28 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadDeviceInfoResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadDeviceInfoResponse.java
@@ -104,13 +104,7 @@ public class ADSReadDeviceInfoResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf(),
- majorVersion.getByteBuf(),
- minorVersion.getByteBuf(),
- version.getByteBuf(),
- device.getByteBuf()
- );
+ return buildADSData(result, majorVersion, minorVersion, version, device);
}
@Override
@@ -132,7 +126,7 @@ public class ADSReadDeviceInfoResponse extends ADSAbstractResponse {
return false;
if (!version.equals(that.version))
return false;
-
+
return device.equals(that.device);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadRequest.java
index 65ed495..880f3f3 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadRequest.java
@@ -99,11 +99,7 @@ public class ADSReadRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- indexGroup.getByteBuf(),
- indexOffset.getByteBuf(),
- length.getByteBuf()
- );
+ return buildADSData(indexGroup, indexOffset, length);
}
@Override
@@ -121,7 +117,7 @@ public class ADSReadRequest extends ADSAbstractRequest {
return false;
if (!indexOffset.equals(that.indexOffset))
return false;
-
+
return length.equals(that.length);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadResponse.java
index 1386d6d..8a38d58 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadResponse.java
@@ -79,11 +79,7 @@ public class ADSReadResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf(),
- getLength().getByteBuf(),
- data.getByteBuf()
- );
+ return buildADSData(result, getLength(), data);
}
public Result getResult() {
@@ -113,7 +109,7 @@ public class ADSReadResponse extends ADSAbstractResponse {
return false;
if (!getLength().equals(that.getLength()))
return false;
-
+
return data.equals(that.data);
}
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadStateResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadStateResponse.java
index ae88895..53e8985 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadStateResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadStateResponse.java
@@ -64,9 +64,7 @@ public class ADSReadStateResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf()
- );
+ return buildADSData(result);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteRequest.java
index 7574d29..ef82e33 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteRequest.java
@@ -125,13 +125,7 @@ public class ADSReadWriteRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- indexGroup.getByteBuf(),
- indexOffset.getByteBuf(),
- readLength.getByteBuf(),
- getWriteLength().getByteBuf(),
- data.getByteBuf()
- );
+ return buildADSData(indexGroup, indexOffset, readLength, getWriteLength(), data);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteResponse.java
index 21fbb2e..8328882 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSReadWriteResponse.java
@@ -93,11 +93,7 @@ public class ADSReadWriteResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf(),
- getLength().getByteBuf(),
- data.getByteBuf()
- );
+ return buildADSData(result, getLength(), data);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlRequest.java
index 61a851f..d2f7121 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlRequest.java
@@ -117,12 +117,7 @@ public class ADSWriteControlRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- adsState.getByteBuf(),
- deviceState.getByteBuf(),
- getLength().getByteBuf(),
- data.getByteBuf()
- );
+ return buildADSData(adsState, deviceState, getLength(), data);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlResponse.java
index c8bcd37..86e2b0a 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteControlResponse.java
@@ -63,9 +63,7 @@ public class ADSWriteControlResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(
- result.getByteBuf()
- );
+ return buildADSData(result);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteRequest.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteRequest.java
index 7d03778..6ce66a6 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteRequest.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteRequest.java
@@ -115,12 +115,7 @@ public class ADSWriteRequest extends ADSAbstractRequest {
@Override
public ADSData getAdsData() {
- return buildADSData(
- indexGroup.getByteBuf(),
- indexOffset.getByteBuf(),
- getLength().getByteBuf(),
- data.getByteBuf()
- );
+ return buildADSData(indexGroup, indexOffset, getLength(), data);
}
@Override
diff --git a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteResponse.java b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteResponse.java
index 859f5f8..fc3de95 100644
--- a/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteResponse.java
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/commands/ADSWriteResponse.java
@@ -64,7 +64,7 @@ public class ADSWriteResponse extends ADSAbstractResponse {
@Override
public ADSData getAdsData() {
- return buildADSData(result.getByteBuf());
+ return buildADSData(result);
}
@Override
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 09d055a..325b6e3 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
@@ -22,8 +22,8 @@ import io.netty.buffer.ByteBuf;
import org.apache.plc4x.java.ads.api.util.ByteReadable;
import org.apache.plc4x.java.ads.api.util.LengthSupplier;
-import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.Objects.requireNonNull;
+import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
public class AdsNotificationSample implements ByteReadable {
@@ -66,11 +66,7 @@ public class AdsNotificationSample implements ByteReadable {
@Override
public ByteBuf getByteBuf() {
- return wrappedBuffer(
- notificationHandle.getByteBuf(),
- getSampleSize().getByteBuf(),
- data.getByteBuf()
- );
+ return buildByteBuff(notificationHandle, getSampleSize(), data);
}
public NotificationHandle getNotificationHandle() {
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 4dea0e4..2c9b56b 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
@@ -23,8 +23,8 @@ import org.apache.plc4x.java.ads.api.util.ByteReadable;
import java.util.List;
-import static io.netty.buffer.Unpooled.wrappedBuffer;
import static java.util.Objects.requireNonNull;
+import static org.apache.plc4x.java.ads.api.util.ByteReadableUtils.buildByteBuff;
public class AdsStampHeader implements ByteReadable {
@@ -63,11 +63,7 @@ public class AdsStampHeader implements ByteReadable {
@Override
public ByteBuf getByteBuf() {
- return wrappedBuffer(
- timeStamp.getByteBuf(),
- samples.getByteBuf(),
- wrappedBuffer(adsNotificationSamples.stream().map(ByteReadable::getByteBuf).toArray(ByteBuf[]::new))
- );
+ return buildByteBuff(timeStamp, samples, () -> buildByteBuff(adsNotificationSamples.toArray(new ByteReadable[adsNotificationSamples.size()])));
}
public TimeStamp getTimeStamp() {
@@ -95,7 +91,7 @@ public class AdsStampHeader implements ByteReadable {
return false;
if (!samples.equals(that.samples))
return false;
-
+
return adsNotificationSamples.equals(that.adsNotificationSamples);
}
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 3a64b38..72bb6f0 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
@@ -19,12 +19,12 @@
package org.apache.plc4x.java.ads.api.generic;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import org.apache.plc4x.java.ads.api.generic.types.*;
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.
@@ -108,16 +108,16 @@ public class AMSHeader implements ByteReadable {
@Override
public ByteBuf getByteBuf() {
- return Unpooled.wrappedBuffer(
- targetAmsNetId.getByteBuf(),
- targetAmsPort.getByteBuf(),
- sourceAmsNetId.getByteBuf(),
- sourceAmsPort.getByteBuf(),
- commandId.getByteBuf(),
- stateFlags.getByteBuf(),
- getDataLength().getByteBuf(),
- code.getByteBuf(),
- invokeId.getByteBuf());
+ return buildByteBuff(
+ targetAmsNetId,
+ targetAmsPort,
+ sourceAmsNetId,
+ sourceAmsPort,
+ commandId,
+ stateFlags,
+ getDataLength(),
+ code,
+ invokeId);
}
public AMSNetId getTargetAmsNetId() {
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 3ff396c..d7d7e0a 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,13 +19,13 @@
package org.apache.plc4x.java.ads.api.generic;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
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;
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.
@@ -69,7 +69,7 @@ public class AMSTCPHeader implements ByteReadable {
@Override
public ByteBuf getByteBuf() {
- return Unpooled.wrappedBuffer(reserved.getByteBuf(), getTcpLength().getByteBuf());
+ return buildByteBuff(reserved, getTcpLength());
}
/**
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 e9ab7a7..cb1bafd 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
@@ -19,12 +19,12 @@
package org.apache.plc4x.java.ads.api.generic;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import org.apache.plc4x.java.ads.api.commands.ADSCommandType;
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;
@@ -72,11 +72,11 @@ public abstract class AMSTCPPacket implements ByteReadable {
@Override
public ByteBuf getByteBuf() {
- return Unpooled.wrappedBuffer(amsTcpHeader.getByteBuf(), amsHeader.getByteBuf(), getAdsData().getByteBuf());
+ return buildByteBuff(amsTcpHeader, amsHeader, getAdsData());
}
- protected ADSData buildADSData(ByteBuf... byteReadables) {
- return () -> Unpooled.wrappedBuffer(byteReadables);
+ protected ADSData buildADSData(ByteReadable... byteReadables) {
+ return () -> buildByteBuff(byteReadables);
}
@Override
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/ByteReadableUtils.java
new file mode 100644
index 0000000..fc9898b
--- /dev/null
+++ b/plc4j/protocols/ads/src/main/java/org/apache/plc4x/java/ads/api/util/ByteReadableUtils.java
@@ -0,0 +1,35 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.ads.api.util;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import java.util.Arrays;
+
+public class ByteReadableUtils {
+
+ private ByteReadableUtils() {
+ // Singleton
+ }
+
+ public static ByteBuf buildByteBuff(ByteReadable... byteReadables) {
+ return Unpooled.wrappedBuffer(Arrays.stream(byteReadables).map(ByteReadable::getByteBuf).toArray(ByteBuf[]::new));
+ }
+}
--
To stop receiving notification emails like this one, please contact
sruehl@apache.org.