Skip to content

Commit edd312e

Browse files
authored
Fixed incorrect encoding byte length (#9)
1 parent 8746b30 commit edd312e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

jamcodec/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ def __init__(self, length: int, strict_decoding: bool = True):
831831

832832
def encode(self, value: Union[list, str, bytes]) -> JamBytes:
833833

834+
byte_length = (self.length + 7) // 8
835+
834836
if type(value) is list:
835837
value = sum(v << i for i, v in enumerate(value))
836838

@@ -847,8 +849,6 @@ def encode(self, value: Union[list, str, bytes]) -> JamBytes:
847849
if type(value) is not int:
848850
raise ScaleEncodeException("Provided value is not an int, binary str or a list of booleans")
849851

850-
byte_length = math.ceil(value.bit_length() / 8)
851-
852852
return JamBytes(value.to_bytes(length=byte_length, byteorder='little'))
853853

854854
def decode(self, data: JamBytes) -> list:

0 commit comments

Comments
 (0)