ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/doc/stringref.pod
(Generate patch)

Comparing CBOR-XS/doc/stringref.pod (file contents):
Revision 1.3 by root, Thu Nov 28 10:16:50 2013 UTC vs.
Revision 1.6 by root, Mon Apr 30 11:24:17 2018 UTC

188encoder to be under control of the sequence in which data items are 188encoder to be under control of the sequence in which data items are
189encoded into the CBOR stream. This means these tags cannot be implemented 189encoded into the CBOR stream. This means these tags cannot be implemented
190on top of every generic CBOR encoder/decoder (which might reorder entries 190on top of every generic CBOR encoder/decoder (which might reorder entries
191in a map); they typically need to be integrated into their works. 191in a map); they typically need to be integrated into their works.
192 192
193=head2 DESIGN RATIONALE
194
195The stringref tag was chosen to be short, without requiring standards
196action. The namespace tag is rare, so doesn't benefit from a short
197encoding as much.
198
199Implicit tagging/counting was chosen to support stream encoders. Having
200to tag strings first requires either multiple passes over the data (which
201might not be available, ruling out some encoders) or tagging more strings
202than needed (wasting space). Explicit tagging also isn't necessarily
203better even under optimal conditions, as the explicit tags waste space.
204
205Stream decoders are affected less by implicit tagging than encoders.
206
207The namespace tag was introduced for two reasons: first to allow embedding
208of CBOR strings into other CBOR strings, secondly for decoding efficiency
209- the decoder only has to expect stringref tags inside namespaces and
210therefore doesn't have to maintain extra state outside of them.
211
193=head1 EXAMPLES 212=head1 EXAMPLES
194 213
195The array-of-maps from the rationale example would normally compress to a 214The array-of-maps from the rationale example would normally compress to a
196CBOR text of 83 bytes. Using this extension where possible, this reduces 215CBOR text of 83 bytes. Using this extension where possible, this reduces
197to 74 bytes: 216to 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
245The strings "1", "4" and "rrr" are too short to get an index assigned. All others that are 264The strings "1", "4" and "rrr" are too short to get an index assigned. All
246not encoded with a stringref do: 265others that are not encoded with a stringref do (this assumes that JSON
266strings 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
343The decoded data structure might look like this: 363The 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
369This section lists known implementations of this extension (L<drop me a
370mail|mailto:cbor@schmorp.de?Subject=CBOR-stringref> if you want to be
371listed 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines