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 5e88487ffb8e2ed534c98b233d003514c6ad5654
Author: Sebastian Rühl <[email protected]>
AuthorDate: Wed Apr 21 16:34:39 2021 +0200

    plc4go: fixed bug where enum got prefixed by space on commons method
---
 plc4go/internal/plc4go/spi/utils/WriteBufferBoxBased.go  |  8 ++++++++
 plc4go/internal/plc4go/spi/utils/WriteBufferJsonBased.go | 11 +++--------
 plc4go/internal/plc4go/spi/utils/bufferCommons.go        |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/plc4go/internal/plc4go/spi/utils/WriteBufferBoxBased.go 
b/plc4go/internal/plc4go/spi/utils/WriteBufferBoxBased.go
index 24b5e68..57815a0 100644
--- a/plc4go/internal/plc4go/spi/utils/WriteBufferBoxBased.go
+++ b/plc4go/internal/plc4go/spi/utils/WriteBufferBoxBased.go
@@ -178,3 +178,11 @@ findTheBox:
        b.PushBack(asciiBox)
        return nil
 }
+
+func (b *boxedWriteBuffer) 
extractAdditionalStringRepresentation(readerWriterArgs ...WithReaderWriterArgs) 
string {
+       representation := 
b.bufferCommons.extractAdditionalStringRepresentation(readerWriterArgs...)
+       if representation != "" {
+               return " " + representation
+       }
+       return ""
+}
diff --git a/plc4go/internal/plc4go/spi/utils/WriteBufferJsonBased.go 
b/plc4go/internal/plc4go/spi/utils/WriteBufferJsonBased.go
index 3df6349..964b583 100644
--- a/plc4go/internal/plc4go/spi/utils/WriteBufferJsonBased.go
+++ b/plc4go/internal/plc4go/spi/utils/WriteBufferJsonBased.go
@@ -239,14 +239,9 @@ func (j *jsonWriteBuffer) generateAttr(logicalName string, 
dataType string, bitL
        logicalName = j.sanitizeLogicalName(logicalName)
        attr[fmt.Sprintf("%s__plc4x_%s", logicalName, rwDataTypeKey)] = dataType
        attr[fmt.Sprintf("%s__plc4x_%s", logicalName, rwBitLengthKey)] = 
bitLength
-       for _, arg := range writerArgs {
-               if !arg.isWriterArgs() {
-                       panic("not a writer arg")
-               }
-               switch arg.(type) {
-               case withAdditionalStringRepresentation:
-                       attr[fmt.Sprintf("%s__plc4x_%s", logicalName, 
rwStringRepresentationKey)] = 
arg.(withAdditionalStringRepresentation).stringRepresentation
-               }
+       additionalStringRepresentation := 
j.extractAdditionalStringRepresentation(upcastWriterArgs(writerArgs...)...)
+       if additionalStringRepresentation != "" {
+               attr[fmt.Sprintf("%s__plc4x_%s", logicalName, 
rwStringRepresentationKey)] = additionalStringRepresentation
        }
        return attr
 }
diff --git a/plc4go/internal/plc4go/spi/utils/bufferCommons.go 
b/plc4go/internal/plc4go/spi/utils/bufferCommons.go
index 5ab13d8..bebbe3c 100644
--- a/plc4go/internal/plc4go/spi/utils/bufferCommons.go
+++ b/plc4go/internal/plc4go/spi/utils/bufferCommons.go
@@ -64,7 +64,7 @@ func (b bufferCommons) 
extractAdditionalStringRepresentation(readerWriterArgs ..
                }
                switch arg.(type) {
                case withAdditionalStringRepresentation:
-                       return " " + 
arg.(withAdditionalStringRepresentation).stringRepresentation
+                       return 
arg.(withAdditionalStringRepresentation).stringRepresentation
                }
        }
        return ""

Reply via email to