You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/02/24 08:44:19 UTC

[plc4x] 03/06: - Implemented the writeString method in WriteBuffer

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/luxtronik2-driver
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 2c5358cd4a73337ee1f7d02ba65f8880d9b87515
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Feb 24 09:21:32 2020 +0100

    - Implemented the writeString method in WriteBuffer
---
 .../org/apache/plc4x/java/spi/generation/WriteBuffer.java    | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
index 7516277..bffaeee 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBuffer.java
@@ -26,6 +26,7 @@ import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
 
 public class WriteBuffer {
 
@@ -215,8 +216,15 @@ public class WriteBuffer {
         throw new UnsupportedOperationException("not implemented yet");
     }
 
-    public void writeString(int bitLength, String encoding, String value) {
-        throw new UnsupportedOperationException("not implemented yet");
+    public void writeString(int bitLength, String encoding, String value) throws ParseException {
+        final byte[] bytes = value.getBytes(Charset.forName(encoding));
+        try {
+            for (byte aByte : bytes) {
+                bo.writeByte(false, 8, aByte);
+            }
+        } catch (IOException e) {
+           throw new ParseException("Error writing string", e);
+        }
     }
 
 }