From e7e157bf8ed9f207921a22c74382bb1c500a57f7 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Sat, 24 Sep 2016 16:37:03 -0400 Subject: [PATCH] Handle stream input in deserialize --- serial/binary.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/serial/binary.py b/serial/binary.py index 2b18bfb..e8c9093 100644 --- a/serial/binary.py +++ b/serial/binary.py @@ -1,4 +1,5 @@ import collections +import io TAG_NULL = 0x00 TAG_TRUE = 0x01 @@ -32,7 +33,7 @@ def serialize(to): def _make_tag_only_parser(tag, value): def parser(b): - return TaggedObject(tag = tag, instance = value), b + return TaggedObject(tag = tag, instance = value) return parser @@ -43,7 +44,14 @@ _TAGS_TO_PARSERS = { } def deserialize(b): - result, remainder = _TAGS_TO_PARSERS[b[0]](b[1:]) + if isinstance(b, bytes): + b = io.BytesIO(b) + + tag = b.read(1)[0] + + result = _TAGS_TO_PARSERS[tag](b) + + remainder = b.read() if len(remainder) == 0: return result -- 2.20.1