mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
recv: remove re-buffering from decoded data.
This commit is contained in:
@@ -115,8 +115,7 @@ def _to_bytes(bits):
|
|||||||
yield [converter.to_byte[chunk]]
|
yield [converter.to_byte[chunk]]
|
||||||
|
|
||||||
|
|
||||||
@chain_wrapper
|
def decode_frames(bits, framer=None):
|
||||||
def decode(bits, framer=None):
|
|
||||||
framer = framer or Framer()
|
framer = framer or Framer()
|
||||||
for frame in framer.decode(_to_bytes(bits)):
|
for frame in framer.decode(_to_bytes(bits)):
|
||||||
yield frame
|
yield bytes(frame)
|
||||||
|
|||||||
@@ -163,11 +163,9 @@ class Receiver(object):
|
|||||||
bitstream = self._demodulate(sampler, symbols)
|
bitstream = self._demodulate(sampler, symbols)
|
||||||
bitstream = itertools.chain.from_iterable(bitstream)
|
bitstream = itertools.chain.from_iterable(bitstream)
|
||||||
|
|
||||||
data = framing.decode(bitstream)
|
for frame in framing.decode_frames(bitstream):
|
||||||
chunks = common.iterate(data, size=16, truncate=False, func=bytearray)
|
output.write(frame)
|
||||||
for chunk in chunks:
|
self.output_size += len(frame)
|
||||||
output.write(bytes(chunk))
|
|
||||||
self.output_size += len(chunk)
|
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
if self.stats:
|
if self.stats:
|
||||||
|
|||||||
@@ -31,22 +31,22 @@ def test_framer(data):
|
|||||||
|
|
||||||
def test_main(data):
|
def test_main(data):
|
||||||
encoded = framing.encode(data)
|
encoded = framing.encode(data)
|
||||||
decoded = framing.decode(encoded)
|
decoded = framing.decode_frames(encoded)
|
||||||
assert bytearray(decoded) == data
|
assert concat(decoded) == data
|
||||||
|
|
||||||
|
|
||||||
def test_fail():
|
def test_fail():
|
||||||
encoded = list(framing.encode(''))
|
encoded = list(framing.encode(''))
|
||||||
encoded[-1] = not encoded[-1]
|
encoded[-1] = not encoded[-1]
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
list(framing.decode(encoded))
|
concat(framing.decode_frames(encoded))
|
||||||
|
|
||||||
|
|
||||||
def test_missing():
|
def test_missing():
|
||||||
f = framing.Framer()
|
f = framing.Framer()
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
list(f.decode(b''))
|
concat(f.decode(b''))
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
list(f.decode(b'\x01'))
|
concat(f.decode(b'\x01'))
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
list(f.decode(b'\xff'))
|
concat(f.decode(b'\xff'))
|
||||||
|
|||||||
Reference in New Issue
Block a user