You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2023/05/17 04:15:31 UTC

[plc4x] 01/03: feat(plc4py): WriteBuffer Add local byte_order check

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

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

commit 3f7001b18472645e45b1082eb10de7466b829e3c
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Sun May 14 05:18:11 2023 +0200

    feat(plc4py): WriteBuffer Add local byte_order check
---
 sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
index 187d1aa0af..31fa7ed6e2 100644
--- a/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
+++ b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
@@ -107,7 +107,6 @@ class WriteBufferByteBased(WriteBuffer):
 
     NUMERIC_UNION = Union[c_byte, c_uint8, c_uint16, c_uint32, c_uint64, c_int8, c_int16, c_int32, c_int64, c_float, c_double]
 
-
     def __init__(self, size: int, byte_order: ByteOrder):
         self.bb = zeros(size * 8, endian=ByteOrder.get_short_name(byte_order))
         self.byte_order = byte_order
@@ -208,6 +207,7 @@ class WriteBufferByteBased(WriteBuffer):
         self._handle_numeric_encoding(c_double(value.value), bit_length, **kwargs)
 
     def _handle_numeric_encoding(self, value: NUMERIC_UNION, bit_length: int, **kwargs):
+        byte_order = kwargs.get("byte_order", self.byte_order)
         value_encoding: str = kwargs.get("encoding", "default")
         if value_encoding == "ASCII":
             if bit_length % 8 != 0:
@@ -219,12 +219,12 @@ class WriteBufferByteBased(WriteBuffer):
                 raise SerializationException(
                     "Provided value of " + str(value) + " exceeds the max value of " + str(max_value))
             string_value: str = "{}".format(value.value)
-            src = bitarray(endian=ByteOrder.get_short_name(self.byte_order))
+            src = bitarray(endian=ByteOrder.get_short_name(byte_order))
             src.frombytes(bytearray(string_value, value_encoding))
             self.bb[self.position:bit_length] = src[:bit_length]
             self.position += bit_length
         elif value_encoding == "default":
-            src = bitarray(endian=ByteOrder.get_short_name(self.byte_order))
+            src = bitarray(endian=ByteOrder.get_short_name(byte_order))
             src.frombytes(value)
             self.bb[self.position:bit_length] = src[:bit_length]
             self.position += bit_length