… | |
… | |
188 | encoder to be under control of the sequence in which data items are |
188 | encoder to be under control of the sequence in which data items are |
189 | encoded into the CBOR stream. This means these tags cannot be implemented |
189 | encoded into the CBOR stream. This means these tags cannot be implemented |
190 | on top of every generic CBOR encoder/decoder (which might reorder entries |
190 | on top of every generic CBOR encoder/decoder (which might reorder entries |
191 | in a map); they typically need to be integrated into their works. |
191 | in a map); they typically need to be integrated into their works. |
192 | |
192 | |
|
|
193 | =head2 DESIGN RATIONALE |
|
|
194 | |
|
|
195 | The stringref tag was chosen to be short, without requiring standards |
|
|
196 | action. The namespace tag is rare, so doesn't benefit from a short |
|
|
197 | encoding as much. |
|
|
198 | |
|
|
199 | Implicit tagging/counting was chosen to support stream encoders. Having |
|
|
200 | to tag strings first requires either multiple passes over the data (which |
|
|
201 | might not be available, ruling out some encoders) or tagging more strings |
|
|
202 | than needed (wasting space). Explicit tagging also isn't necessarily |
|
|
203 | better even under optimal conditions, as the explicit tags waste space. |
|
|
204 | |
|
|
205 | Stream decoders are affected less by implicit tagging than encoders. |
|
|
206 | |
|
|
207 | The namespace tag was introduced for two reasons: first to allow embedding |
|
|
208 | of CBOR strings into other CBOR strings, secondly for decoding efficiency |
|
|
209 | - the decoder only has to expect stringref tags inside namespaces and |
|
|
210 | therefore doesn't have to maintain extra state outside of them. |
|
|
211 | |
193 | =head1 EXAMPLES |
212 | =head1 EXAMPLES |
194 | |
213 | |
195 | The array-of-maps from the rationale example would normally compress to a |
214 | The array-of-maps from the rationale example would normally compress to a |
196 | CBOR text of 83 bytes. Using this extension where possible, this reduces |
215 | CBOR text of 83 bytes. Using this extension where possible, this reduces |
197 | to 74 bytes: |
216 | to 74 bytes: |
… | |
… | |
240 | "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp", "qqq", "rrr", |
259 | "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp", "qqq", "rrr", |
241 | "333", |
260 | "333", |
242 | "ssss", |
261 | "ssss", |
243 | "qqq", "rrr", "ssss"] |
262 | "qqq", "rrr", "ssss"] |
244 | |
263 | |
245 | The strings "1", "4" and "rrr" are too short to get an index assigned. All others that are |
264 | The strings "1", "4" and "rrr" are too short to get an index assigned. All |
246 | not encoded with a stringref do: |
265 | others that are not encoded with a stringref do (this assumes that JSON |
|
|
266 | strings are encoded as CBOR byte strings): |
247 | |
267 | |
248 | d9 0100 # tag(256) |
268 | d9 0100 # tag(256) |
249 | 98 20 # array(32) |
269 | 98 20 # array(32) |
250 | 41 # bytes(1) |
270 | 41 # bytes(1) |
251 | 31 # "1" |
271 | 31 # "1" |
… | |
… | |
299 | 707070 # "ppp" |
319 | 707070 # "ppp" |
300 | 43 # bytes(3) |
320 | 43 # bytes(3) |
301 | 717171 # "qqq" |
321 | 717171 # "qqq" |
302 | 43 # bytes(3) |
322 | 43 # bytes(3) |
303 | 727272 # "rrr" |
323 | 727272 # "rrr" |
|
|
324 | d8 19 # tag(25) |
|
|
325 | 01 # unsigned(1) |
304 | 44 # bytes(4) |
326 | 44 # bytes(4) |
305 | 73737373 # "ssss" |
327 | 73737373 # "ssss" |
306 | d8 19 # tag(25) |
|
|
307 | 01 # unsigned(1) |
|
|
308 | d8 19 # tag(25) |
328 | d8 19 # tag(25) |
309 | 17 # unsigned(23) |
329 | 17 # unsigned(23) |
310 | 43 # bytes(3) |
330 | 43 # bytes(3) |
311 | 727272 # "rrr" |
331 | 727272 # "rrr" |
312 | d8 19 # tag(25) |
332 | d8 19 # tag(25) |
… | |
… | |
342 | |
362 | |
343 | The decoded data structure might look like this: |
363 | The decoded data structure might look like this: |
344 | |
364 | |
345 | ["aaa","aaa",["bbb","aaa","aaa"],["ccc","ccc"],"aaa"] |
365 | ["aaa","aaa",["bbb","aaa","aaa"],["ccc","ccc"],"aaa"] |
346 | |
366 | |
|
|
367 | =head1 IMPLEMENTATIONS |
347 | |
368 | |
|
|
369 | This section lists known implementations of this extension (L<drop me a |
|
|
370 | mail|mailto:cbor@schmorp.de?Subject=CBOR-stringref> if you want to be |
|
|
371 | listed here). |
|
|
372 | |
|
|
373 | =over 4 |
|
|
374 | |
|
|
375 | =item * [Perl] L<CBOR::XS|http://software.schmorp.de/pkg/CBOR-XS.html> (reference implementation) |
|
|
376 | |
|
|
377 | =back |
|
|
378 | |