cbor_py
cbor_py copied to clipboard
Generator support
The CBOR format has self-descriptive length, so many of its elements can be placed in sequence, or in a stream. For that I find a generator a useful concept. I had to code it like this,
def ll1generate_cbor_tokens (token, f):
if token is not None:
yield token
try:
while True:
yield cbor.load (f)
except EOFError:
pass
It would be useful to have this supported directly for files, sockets and strings. The behaviour of loads()
is even to ignore the extra content, and reveal nothing about the fact that it exists (AFAIK).