cbor_py icon indicating copy to clipboard operation
cbor_py copied to clipboard

Generator support

Open vanrein opened this issue 4 years ago • 0 comments

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).

vanrein avatar Mar 08 '20 20:03 vanrein