Skip to content

Commit 1bbd332

Browse files
committed
Fixed invalid UTF-8 by sending data as Scaled Count 2
1 parent 2e06c04 commit 1bbd332

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pynuodb/encodedsession.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class EncodedSession(Session):
4343
putScaledTime -- Appends a Scaled Time value to the message.
4444
putScaledTimestamp -- Appends a Scaled Timestamp value to the message.
4545
putScaledDate -- Appends a Scaled Date value to the message.
46+
putScaledCount2 -- Appends a scaled and signed decimal to the message
4647
putValue -- Determines the probable type of the value and calls the supporting function.
4748
getInt -- Read the next Integer value off the session.
4849
getScaledInt -- Read the next Scaled Integer value off the session.
@@ -396,6 +397,11 @@ def putScaledInt(self, value):
396397
value += 0
397398
scale = abs(value.as_tuple()[2])
398399
valueStr = toSignedByteString(int(value * decimal.Decimal(10**scale)))
400+
401+
#If our length is more than 9 bytes we will need to send the data using ScaledCount2
402+
if len(valueStr) > 9:
403+
return self.putScaledCount2(value)
404+
399405
packed = chr(protocol.SCALEDLEN0 + len(valueStr)) + chr(scale) + valueStr
400406
self.__output += packed
401407
return self
@@ -531,6 +537,15 @@ def putScaledDate(self, value):
531537
self.__output += packed
532538
return self
533539

540+
def putScaledCount2(self, value):
541+
""" Appends a scaled and signed decimal to the message """
542+
scale = abs(value.as_tuple()[2])
543+
sign = "1" if value.as_tuple()[0] == 0 else "-1"
544+
value = toSignedByteString(int(value * decimal.Decimal(10**scale)))
545+
packed = chr(protocol.SCALEDCOUNT2) + chr(scale) + sign + chr(len(value)) + value
546+
self.__output += packed
547+
return self
548+
534549
def putValue(self, value):
535550
"""Determines the probable type of the value and calls the supporting function."""
536551
if value is None:

tests/nuodb_basic_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def _test_decimal_fixture(self, value, precision, scale):
153153
#
154154
# py.test -k "test_many_significant_digits"
155155
#
156-
@unittest.skip("produces invalid UTF-8 code sequence")
157156
def test_many_significant_digits(self):
158157
self._test_decimal_fixture(decimal.Decimal("31943874831932418390.01"), 38, 12)
159158

0 commit comments

Comments
 (0)