cbor2 6.0 changed the tag_hook callback signature from tag_hook(decoder, tag) to
tag_hook(tag, immutable). The hook in stream_v2/examples/client.py (and the
example in cbor/dectris-compression-tag.md) therefore fails on cbor2 >= 6 with:
AttributeError: 'bool' object has no attribute 'tag'
Since both versions pass two positional arguments, the hook can support both by
checking which argument is the CBORTag:
def tag_hook(decoder_or_tag, tag_or_immutable=None):
# cbor2 >= 6 calls tag_hook(tag, immutable); older cbor2 calls tag_hook(decoder, tag)
tag = decoder_or_tag if isinstance(decoder_or_tag, cbor2.CBORTag) else tag_or_immutable
tag_decoder = tag_decoders.get(tag.tag)
return tag_decoder(tag) if tag_decoder else tag
cbor2 6.0 changed the
tag_hookcallback signature fromtag_hook(decoder, tag)totag_hook(tag, immutable). The hook instream_v2/examples/client.py(and theexample in
cbor/dectris-compression-tag.md) therefore fails on cbor2 >= 6 with:Since both versions pass two positional arguments, the hook can support both by
checking which argument is the
CBORTag: