Subject: Re: [Cbor] Maps used as keys?

From: Kio Smallwood <[email-masked]>
Date: Mon, 16 Apr 2018 01:21:22 +0100

Hi All, 

Sorry to be late to the party but we recently fixed this issue for one
of the Python implementations: https://github.com/agronholm/cbor2 

Although we're very unlikely to use a python dictionary-like object as a
key, it also encountered this problem if an array was being used as a
key since by default, arrays are de-serialized into lists, and those are
not usable as keys either. 

All mutable and unhashable types which can be used as keys in CBOR will
be unpacked as equivalent immutable and hashable types. 

* list => tuple 

* bytearray => bytes 

* map => frozendict 

* set (tag 258) => frozenset 

cbor2 also supports custom tag handling which can be made aware that it
is currently decoding a key and behave accordingly, as documented here:
http://cbor2.readthedocs.io/en/latest/customizing.html#decoding-tagged-items-as-keys

Hope that helps protocol implementers. 

Cheers, 

Kio