8000 Added support of bytearrays to msgpack/fallback.py · popravich/msgpack-python@48ca2d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48ca2d7

Browse files
committed
Added support of bytearrays to msgpack/fallback.py
1 parent d5436c2 commit 48ca2d7

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

msgpack/fallback.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
193193
def feed(self, next_bytes):
194194
if isinstance(next_bytes, array.array):
195195
next_bytes = next_bytes.tostring()
196+
elif isinstance(next_bytes, bytearray):
197+
next_bytes = str(next_bytes)
196198
assert self._fb_feeding
197199
if self._fb_buf_n + len(next_bytes) > self._max_buffer_size:
198200
raise BufferFull

test/test_buffer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ def test_unpack_buffer():
1111
obj = unpackb(buf, use_list=1)
1212
assert [b'foo', b'bar'] == obj
1313

14+
15+
def test_unpack_bytearray():
16+
buf = bytearray(packb(('foo', 'bar')))
17+
obj = unpackb(buf, use_list=1)
18+
assert [b'foo', b'bar'] == obj
19+
assert all(type(s)==str for s in obj)
20+

0 commit comments

Comments
 (0)
0