Show More
@@ -140,12 +140,15 b' def streamencodearrayfromiter(it):' | |||||
140 |
|
140 | |||
141 | yield BREAK |
|
141 | yield BREAK | |
142 |
|
142 | |||
|
143 | def _mixedtypesortkey(v): | |||
|
144 | return type(v).__name__, v | |||
|
145 | ||||
143 | def streamencodeset(s): |
|
146 | def streamencodeset(s): | |
144 | # https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml defines |
|
147 | # https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml defines | |
145 | # semantic tag 258 for finite sets. |
|
148 | # semantic tag 258 for finite sets. | |
146 | yield encodelength(MAJOR_TYPE_SEMANTIC, 258) |
|
149 | yield encodelength(MAJOR_TYPE_SEMANTIC, 258) | |
147 |
|
150 | |||
148 | for chunk in streamencodearray(sorted(s)): |
|
151 | for chunk in streamencodearray(sorted(s, key=_mixedtypesortkey)): | |
149 | yield chunk |
|
152 | yield chunk | |
150 |
|
153 | |||
151 | def streamencodemap(d): |
|
154 | def streamencodemap(d): | |
@@ -155,7 +158,8 b' def streamencodemap(d):' | |||||
155 | """ |
|
158 | """ | |
156 | yield encodelength(MAJOR_TYPE_MAP, len(d)) |
|
159 | yield encodelength(MAJOR_TYPE_MAP, len(d)) | |
157 |
|
160 | |||
158 |
for key, value in sorted(d.iteritems() |
|
161 | for key, value in sorted(d.iteritems(), | |
|
162 | key=lambda x: _mixedtypesortkey(x[0])): | |||
159 | for chunk in streamencode(key): |
|
163 | for chunk in streamencode(key): | |
160 | yield chunk |
|
164 | yield chunk | |
161 | for chunk in streamencode(value): |
|
165 | for chunk in streamencode(value): |
General Comments 0
You need to be logged in to leave comments.
Login now