projects
/
sandbox
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
5f3192e
)
Handle stream input in deserialize
author
David Kerkeslager
<kerkeslager@gmail.com>
Sat, 24 Sep 2016 20:37:03 +0000
(16:37 -0400)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Sat, 24 Sep 2016 20:37:03 +0000
(16:37 -0400)
serial/binary.py
patch
|
blob
|
history
diff --git
a/serial/binary.py
b/serial/binary.py
index
2b18bfb
..
e8c9093
100644
(file)
--- a/
serial/binary.py
+++ b/
serial/binary.py
@@
-1,4
+1,5
@@
import collections
import collections
+import io
TAG_NULL = 0x00
TAG_TRUE = 0x01
TAG_NULL = 0x00
TAG_TRUE = 0x01
@@
-32,7
+33,7
@@
def serialize(to):
def _make_tag_only_parser(tag, value):
def parser(b):
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
return parser
@@
-43,7
+44,14
@@
_TAGS_TO_PARSERS = {
}
def deserialize(b):
}
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
if len(remainder) == 0:
return result