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 2022/07/04 15:45:11 UTC

[plc4x] 01/02: feat(spi): changed the way a byte is rendered

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

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit a243df0a92bc2753ddd8bd9d64a6ee7ee2703ba4
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Jul 4 17:44:31 2022 +0200

    feat(spi): changed the way a byte is rendered
    
    - Now a ascii representation is displayed if applicable
---
 plc4go/internal/spi/utils/WriteBufferBoxBased.go                    | 6 +++++-
 .../org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java   | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/plc4go/internal/spi/utils/WriteBufferBoxBased.go b/plc4go/internal/spi/utils/WriteBufferBoxBased.go
index 9e6cb8b6a..80e1a2d36 100644
--- a/plc4go/internal/spi/utils/WriteBufferBoxBased.go
+++ b/plc4go/internal/spi/utils/WriteBufferBoxBased.go
@@ -98,7 +98,11 @@ func (b *boxedWriteBuffer) WriteBit(logicalName string, value bool, writerArgs .
 
 func (b *boxedWriteBuffer) WriteByte(logicalName string, value byte, writerArgs ...WithWriterArgs) error {
 	additionalStringRepresentation := b.extractAdditionalStringRepresentation(upcastWriterArgs(writerArgs...)...)
-	b.PushBack(b.asciiBoxWriter.BoxString(logicalName, fmt.Sprintf("%#02x%s", value, additionalStringRepresentation), 0))
+	printSafeChar := value
+	if value < 32 || value > 126 {
+		printSafeChar = '.'
+	}
+	b.PushBack(b.asciiBoxWriter.BoxString(logicalName, fmt.Sprintf("%#02x '%c'%s", value, printSafeChar, additionalStringRepresentation), 0))
 	b.move(8)
 	return nil
 }
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java
index 6175eef21..397a93406 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/generation/WriteBufferBoxBased.java
@@ -92,7 +92,7 @@ public class WriteBufferBoxBased implements WriteBuffer, BufferCommons {
     @Override
     public void writeByte(String logicalName, byte value, WithWriterArgs... writerArgs) throws SerializationException {
         String additionalStringRepresentation = extractAdditionalStringRepresentation(writerArgs).map(s -> " " + s).orElse("");
-        boxes.offerLast(Either.left(asciiBoxWriter.boxString(logicalName, String.format("%02x%s", value, additionalStringRepresentation), 0)));
+        boxes.offerLast(Either.left(asciiBoxWriter.boxString(logicalName, String.format("0x%02x '%c'%s", value, value < 32 || value > 126 ? '.' : value, additionalStringRepresentation), 0)));
         move(8);
     }