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


The following commit(s) were added to refs/heads/develop by this push:
     new 7fb6d3f4a6 fix(plc4go): avoid unnecessary wrapping of 
WithReaderWriterArgs
7fb6d3f4a6 is described below

commit 7fb6d3f4a69f28c747ee98689554f6d75388cdef
Author: Sebastian Rühl <[email protected]>
AuthorDate: Thu Mar 19 16:23:07 2026 +0100

    fix(plc4go): avoid unnecessary wrapping of WithReaderWriterArgs
    
    closes #2494
---
 plc4go/spi/utils/Buffer.go |  8 ++++++++
 plc4go/tests/misc_test.go  | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/plc4go/spi/utils/Buffer.go b/plc4go/spi/utils/Buffer.go
index e80248da84..929c60cc7a 100644
--- a/plc4go/spi/utils/Buffer.go
+++ b/plc4go/spi/utils/Buffer.go
@@ -83,6 +83,10 @@ type withEncoding struct {
 func UpcastReaderArgs(args ...WithReaderArgs) []WithReaderWriterArgs {
        result := make([]WithReaderWriterArgs, len(args))
        for i, arg := range args {
+               if readWriterArg, ok := arg.(WithReaderWriterArgs); ok {
+                       result[i] = readWriterArg
+                       continue
+               }
                result[i] = readerWriterArg{arg, writerArg{}}
        }
        return result
@@ -91,6 +95,10 @@ func UpcastReaderArgs(args ...WithReaderArgs) 
[]WithReaderWriterArgs {
 func UpcastWriterArgs(args ...WithWriterArgs) []WithReaderWriterArgs {
        result := make([]WithReaderWriterArgs, len(args))
        for i, arg := range args {
+               if readWriterArg, ok := arg.(WithReaderWriterArgs); ok {
+                       result[i] = readWriterArg
+                       continue
+               }
                result[i] = readerWriterArg{readerArg{}, arg}
        }
        return result
diff --git a/plc4go/tests/misc_test.go b/plc4go/tests/misc_test.go
new file mode 100644
index 0000000000..4b3f605400
--- /dev/null
+++ b/plc4go/tests/misc_test.go
@@ -0,0 +1,28 @@
+package tests
+
+import (
+       "encoding/binary"
+       "testing"
+
+       "github.com/apache/plc4x/plc4go/spi/codegen"
+       "github.com/apache/plc4x/plc4go/spi/utils"
+       "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
+)
+
+func TestByteOrderUpcast(t *testing.T) {
+       t.Run("little endian", func(t *testing.T) {
+               rw := 
utils.UpcastReaderArgs(codegen.WithByteOrder(binary.LittleEndian))
+               fc := codegen.FieldCommons[any]{}
+               byteOrder := fc.ExtractByteOrder(rw...)
+               require.NotNil(t, byteOrder)
+               assert.Equal(t, binary.LittleEndian, *byteOrder)
+       })
+       t.Run("big endian", func(t *testing.T) {
+               rw := 
utils.UpcastReaderArgs(codegen.WithByteOrder(binary.BigEndian))
+               fc := codegen.FieldCommons[any]{}
+               byteOrder := fc.ExtractByteOrder(rw...)
+               require.NotNil(t, byteOrder)
+               assert.Equal(t, binary.BigEndian, *byteOrder)
+       })
+}

Reply via email to