idnits 2.17.1 draft-ietf-cbor-7049bis-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- -- The abstract seems to indicate that this document obsoletes RFC7049, but the header doesn't have an 'Obsoletes:' line to match this. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (August 25, 2019) is 1705 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '2' on line 2495 -- Looks like a reference, but probably isn't: '3' on line 2495 -- Looks like a reference, but probably isn't: '4' on line 2493 -- Looks like a reference, but probably isn't: '5' on line 2493 -- Looks like a reference, but probably isn't: '100' on line 1357 == Missing Reference: '-1' is mentioned on line 1353, but not defined -- Looks like a reference, but probably isn't: '1' on line 2779 == Missing Reference: 'RFCthis' is mentioned on line 2086, but not defined == Missing Reference: 'TM' is mentioned on line 2314, but not defined -- Looks like a reference, but probably isn't: '0' on line 2795 == Missing Reference: 'RFC4627' is mentioned on line 2930, but not defined ** Obsolete undefined reference: RFC 4627 (Obsoleted by RFC 7158, RFC 7159) == Missing Reference: 'CNN-TERMS' is mentioned on line 2932, but not defined -- Possible downref: Non-RFC (?) normative reference: ref. 'ECMA262' -- Possible downref: Non-RFC (?) normative reference: ref. 'IEEE754' -- Obsolete informational reference (is this intentional?): RFC 7049 (Obsoleted by RFC 8949) Summary: 1 error (**), 0 flaws (~~), 6 warnings (==), 13 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group C. Bormann 3 Internet-Draft Universitaet Bremen TZI 4 Intended status: Standards Track P. Hoffman 5 Expires: February 26, 2020 ICANN 6 August 25, 2019 8 Concise Binary Object Representation (CBOR) 9 draft-ietf-cbor-7049bis-07 11 Abstract 13 The Concise Binary Object Representation (CBOR) is a data format 14 whose design goals include the possibility of extremely small code 15 size, fairly small message size, and extensibility without the need 16 for version negotiation. These design goals make it different from 17 earlier binary serializations such as ASN.1 and MessagePack. 19 This document is a revised edition of RFC 7049, with editorial 20 improvements, added detail, and fixed errata. This revision formally 21 obsoletes RFC 7049, while keeping full compatibility of the 22 interchange format from RFC 7049. It does not create a new version 23 of the format. 25 Contributing 27 This document is being worked on in the CBOR Working Group. Please 28 contribute on the mailing list there, or in the GitHub repository for 29 this draft: https://github.com/cbor-wg/CBORbis 31 The charter for the CBOR Working Group says that the WG will update 32 RFC 7049 to fix verified errata. Security issues and clarifications 33 may be addressed, but changes to this document will ensure backward 34 compatibility for popular deployed codebases. This document will be 35 targeted at becoming an Internet Standard. 37 Status of This Memo 39 This Internet-Draft is submitted in full conformance with the 40 provisions of BCP 78 and BCP 79. 42 Internet-Drafts are working documents of the Internet Engineering 43 Task Force (IETF). Note that other groups may also distribute 44 working documents as Internet-Drafts. The list of current Internet- 45 Drafts is at https://datatracker.ietf.org/drafts/current/. 47 Internet-Drafts are draft documents valid for a maximum of six months 48 and may be updated, replaced, or obsoleted by other documents at any 49 time. It is inappropriate to use Internet-Drafts as reference 50 material or to cite them other than as "work in progress." 52 This Internet-Draft will expire on February 26, 2020. 54 Copyright Notice 56 Copyright (c) 2019 IETF Trust and the persons identified as the 57 document authors. All rights reserved. 59 This document is subject to BCP 78 and the IETF Trust's Legal 60 Provisions Relating to IETF Documents 61 (https://trustee.ietf.org/license-info) in effect on the date of 62 publication of this document. Please review these documents 63 carefully, as they describe your rights and restrictions with respect 64 to this document. Code Components extracted from this document must 65 include Simplified BSD License text as described in Section 4.e of 66 the Trust Legal Provisions and are provided without warranty as 67 described in the Simplified BSD License. 69 Table of Contents 71 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 72 1.1. Objectives . . . . . . . . . . . . . . . . . . . . . . . 4 73 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 74 2. CBOR Data Models . . . . . . . . . . . . . . . . . . . . . . 7 75 2.1. Extended Generic Data Models . . . . . . . . . . . . . . 8 76 2.2. Specific Data Models . . . . . . . . . . . . . . . . . . 9 77 3. Specification of the CBOR Encoding . . . . . . . . . . . . . 9 78 3.1. Major Types . . . . . . . . . . . . . . . . . . . . . . . 10 79 3.2. Indefinite Lengths for Some Major Types . . . . . . . . . 13 80 3.2.1. The "break" Stop Code . . . . . . . . . . . . . . . . 13 81 3.2.2. Indefinite-Length Arrays and Maps . . . . . . . . . . 13 82 3.2.3. Indefinite-Length Byte Strings and Text Strings . . . 15 83 3.3. Floating-Point Numbers and Values with No Content . . . . 16 84 3.4. Tagging of Items . . . . . . . . . . . . . . . . . . . . 17 85 3.4.1. Date and Time . . . . . . . . . . . . . . . . . . . . 19 86 3.4.2. Standard Date/Time String . . . . . . . . . . . . . . 19 87 3.4.3. Epoch-based Date/Time . . . . . . . . . . . . . . . . 20 88 3.4.4. Bignums . . . . . . . . . . . . . . . . . . . . . . . 20 89 3.4.5. Decimal Fractions and Bigfloats . . . . . . . . . . . 21 90 3.4.6. Content Hints . . . . . . . . . . . . . . . . . . . . 23 91 3.4.6.1. Encoded CBOR Data Item . . . . . . . . . . . . . 23 92 3.4.6.2. Expected Later Encoding for CBOR-to-JSON 93 Converters . . . . . . . . . . . . . . . . . . . 23 94 3.4.6.3. Encoded Text . . . . . . . . . . . . . . . . . . 24 95 3.4.7. Self-Described CBOR . . . . . . . . . . . . . . . . . 25 96 4. Serialization Considerations . . . . . . . . . . . . . . . . 25 97 4.1. Preferred Serialization . . . . . . . . . . . . . . . . . 25 98 4.2. Deterministically Encoded CBOR . . . . . . . . . . . . . 26 99 4.2.1. Core Deterministic Encoding Requirements . . . . . . 26 100 4.2.2. Additional Deterministic Encoding Considerations . . 27 101 4.2.3. Length-first map key ordering . . . . . . . . . . . . 28 102 5. Creating CBOR-Based Protocols . . . . . . . . . . . . . . . . 29 103 5.1. CBOR in Streaming Applications . . . . . . . . . . . . . 30 104 5.2. Generic Encoders and Decoders . . . . . . . . . . . . . . 31 105 5.3. Invalid Items . . . . . . . . . . . . . . . . . . . . . . 31 106 5.4. Handling Unknown Simple Values and Tags . . . . . . . . . 32 107 5.5. Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 33 108 5.6. Specifying Keys for Maps . . . . . . . . . . . . . . . . 33 109 5.6.1. Equivalence of Keys . . . . . . . . . . . . . . . . . 34 110 5.7. Undefined Values . . . . . . . . . . . . . . . . . . . . 35 111 5.8. Strict Decoding Mode . . . . . . . . . . . . . . . . . . 35 112 6. Converting Data between CBOR and JSON . . . . . . . . . . . . 37 113 6.1. Converting from CBOR to JSON . . . . . . . . . . . . . . 37 114 6.2. Converting from JSON to CBOR . . . . . . . . . . . . . . 38 115 7. Future Evolution of CBOR . . . . . . . . . . . . . . . . . . 39 116 7.1. Extension Points . . . . . . . . . . . . . . . . . . . . 40 117 7.2. Curating the Additional Information Space . . . . . . . . 40 118 8. Diagnostic Notation . . . . . . . . . . . . . . . . . . . . . 41 119 8.1. Encoding Indicators . . . . . . . . . . . . . . . . . . . 42 120 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 42 121 9.1. Simple Values Registry . . . . . . . . . . . . . . . . . 43 122 9.2. Tags Registry . . . . . . . . . . . . . . . . . . . . . . 43 123 9.3. Media Type ("MIME Type") . . . . . . . . . . . . . . . . 43 124 9.4. CoAP Content-Format . . . . . . . . . . . . . . . . . . . 44 125 9.5. The +cbor Structured Syntax Suffix Registration . . . . . 45 126 10. Security Considerations . . . . . . . . . . . . . . . . . . . 45 127 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 47 128 11.1. Normative References . . . . . . . . . . . . . . . . . . 47 129 11.2. Informative References . . . . . . . . . . . . . . . . . 48 130 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 50 131 Appendix B. Jump Table . . . . . . . . . . . . . . . . . . . . . 54 132 Appendix C. Pseudocode . . . . . . . . . . . . . . . . . . . . . 57 133 Appendix D. Half-Precision . . . . . . . . . . . . . . . . . . . 59 134 Appendix E. Comparison of Other Binary Formats to CBOR's Design 135 Objectives . . . . . . . . . . . . . . . . . . . . . 60 136 E.1. ASN.1 DER, BER, and PER . . . . . . . . . . . . . . . . . 61 137 E.2. MessagePack . . . . . . . . . . . . . . . . . . . . . . . 61 138 E.3. BSON . . . . . . . . . . . . . . . . . . . . . . . . . . 62 139 E.4. MSDTP: RFC 713 . . . . . . . . . . . . . . . . . . . . . 62 140 E.5. Conciseness on the Wire . . . . . . . . . . . . . . . . . 62 141 Appendix F. Changes from RFC 7049 . . . . . . . . . . . . . . . 63 142 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 63 143 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 64 145 1. Introduction 147 There are hundreds of standardized formats for binary representation 148 of structured data (also known as binary serialization formats). Of 149 those, some are for specific domains of information, while others are 150 generalized for arbitrary data. In the IETF, probably the best-known 151 formats in the latter category are ASN.1's BER and DER [ASN.1]. 153 The format defined here follows some specific design goals that are 154 not well met by current formats. The underlying data model is an 155 extended version of the JSON data model [RFC8259]. It is important 156 to note that this is not a proposal that the grammar in RFC 8259 be 157 extended in general, since doing so would cause a significant 158 backwards incompatibility with already deployed JSON documents. 159 Instead, this document simply defines its own data model that starts 160 from JSON. 162 Appendix E lists some existing binary formats and discusses how well 163 they do or do not fit the design objectives of the Concise Binary 164 Object Representation (CBOR). 166 This document is a revised edition of [RFC7049], with editorial 167 improvements, added detail, and fixed errata. This revision formally 168 obsoletes RFC 7049, while keeping full compatibility of the 169 interchange format from RFC 7049. It does not create a new version 170 of the format. 172 1.1. Objectives 174 The objectives of CBOR, roughly in decreasing order of importance, 175 are: 177 1. The representation must be able to unambiguously encode most 178 common data formats used in Internet standards. 180 * It must represent a reasonable set of basic data types and 181 structures using binary encoding. "Reasonable" here is 182 largely influenced by the capabilities of JSON, with the major 183 addition of binary byte strings. The structures supported are 184 limited to arrays and trees; loops and lattice-style graphs 185 are not supported. 187 * There is no requirement that all data formats be uniquely 188 encoded; that is, it is acceptable that the number "7" might 189 be encoded in multiple different ways. 191 2. The code for an encoder or decoder must be able to be compact in 192 order to support systems with very limited memory, processor 193 power, and instruction sets. 195 * An encoder and a decoder need to be implementable in a very 196 small amount of code (for example, in class 1 constrained 197 nodes as defined in [RFC7228]). 199 * The format should use contemporary machine representations of 200 data (for example, not requiring binary-to-decimal 201 conversion). 203 3. Data must be able to be decoded without a schema description. 205 * Similar to JSON, encoded data should be self-describing so 206 that a generic decoder can be written. 208 4. The serialization must be reasonably compact, but data 209 compactness is secondary to code compactness for the encoder and 210 decoder. 212 * "Reasonable" here is bounded by JSON as an upper bound in 213 size, and by implementation complexity maintaining a lower 214 bound. Using either general compression schemes or extensive 215 bit-fiddling violates the complexity goals. 217 5. The format must be applicable to both constrained nodes and high- 218 volume applications. 220 * This means it must be reasonably frugal in CPU usage for both 221 encoding and decoding. This is relevant both for constrained 222 nodes and for potential usage in applications with a very high 223 volume of data. 225 6. The format must support all JSON data types for conversion to and 226 from JSON. 228 * It must support a reasonable level of conversion as long as 229 the data represented is within the capabilities of JSON. It 230 must be possible to define a unidirectional mapping towards 231 JSON for all types of data. 233 7. The format must be extensible, and the extended data must be 234 decodable by earlier decoders. 236 * The format is designed for decades of use. 238 * The format must support a form of extensibility that allows 239 fallback so that a decoder that does not understand an 240 extension can still decode the message. 242 * The format must be able to be extended in the future by later 243 IETF standards. 245 1.2. Terminology 247 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 248 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 249 "OPTIONAL" in this document are to be interpreted as described in 250 BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all 251 capitals, as shown here. 253 The term "byte" is used in its now-customary sense as a synonym for 254 "octet". All multi-byte values are encoded in network byte order 255 (that is, most significant byte first, also known as "big-endian"). 257 This specification makes use of the following terminology: 259 Data item: A single piece of CBOR data. The structure of a data 260 item may contain zero, one, or more nested data items. The term 261 is used both for the data item in representation format and for 262 the abstract idea that can be derived from that by a decoder. 264 Decoder: A process that decodes a well-formed CBOR data item and 265 makes it available to an application. Formally speaking, a 266 decoder contains a parser to break up the input using the syntax 267 rules of CBOR, as well as a semantic processor to prepare the data 268 in a form suitable to the application. 270 Encoder: A process that generates the representation format of a 271 CBOR data item from application information. 273 Data Stream: A sequence of zero or more data items, not further 274 assembled into a larger containing data item. The independent 275 data items that make up a data stream are sometimes also referred 276 to as "top-level data items". 278 Well-formed: A data item that follows the syntactic structure of 279 CBOR. A well-formed data item uses the initial bytes and the byte 280 strings and/or data items that are implied by their values as 281 defined in CBOR and does not include following extraneous data. 282 CBOR decoders by definition only return contents from well-formed 283 data items. 285 Valid: A data item that is well-formed and also follows the semantic 286 restrictions that apply to CBOR data items. 288 Stream decoder: A process that decodes a data stream and makes each 289 of the data items in the sequence available to an application as 290 they are received. 292 Where bit arithmetic or data types are explained, this document uses 293 the notation familiar from the programming language C, except that 294 "**" denotes exponentiation. Similar to the "0x" notation for 295 hexadecimal numbers, numbers in binary notation are prefixed with 296 "0b". Underscores can be added to such a number solely for 297 readability, so 0b00100001 (0x21) might be written 0b001_00001 to 298 emphasize the desired interpretation of the bits in the byte; in this 299 case, it is split into three bits and five bits. Encoded CBOR data 300 items are sometimes given in the "0x" or "0b" notation; these values 301 are first interpreted as numbers as in C and are then interpreted as 302 byte strings in network byte order, including any leading zero bytes 303 expressed in the notation. 305 2. CBOR Data Models 307 CBOR is explicit about its generic data model, which defines the set 308 of all data items that can be represented in CBOR. Its basic generic 309 data model is extensible by the registration of simple type values 310 and tags. Applications can then subset the resulting extended 311 generic data model to build their specific data models. 313 Within environments that can represent the data items in the generic 314 data model, generic CBOR encoders and decoders can be implemented 315 (which usually involves defining additional implementation data types 316 for those data items that do not already have a natural 317 representation in the environment). The ability to provide generic 318 encoders and decoders is an explicit design goal of CBOR; however 319 many applications will provide their own application-specific 320 encoders and/or decoders. 322 In the basic (un-extended) generic data model, a data item is one of: 324 o an integer in the range -2**64..2**64-1 inclusive 326 o a simple value, identified by a number between 0 and 255, but 327 distinct from that number 329 o a floating-point value, distinct from an integer, out of the set 330 representable by IEEE 754 binary64 (including non-finites) 331 [IEEE754] 333 o a sequence of zero or more bytes ("byte string") 335 o a sequence of zero or more Unicode code points ("text string") 337 o a sequence of zero or more data items ("array") 339 o a mapping (mathematical function) from zero or more data items 340 ("keys") each to a data item ("values"), ("map") 342 o a tagged data item ("tag"), comprising a tag number (an integer in 343 the range 0..2**64-1) and a tagged value (a data item) 345 Note that integer and floating-point values are distinct in this 346 model, even if they have the same numeric value. 348 Also note that serialization variants, such as number of bytes of the 349 encoded floating value, or the choice of one of the ways in which an 350 integer, the length of a text or byte string, the number of elements 351 in an array or pairs in a map, or a tag number, (collectively "the 352 argument", see Section 3) can be encoded, are not visible at the 353 generic data model level. 355 2.1. Extended Generic Data Models 357 This basic generic data model comes pre-extended by the registration 358 of a number of simple values and tag numbers right in this document, 359 such as: 361 o "false", "true", "null", and "undefined" (simple values identified 362 by 20..23) 364 o integer and floating-point values with a larger range and 365 precision than the above (tag numbers 2 to 5) 367 o application data types such as a point in time or an RFC 3339 368 date/time string (tag numbers 1, 0) 370 Further elements of the extended generic data model can be (and have 371 been) defined via the IANA registries created for CBOR. Even if such 372 an extension is unknown to a generic encoder or decoder, data items 373 using that extension can be passed to or from the application by 374 representing them at the interface to the application within the 375 basic generic data model, i.e., as generic values of a simple type or 376 generic tags. 378 In other words, the basic generic data model is stable as defined in 379 this document, while the extended generic data model expands by the 380 registration of new simple values or tag numbers, but never shrinks. 382 While there is a strong expectation that generic encoders and 383 decoders can represent "false", "true", and "null" ("undefined" is 384 intentionally omitted) in the form appropriate for their programming 385 environment, implementation of the data model extensions created by 386 tags is truly optional and a matter of implementation quality. 388 2.2. Specific Data Models 390 The specific data model for a CBOR-based protocol usually subsets the 391 extended generic data model and assigns application semantics to the 392 data items within this subset and its components. When documenting 393 such specific data models, where it is desired to specify the types 394 of data items, it is preferred to identify the types by the names 395 they have in the generic data model ("negative integer", "array") 396 instead of by referring to aspects of their CBOR representation 397 ("major type 1", "major type 4"). 399 Specific data models can also specify what values (including values 400 of different types) are equivalent for the purposes of map keys and 401 encoder freedom. For example, in the generic data model, a valid map 402 MAY have both "0" and "0.0" as keys, and an encoder MUST NOT encode 403 "0.0" as an integer (major type 0, Section 3.1). However, if a 404 specific data model declares that floating-point and integer 405 representations of integral values are equivalent, using both map 406 keys "0" and "0.0" in a single map would be considered duplicates and 407 so invalid, and an encoder could encode integral-valued floats as 408 integers or vice versa, perhaps to save encoded bytes. 410 3. Specification of the CBOR Encoding 412 A CBOR data item (Section 2) is encoded to or decoded from a byte 413 string carrying a well-formed encoded data item as described in this 414 section. The encoding is summarized in Table 6. An encoder MUST 415 produce only well-formed encoded data items. A decoder MUST NOT 416 return a decoded data item when it encounters input that is not a 417 well-formed encoded CBOR data item (this does not detract from the 418 usefulness of diagnostic and recovery tools that might make available 419 some information from a damaged encoded CBOR data item). 421 The initial byte of each encoded data item contains both information 422 about the major type (the high-order 3 bits, described in 423 Section 3.1) and additional information (the low-order 5 bits). With 424 a few exceptions, the additional information's value describes how to 425 load an unsigned integer "argument": 427 Less than 24: The argument's value is the value of the additional 428 information. 430 24, 25, 26, or 27: The argument's value is held in the following 1, 431 2, 4, or 8 bytes, respectively, in network byte order. For major 432 type 7 and additional information value 25, 26, 27, these bytes 433 are not used as an integer argument, but as a floating-point value 434 (see Section 3.3). 436 28, 29, 30: These values are reserved for future additions to the 437 CBOR format. In the present version of CBOR, the encoded item is 438 not well-formed. 440 31: No argument value is derived. If the major type is 0, 1, or 6, 441 the encoded item is not well-formed. For major types 2 to 5, the 442 item's length is indefinite, and for major type 7, the byte does 443 not consitute a data item at all but terminates an indefinite 444 length item; both are described in Section 3.2. 446 The initial byte and any additional bytes consumed to construct the 447 argument are collectively referred to as the "head" of the data item. 449 The meaning of this argument depends on the major type. For example, 450 in major type 0, the argument is the value of the data item itself 451 (and in major type 1 the value of the data item is computed from the 452 argument); in major type 2 and 3 it gives the length of the string 453 data in bytes that follows; and in major types 4 and 5 it is used to 454 determine the number of data items enclosed. 456 If the encoded sequence of bytes ends before the end of a data item, 457 that item is not well-formed. If the encoded sequence of bytes still 458 has bytes remaining after the outermost encoded item is decoded, that 459 encoding is not a single well-formed CBOR item; depending on the 460 application, the decoder may either treat the encoding as not well- 461 formed or just identify the start of the remaining bytes to the 462 application. 464 A CBOR decoder implementation can be based on a jump table with all 465 256 defined values for the initial byte (Table 6). A decoder in a 466 constrained implementation can instead use the structure of the 467 initial byte and following bytes for more compact code (see 468 Appendix C for a rough impression of how this could look). 470 3.1. Major Types 472 The following lists the major types and the additional information 473 and other bytes associated with the type. 475 Major type 0: an integer in the range 0..2**64-1 inclusive. The 476 value of the encoded item is the argument itself. For example, 477 the integer 10 is denoted as the one byte 0b000_01010 (major type 478 0, additional information 10). The integer 500 would be 479 0b000_11001 (major type 0, additional information 25) followed by 480 the two bytes 0x01f4, which is 500 in decimal. 482 Major type 1: a negative integer in the range -2**64..-1 inclusive. 483 The value of the item is -1 minus the argument. For example, the 484 integer -500 would be 0b001_11001 (major type 1, additional 485 information 25) followed by the two bytes 0x01f3, which is 499 in 486 decimal. 488 Major type 2: a byte string. The number of bytes in the string is 489 equal to the argument. For example, a byte string whose length is 490 5 would have an initial byte of 0b010_00101 (major type 2, 491 additional information 5 for the length), followed by 5 bytes of 492 binary content. A byte string whose length is 500 would have 3 493 initial bytes of 0b010_11001 (major type 2, additional information 494 25 to indicate a two-byte length) followed by the two bytes 0x01f4 495 for a length of 500, followed by 500 bytes of binary content. 497 Major type 3: a text string (Section 2), encoded as UTF-8 498 ([RFC3629]). The number of bytes in the string is equal to the 499 argument. A string containing an invalid UTF-8 sequence is well- 500 formed but invalid. This type is provided for systems that need 501 to interpret or display human-readable text, and allows the 502 differentiation between unstructured bytes and text that has a 503 specified repertoire and encoding. In contrast to formats such as 504 JSON, the Unicode characters in this type are never escaped. 505 Thus, a newline character (U+000A) is always represented in a 506 string as the byte 0x0a, and never as the bytes 0x5c6e (the 507 characters "\" and "n") or as 0x5c7530303061 (the characters "\", 508 "u", "0", "0", "0", and "a"). 510 Major type 4: an array of data items. Arrays are also called lists, 511 sequences, or tuples. The argument is the number of data items in 512 the array. Items in an array do not need to all be of the same 513 type. For example, an array that contains 10 items of any type 514 would have an initial byte of 0b100_01010 (major type of 4, 515 additional information of 10 for the length) followed by the 10 516 remaining items. 518 Major type 5: a map of pairs of data items. Maps are also called 519 tables, dictionaries, hashes, or objects (in JSON). A map is 520 comprised of pairs of data items, each pair consisting of a key 521 that is immediately followed by a value. The argument is the 522 number of _pairs_ of data items in the map. For example, a map 523 that contains 9 pairs would have an initial byte of 0b101_01001 524 (major type of 5, additional information of 9 for the number of 525 pairs) followed by the 18 remaining items. The first item is the 526 first key, the second item is the first value, the third item is 527 the second key, and so on. Because items in a map come in pairs, 528 their total number is always even: A map that contains an odd 529 number of items (no value data present after the last key data 530 item) is not well-formed. A map that has duplicate keys may be 531 well-formed, but it is not valid, and thus it causes indeterminate 532 decoding; see also Section 5.6. 534 Major type 6: a tagged data item ("tag") whose tag number is the 535 argument and whose enclosed data item is the single encoded data 536 item that follows the head. See Section 3.4. 538 Major type 7: floating-point numbers and simple values, as well as 539 the "break" stop code. See Section 3.3. 541 These eight major types lead to a simple table showing which of the 542 256 possible values for the initial byte of a data item are used 543 (Table 6). 545 In major types 6 and 7, many of the possible values are reserved for 546 future specification. See Section 9 for more information on these 547 values. 549 Table 1 summarizes the major types defined by CBOR, ignoring the next 550 section for now. The number N in this table stands for the argument, 551 mt for the major type. 553 +----+-----------------------+---------------------------------+ 554 | mt | Meaning | Content | 555 +----+-----------------------+---------------------------------+ 556 | 0 | unsigned integer N | - | 557 | | | | 558 | 1 | negative integer -1-N | - | 559 | | | | 560 | 2 | byte string | N bytes | 561 | | | | 562 | 3 | text string | N bytes (UTF-8 text) | 563 | | | | 564 | 4 | array | N data items (elements) | 565 | | | | 566 | 5 | map | 2N data items (key/value pairs) | 567 | | | | 568 | 6 | tag of number N | 1 data item | 569 | | | | 570 | 7 | simple/float | - | 571 +----+-----------------------+---------------------------------+ 573 Table 1: Overview over CBOR major types (definite length encoded) 575 3.2. Indefinite Lengths for Some Major Types 577 Four CBOR items (arrays, maps, byte strings, and text strings) can be 578 encoded with an indefinite length using additional information value 579 31. This is useful if the encoding of the item needs to begin before 580 the number of items inside the array or map, or the total length of 581 the string, is known. (The application of this is often referred to 582 as "streaming" within a data item.) 584 Indefinite-length arrays and maps are dealt with differently than 585 indefinite-length byte strings and text strings. 587 3.2.1. The "break" Stop Code 589 The "break" stop code is encoded with major type 7 and additional 590 information value 31 (0b111_11111). It is not itself a data item: it 591 is just a syntactic feature to close an indefinite-length item. 593 If the "break" stop code appears anywhere where a data item is 594 expected, other than directly inside an indefinite-length string, 595 array, or map -- for example directly inside a definite-length array 596 or map -- the enclosing item is not well-formed. 598 3.2.2. Indefinite-Length Arrays and Maps 600 Indefinite-length arrays and maps are represented using their major 601 type with the additional information value of 31, followed by an 602 arbitrary-length sequence of zero or more items for an array or key/ 603 value pairs for a map, followed by the "break" stop code 604 (Section 3.2.1). In other words, indefinite-length arrays and maps 605 look identical to other arrays and maps except for beginning with the 606 additional information value of 31 and ending with the "break" stop 607 code. 609 If the break stop code appears after a key in a map, in place of that 610 key's value, the map is not well-formed. 612 There is no restriction against nesting indefinite-length array or 613 map items. A "break" only terminates a single item, so nested 614 indefinite-length items need exactly as many "break" stop codes as 615 there are type bytes starting an indefinite-length item. 617 For example, assume an encoder wants to represent the abstract array 618 [1, [2, 3], [4, 5]]. The definite-length encoding would be 619 0x8301820203820405: 621 83 -- Array of length 3 622 01 -- 1 623 82 -- Array of length 2 624 02 -- 2 625 03 -- 3 626 82 -- Array of length 2 627 04 -- 4 628 05 -- 5 630 Indefinite-length encoding could be applied independently to each of 631 the three arrays encoded in this data item, as required, leading to 632 representations such as: 634 0x9f018202039f0405ffff 635 9F -- Start indefinite-length array 636 01 -- 1 637 82 -- Array of length 2 638 02 -- 2 639 03 -- 3 640 9F -- Start indefinite-length array 641 04 -- 4 642 05 -- 5 643 FF -- "break" (inner array) 644 FF -- "break" (outer array) 646 0x9f01820203820405ff 647 9F -- Start indefinite-length array 648 01 -- 1 649 82 -- Array of length 2 650 02 -- 2 651 03 -- 3 652 82 -- Array of length 2 653 04 -- 4 654 05 -- 5 655 FF -- "break" 657 0x83018202039f0405ff 658 83 -- Array of length 3 659 01 -- 1 660 82 -- Array of length 2 661 02 -- 2 662 03 -- 3 663 9F -- Start indefinite-length array 664 04 -- 4 665 05 -- 5 666 FF -- "break" 668 0x83019f0203ff820405 669 83 -- Array of length 3 670 01 -- 1 671 9F -- Start indefinite-length array 672 02 -- 2 673 03 -- 3 674 FF -- "break" 675 82 -- Array of length 2 676 04 -- 4 677 05 -- 5 679 An example of an indefinite-length map (that happens to have two key/ 680 value pairs) might be: 682 0xbf6346756ef563416d7421ff 683 BF -- Start indefinite-length map 684 63 -- First key, UTF-8 string length 3 685 46756e -- "Fun" 686 F5 -- First value, true 687 63 -- Second key, UTF-8 string length 3 688 416d74 -- "Amt" 689 21 -- Second value, -2 690 FF -- "break" 692 3.2.3. Indefinite-Length Byte Strings and Text Strings 694 Indefinite-length strings are represented by a byte containing the 695 major type and additional information value of 31, followed by a 696 series of zero or more byte or text strings ("chunks") that have 697 definite lengths, followed by the "break" stop code (Section 3.2.1). 698 The data item represented by the indefinite-length string is the 699 concatenation of the chunks (i.e., the empty byte or text string, 700 respectively, if no chunk is present). 702 If any item between the indefinite-length string indicator 703 (0b010_11111 or 0b011_11111) and the "break" stop code is not a 704 definite-length string item of the same major type, the string is not 705 well-formed. 707 If any definite-length text string inside an indefinite-length text 708 string is invalid, the indefinite-length text string is invalid. 709 Note that this implies that the bytes of a single UTF-8 character 710 cannot be spread between chunks: a new chunk can only be started at a 711 character boundary. 713 For example, assume the sequence: 715 0b010_11111 0b010_00100 0xaabbccdd 0b010_00011 0xeeff99 0b111_11111 716 5F -- Start indefinite-length byte string 717 44 -- Byte string of length 4 718 aabbccdd -- Bytes content 719 43 -- Byte string of length 3 720 eeff99 -- Bytes content 721 FF -- "break" 723 After decoding, this results in a single byte string with seven 724 bytes: 0xaabbccddeeff99. 726 3.3. Floating-Point Numbers and Values with No Content 728 Major type 7 is for two types of data: floating-point numbers and 729 "simple values" that do not need any content. Each value of the 730 5-bit additional information in the initial byte has its own separate 731 meaning, as defined in Table 2. Like the major types for integers, 732 items of this major type do not carry content data; all the 733 information is in the initial bytes. 735 +------------+------------------------------------------------------+ 736 | 5-Bit | Semantics | 737 | Value | | 738 +------------+------------------------------------------------------+ 739 | 0..23 | Simple value (value 0..23) | 740 | | | 741 | 24 | Simple value (value 32..255 in following byte) | 742 | | | 743 | 25 | IEEE 754 Half-Precision Float (16 bits follow) | 744 | | | 745 | 26 | IEEE 754 Single-Precision Float (32 bits follow) | 746 | | | 747 | 27 | IEEE 754 Double-Precision Float (64 bits follow) | 748 | | | 749 | 28-30 | Reserved, not well-formed in the present document | 750 | | | 751 | 31 | "break" stop code for indefinite-length items | 752 | | (Section 3.2.1) | 753 +------------+------------------------------------------------------+ 755 Table 2: Values for Additional Information in Major Type 7 757 As with all other major types, the 5-bit value 24 signifies a single- 758 byte extension: it is followed by an additional byte to represent the 759 simple value. (To minimize confusion, only the values 32 to 255 are 760 used.) This maintains the structure of the initial bytes: as for the 761 other major types, the length of these always depends on the 762 additional information in the first byte. Table 3 lists the values 763 assigned and available for simple types. 765 +---------+-----------------+ 766 | Value | Semantics | 767 +---------+-----------------+ 768 | 0..19 | (Unassigned) | 769 | | | 770 | 20 | False | 771 | | | 772 | 21 | True | 773 | | | 774 | 22 | Null | 775 | | | 776 | 23 | Undefined value | 777 | | | 778 | 24..31 | (Reserved) | 779 | | | 780 | 32..255 | (Unassigned) | 781 +---------+-----------------+ 783 Table 3: Simple Values 785 An encoder MUST NOT issue two-byte sequences that start with 0xf8 786 (major type = 7, additional information = 24) and continue with a 787 byte less than 0x20 (32 decimal). Such sequences are not well- 788 formed. (This implies that an encoder cannot encode false, true, 789 null, or undefined in two-byte sequences, only the one-byte variants 790 of these are well-formed.) 792 The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit 793 IEEE 754 binary floating-point values [IEEE754]. These floating- 794 point values are encoded in the additional bytes of the appropriate 795 size. (See Appendix D for some information about 16-bit floating 796 point.) 798 3.4. Tagging of Items 800 In CBOR, a data item can be enclosed by a tag to give it additional 801 semantics while retaining its structure. The tag is major type 6, 802 and represents an unsigned integer as indicated by the tag's argument 803 (Section 3); the (sole) enclosed data item is carried as content 804 data. If a tag requires structured data, this structure is encoded 805 into the nested data item. The definition of a tag number usually 806 restricts what kinds of nested data item or items are valid for tags 807 using this tag number. 809 For example, assume that a byte string of length 12 is marked with a 810 tag of number 2 to indicate it is a positive bignum (Section 3.4.4). 811 This would be marked as 0b110_00010 (major type 6, additional 812 information 2 for the tag number) followed by 0b010_01100 (major type 813 2, additional information of 12 for the length) followed by the 12 814 bytes of the bignum. 816 Decoders do not need to understand tags of every tag number, and tags 817 may be of little value in applications where the implementation 818 creating a particular CBOR data item and the implementation decoding 819 that stream know the semantic meaning of each item in the data flow. 820 Their primary purpose in this specification is to define common data 821 types such as dates. A secondary purpose is to allow optional 822 tagging when the decoder is a generic CBOR decoder that might be able 823 to benefit from hints about the content of items. Understanding the 824 semantic tags is optional for a decoder; it can just jump over the 825 initial bytes of the tag and interpret the tagged data item itself. 827 A tag applies semantics to the data item it encloses. Thus, if tag A 828 encloses tag B, which encloses data item C, tag A applies to the 829 result of applying tag B on data item C. That is, a tagged item is a 830 data item consisting of a tag number and an enclosed value. The 831 content of the tagged item (the enclosed data item) is the data item 832 (the value) that is being tagged. 834 IANA maintains a registry of tag numbers as described in Section 9.2. 835 Table 4 provides a list of tag numbers that were defined in 836 [RFC7049], with definitions in the rest of this section. Note that 837 many other tag numbers have been defined since the publication of 838 [RFC7049]; see the registry described at Section 9.2 for the complete 839 list. 841 +----------+----------+---------------------------------------------+ 842 | Tag | Data | Semantics | 843 | Number | Item | | 844 +----------+----------+---------------------------------------------+ 845 | 0 | text | Standard date/time string; see | 846 | | string | Section 3.4.2 | 847 | | | | 848 | 1 | multiple | Epoch-based date/time; see Section 3.4.3 | 849 | | | | 850 | 2 | byte | Positive bignum; see Section 3.4.4 | 851 | | string | | 852 | | | | 853 | 3 | byte | Negative bignum; see Section 3.4.4 | 854 | | string | | 855 | | | | 856 | 4 | array | Decimal fraction; see Section 3.4.5 | 857 | | | | 858 | 5 | array | Bigfloat; see Section 3.4.5 | 859 | | | | 860 | 21 | multiple | Expected conversion to base64url encoding; | 861 | | | see Section 3.4.6.2 | 862 | | | | 863 | 22 | multiple | Expected conversion to base64 encoding; see | 864 | | | Section 3.4.6.2 | 865 | | | | 866 | 23 | multiple | Expected conversion to base16 encoding; see | 867 | | | Section 3.4.6.2 | 868 | | | | 869 | 24 | byte | Encoded CBOR data item; see Section 3.4.6.1 | 870 | | string | | 871 | | | | 872 | 32 | text | URI; see Section 3.4.6.3 | 873 | | string | | 874 | | | | 875 | 33 | text | base64url; see Section 3.4.6.3 | 876 | | string | | 877 | | | | 878 | 34 | text | base64; see Section 3.4.6.3 | 879 | | string | | 880 | | | | 881 | 35 | text | Regular expression; see Section 3.4.6.3 | 882 | | string | | 883 | | | | 884 | 36 | text | MIME message; see Section 3.4.6.3 | 885 | | string | | 886 | | | | 887 | 55799 | multiple | Self-described CBOR; see Section 3.4.7 | 888 +----------+----------+---------------------------------------------+ 890 Table 4: Tag numbers defined in RFC 7049 892 3.4.1. Date and Time 894 Protocols using tag numbers 0 and 1 extend the generic data model 895 (Section 2) with data items representing points in time. 897 3.4.2. Standard Date/Time String 899 Tag number 0 contains a text string in the standard format described 900 by the "date-time" production in [RFC3339], as refined by Section 3.3 901 of [RFC4287], representing the point in time described there. A 902 nested item of another type or that doesn't match the [RFC4287] 903 format is invalid. 905 3.4.3. Epoch-based Date/Time 907 Tag number 1 contains a numerical value counting the number of 908 seconds from 1970-01-01T00:00Z in UTC time to the represented point 909 in civil time. 911 The enclosed item MUST be an unsigned or negative integer (major 912 types 0 and 1), or a floating-point number (major type 7 with 913 additional information 25, 26, or 27). Other contained types are 914 invalid. 916 Non-negative values (major type 0 and non-negative floating-point 917 numbers) stand for time values on or after 1970-01-01T00:00Z UTC and 918 are interpreted according to POSIX [TIME_T]. (POSIX time is also 919 known as UNIX Epoch time. Note that leap seconds are handled 920 specially by POSIX time and this results in a 1 second discontinuity 921 several times per decade.) Note that applications that require the 922 expression of times beyond early 2106 cannot leave out support of 923 64-bit integers for the enclosed value. 925 Negative values (major type 1 and negative floating-point numbers) 926 are interpreted as determined by the application requirements as 927 there is no universal standard for UTC count-of-seconds time before 928 1970-01-01T00:00Z (this is particularly true for points in time that 929 precede discontinuities in national calendars). The same applies to 930 non-finite values. 932 To indicate fractional seconds, floating-point values can be used 933 within Tag number 1 instead of integer values. Note that this 934 generally requires binary64 support, as binary16 and binary32 provide 935 non-zero fractions of seconds only for a short period of time around 936 early 1970. An application that requires Tag number 1 support may 937 restrict the enclosed value to be an integer (or a floating-point 938 value) only. 940 3.4.4. Bignums 942 Protocols using tag numbers 2 and 3 extend the generic data model 943 (Section 2) with "bignums" representing arbitrarily sized integers. 944 In the generic data model, bignum values are not equal to integers 945 from the basic data model, but specific data models can define that 946 equivalence, and preferred encoding never makes use of bignums that 947 also can be expressed as basic integers (see below). 949 Bignums are encoded as a byte string data item, which is interpreted 950 as an unsigned integer n in network byte order. Contained items of 951 other types are invalid. For tag number 2, the value of the bignum 952 is n. For tag number 3, the value of the bignum is -1 - n. The 953 preferred encoding of the byte string is to leave out any leading 954 zeroes (note that this means the preferred encoding for n = 0 is the 955 empty byte string, but see below). Decoders that understand these 956 tags MUST be able to decode bignums that do have leading zeroes. The 957 preferred encoding of an integer that can be represented using major 958 type 0 or 1 is to encode it this way instead of as a bignum (which 959 means that the empty string never occurs in a bignum when using 960 preferred encoding). Note that this means the non-preferred choice 961 of a bignum representation instead of a basic integer for encoding a 962 number is not intended to have application semantics (just as the 963 choice of a longer basic integer representation than needed, such as 964 0x1800 for 0x00 does not). 966 For example, the number 18446744073709551616 (2**64) is represented 967 as 0b110_00010 (major type 6, tag number 2), followed by 0b010_01001 968 (major type 2, length 9), followed by 0x010000000000000000 (one byte 969 0x01 and eight bytes 0x00). In hexadecimal: 971 C2 -- Tag 2 972 49 -- Byte string of length 9 973 010000000000000000 -- Bytes content 975 3.4.5. Decimal Fractions and Bigfloats 977 Protocols using tag number 4 extend the generic data model with data 978 items representing arbitrary-length decimal fractions m*(10*e). 979 Protocols using tag number 5 extend the generic data model with data 980 items representing arbitrary-length binary fractions m*(2*e). As 981 with bignums, values of different types are not equal in the generic 982 data model. 984 Decimal fractions combine an integer mantissa with a base-10 scaling 985 factor. They are most useful if an application needs the exact 986 representation of a decimal fraction such as 1.1 because there is no 987 exact representation for many decimal fractions in binary floating 988 point. 990 Bigfloats combine an integer mantissa with a base-2 scaling factor. 991 They are binary floating-point values that can exceed the range or 992 the precision of the three IEEE 754 formats supported by CBOR 993 (Section 3.3). Bigfloats may also be used by constrained 994 applications that need some basic binary floating-point capability 995 without the need for supporting IEEE 754. 997 A decimal fraction or a bigfloat is represented as a tagged array 998 that contains exactly two integer numbers: an exponent e and a 999 mantissa m. Decimal fractions (tag number 4) use base-10 exponents; 1000 the value of a decimal fraction data item is m*(10**e). Bigfloats 1001 (tag number 5) use base-2 exponents; the value of a bigfloat data 1002 item is m*(2**e). The exponent e MUST be represented in an integer 1003 of major type 0 or 1, while the mantissa also can be a bignum 1004 (Section 3.4.4). Contained items with other structures are invalid. 1006 An example of a decimal fraction is that the number 273.15 could be 1007 represented as 0b110_00100 (major type of 6 for the tag, additional 1008 information of 4 for the number of tag), followed by 0b100_00010 1009 (major type of 4 for the array, additional information of 2 for the 1010 length of the array), followed by 0b001_00001 (major type of 1 for 1011 the first integer, additional information of 1 for the value of -2), 1012 followed by 0b000_11001 (major type of 0 for the second integer, 1013 additional information of 25 for a two-byte value), followed by 1014 0b0110101010110011 (27315 in two bytes). In hexadecimal: 1016 C4 -- Tag 4 1017 82 -- Array of length 2 1018 21 -- -2 1019 19 6ab3 -- 27315 1021 An example of a bigfloat is that the number 1.5 could be represented 1022 as 0b110_00101 (major type of 6 for the tag, additional information 1023 of 5 for the number of tag), followed by 0b100_00010 (major type of 4 1024 for the array, additional information of 2 for the length of the 1025 array), followed by 0b001_00000 (major type of 1 for the first 1026 integer, additional information of 0 for the value of -1), followed 1027 by 0b000_00011 (major type of 0 for the second integer, additional 1028 information of 3 for the value of 3). In hexadecimal: 1030 C5 -- Tag 5 1031 82 -- Array of length 2 1032 20 -- -1 1033 03 -- 3 1035 Decimal fractions and bigfloats provide no representation of 1036 Infinity, -Infinity, or NaN; if these are needed in place of a 1037 decimal fraction or bigfloat, the IEEE 754 half-precision 1038 representations from Section 3.3 can be used. For constrained 1039 applications, where there is a choice between representing a specific 1040 number as an integer and as a decimal fraction or bigfloat (such as 1041 when the exponent is small and non-negative), there is a quality-of- 1042 implementation expectation that the integer representation is used 1043 directly. 1045 3.4.6. Content Hints 1047 The tags in this section are for content hints that might be used by 1048 generic CBOR processors. These content hints do not extend the 1049 generic data model. 1051 3.4.6.1. Encoded CBOR Data Item 1053 Sometimes it is beneficial to carry an embedded CBOR data item that 1054 is not meant to be decoded immediately at the time the enclosing data 1055 item is being decoded. Tag number 24 (CBOR data item) can be used to 1056 tag the embedded byte string as a data item encoded in CBOR format. 1057 Contained items that aren't byte strings are invalid. Any contained 1058 byte string is valid, even if it encodes an invalid or ill-formed 1059 CBOR item. 1061 3.4.6.2. Expected Later Encoding for CBOR-to-JSON Converters 1063 Tags number 21 to 23 indicate that a byte string might require a 1064 specific encoding when interoperating with a text-based 1065 representation. These tags are useful when an encoder knows that the 1066 byte string data it is writing is likely to be later converted to a 1067 particular JSON-based usage. That usage specifies that some strings 1068 are encoded as base64, base64url, and so on. The encoder uses byte 1069 strings instead of doing the encoding itself to reduce the message 1070 size, to reduce the code size of the encoder, or both. The encoder 1071 does not know whether or not the converter will be generic, and 1072 therefore wants to say what it believes is the proper way to convert 1073 binary strings to JSON. 1075 The data item tagged can be a byte string or any other data item. In 1076 the latter case, the tag applies to all of the byte string data items 1077 contained in the data item, except for those contained in a nested 1078 data item tagged with an expected conversion. 1080 These three tag numbers suggest conversions to three of the base data 1081 encodings defined in [RFC4648]. For base64url encoding (tag number 1082 21), padding is not used (see Section 3.2 of RFC 4648); that is, all 1083 trailing equals signs ("=") are removed from the encoded string. For 1084 base64 encoding (tag number 22), padding is used as defined in RFC 1085 4648. For both base64url and base64, padding bits are set to zero 1086 (see Section 3.5 of RFC 4648), and encoding is performed without the 1087 inclusion of any line breaks, whitespace, or other additional 1088 characters. Note that, for all three tag numbers, the encoding of 1089 the empty byte string is the empty text string. 1091 3.4.6.3. Encoded Text 1093 Some text strings hold data that have formats widely used on the 1094 Internet, and sometimes those formats can be validated and presented 1095 to the application in appropriate form by the decoder. There are 1096 tags for some of these formats. As with tag numbers 21 to 23, if 1097 these tags are applied to an item other than a text string, they 1098 apply to all text string data items it contains. 1100 o Tag number 32 is for URIs, as defined in [RFC3986]. If the text 1101 string doesn't match the "URI-reference" production, the string is 1102 invalid. 1104 o Tag numbers 33 and 34 are for base64url- and base64-encoded text 1105 strings, as defined in [RFC4648]. If any of: 1107 * the encoded text string contains non-alphabet characters or 1108 only 1 character in the last block of 4, or 1110 * the padding bits in a 2- or 3-character block are not 0, or 1112 * the base64 encoding has the wrong number of padding characters, 1113 or 1115 * the base64url encoding has padding characters, 1117 the string is invalid. 1119 o Tag number 35 is for regular expressions that are roughly in Perl 1120 Compatible Regular Expressions (PCRE/PCRE2) form [PCRE] or a 1121 version of the JavaScript regular expression syntax [ECMA262]. 1122 (Note that more specific identification may be necessary if the 1123 actual version of the specification underlying the regular 1124 expression, or more than just the text of the regular expression 1125 itself, need to be conveyed.) Any contained string value is 1126 valid. 1128 o Tag number 36 is for MIME messages (including all headers), as 1129 defined in [RFC2045]. A text string that isn't a valid MIME 1130 message is invalid. 1132 Note that tag numbers 33 and 34 differ from 21 and 22 in that the 1133 data is transported in base-encoded form for the former and in raw 1134 byte string form for the latter. 1136 3.4.7. Self-Described CBOR 1138 In many applications, it will be clear from the context that CBOR is 1139 being employed for encoding a data item. For instance, a specific 1140 protocol might specify the use of CBOR, or a media type is indicated 1141 that specifies its use. However, there may be applications where 1142 such context information is not available, such as when CBOR data is 1143 stored in a file that does not have disambiguating metadata. Here, 1144 it may help to have some distinguishing characteristics for the data 1145 itself. 1147 Tag number 55799 is defined for this purpose. It does not impart any 1148 special semantics on the data item that it encloses; that is, the 1149 semantics of a data item enclosed in tag number 55799 is exactly 1150 identical to the semantics of the data item itself. 1152 The serialization of this tag's head is 0xd9d9f7, which does not 1153 appear to be in use as a distinguishing mark for any frequently used 1154 file types. In particular, 0xd9d9f7 is not a valid start of a 1155 Unicode text in any Unicode encoding if it is followed by a valid 1156 CBOR data item. 1158 For instance, a decoder might be able to decode both CBOR and JSON. 1159 Such a decoder would need to mechanically distinguish the two 1160 formats. An easy way for an encoder to help the decoder would be to 1161 tag the entire CBOR item with tag number 55799, the serialization of 1162 which will never be found at the beginning of a JSON text. 1164 4. Serialization Considerations 1166 4.1. Preferred Serialization 1168 For some values at the data model level, CBOR provides multiple 1169 serializations. For many applications, it is desirable that an 1170 encoder always chooses a preferred serialization; however, the 1171 present specification does not put the burden of enforcing this 1172 preference on either encoder or decoder. 1174 Some constrained decoders may be limited in their ability to decode 1175 non-preferred serializations: For example, if only integers below 1176 1_000_000_000 are expected in an application, the decoder may leave 1177 out the code that would be needed to decode 64-bit arguments in 1178 integers. An encoder that always uses preferred serialization 1179 ("preferred encoder") interoperates with this decoder for the numbers 1180 that can occur in this application. More generally speaking, it 1181 therefore can be said that a preferred encoder is more universally 1182 interoperable (and also less wasteful) than one that, say, always 1183 uses 64-bit integers. 1185 Similarly, a constrained encoder may be limited in the variety of 1186 representation variants it supports in such a way that it does not 1187 emit preferred serializations ("variant encoder"): Say, it could be 1188 designed to always use the 32-bit variant for an integer that it 1189 encodes even if a short representation is available (again, assuming 1190 that there is no application need for integers that can only be 1191 represented with the 64-bit variant). A decoder that does not rely 1192 on only ever receiving preferred serializations ("variation-tolerant 1193 decoder") can there be said to be more universally interoperable (it 1194 might very well optimize for the case of receiving preferred 1195 serializations, though). Full implementations of CBOR decoders are 1196 by definition variation-tolerant; the distinction is only relevant if 1197 a constrained implementation of a CBOR decoder meets a variant 1198 encoder. 1200 The preferred serialization always uses the shortest form of 1201 representing the argument (Section 3)); it also uses the shortest 1202 floating-point encoding that preserves the value being encoded (see 1203 Section 5.5). Definite length encoding is preferred whenever the 1204 length is known at the time the serialization of the item starts. 1206 4.2. Deterministically Encoded CBOR 1208 Some protocols may want encoders to only emit CBOR in a particular 1209 deterministic format; those protocols might also have the decoders 1210 check that their input is in that deterministic format. Those 1211 protocols are free to define what they mean by a "deterministic 1212 format" and what encoders and decoders are expected to do. This 1213 section defines a set of restrictions that can serve as the base of 1214 such a deterministic format. 1216 4.2.1. Core Deterministic Encoding Requirements 1218 A CBOR encoding satisfies the "core deterministic encoding 1219 requirements" if it satisfies the following restrictions: 1221 o Arguments (see Section 3) for integers, lengths in major types 2 1222 through 5, and tags MUST be as short as possible. In particular: 1224 * 0 to 23 and -1 to -24 MUST be expressed in the same byte as the 1225 major type; 1227 * 24 to 255 and -25 to -256 MUST be expressed only with an 1228 additional uint8_t; 1230 * 256 to 65535 and -257 to -65536 MUST be expressed only with an 1231 additional uint16_t; 1233 * 65536 to 4294967295 and -65537 to -4294967296 MUST be expressed 1234 only with an additional uint32_t. 1236 o The keys in every map MUST be sorted in the bytewise lexicographic 1237 order of their deterministic encodings. For example, the 1238 following keys are sorted correctly: 1240 1. 10, encoded as 0x0a. 1242 2. 100, encoded as 0x1864. 1244 3. -1, encoded as 0x20. 1246 4. "z", encoded as 0x617a. 1248 5. "aa", encoded as 0x626161. 1250 6. [100], encoded as 0x811864. 1252 7. [-1], encoded as 0x8120. 1254 8. false, encoded as 0xf4. 1256 o Indefinite-length items MUST NOT appear. They can be encoded as 1257 definite-length items instead. 1259 4.2.2. Additional Deterministic Encoding Considerations 1261 If a protocol allows for IEEE floats, then additional deterministic 1262 encoding rules might need to be added. One example rule might be to 1263 have all floats start as a 64-bit float, then do a test conversion to 1264 a 32-bit float; if the result is the same numeric value, use the 1265 shorter value and repeat the process with a test conversion to a 1266 16-bit float. (This rule selects 16-bit float for positive and 1267 negative Infinity as well.) Although IEEE floats can represent both 1268 positive and negative zero as distinct values, the application might 1269 not distinguish these and might decide to represent all zero values 1270 with a positive sign, disallowing negative zero. Also, there are 1271 many representations for NaN. If NaN is an allowed value, it must 1272 always be represented as 0xf97e00. 1274 CBOR tags present additional considerations for deterministic 1275 encoding. The absence or presence of tags in a deterministic format 1276 is determined by the optionality of the tags in the protocol. In a 1277 CBOR-based protocol that allows optional tagging anywhere, the 1278 deterministic format must not allow them. In a protocol that 1279 requires tags in certain places, the tag needs to appear in the 1280 deterministic format. A CBOR-based protocol that uses deterministic 1281 encoding might instead say that all tags that appear in a message 1282 must be retained regardless of whether they are optional. 1284 Protocols that include floating, big integer, or other complex values 1285 need to define extra requirements on their deterministic encodings. 1286 For example: 1288 o If a protocol includes a field that can express floating-point 1289 values (Section 3.3), the protocol's deterministic encoding needs 1290 to specify whether the integer 1.0 is encoded as 0x01, 0xf93c00, 1291 0xfa3f800000, or 0xfb3ff0000000000000. Three sensible rules for 1292 this are: 1294 1. Encode integral values that fit in 64 bits as values from 1295 major types 0 and 1, and other values as the smallest of 16-, 1296 32-, or 64-bit floating point that accurately represents the 1297 value, 1299 2. Encode all values as the smallest of 16-, 32-, or 64-bit 1300 floating point that accurately represents the value, even for 1301 integral values, or 1303 3. Encode all values as 64-bit floating point. 1305 If NaN is an allowed value, the protocol needs to pick a single 1306 representation, for example 0xf97e00. 1308 o If a protocol includes a field that can express integers with an 1309 absolute value of 2^64 or larger using tag numbers 2 or 3 1310 (Section 3.4.4), the protocol's deterministic encoding needs to 1311 specify whether small integers are expressed using the tag or 1312 major types 0 and 1. 1314 o A protocol might give encoders the choice of representing a URL as 1315 either a text string or, using Section 3.4.6.3, tag number 32 1316 containing a text string. This protocol's deterministic encoding 1317 needs to either require that the tag is present or require that 1318 it's absent, not allow either one. 1320 4.2.3. Length-first map key ordering 1322 The core deterministic encoding requirements sort map keys in a 1323 different order from the one suggested by Section 3.9 of [RFC7049] 1324 (called "Canonical CBOR" there). Protocols that need to be 1325 compatible with [RFC7049]'s order can instead be specified in terms 1326 of this specification's "length-first core deterministic encoding 1327 requirements": 1329 A CBOR encoding satisfies the "length-first core deterministic 1330 encoding requirements" if it satisfies the core deterministic 1331 encoding requirements except that the keys in every map MUST be 1332 sorted such that: 1334 1. If two keys have different lengths, the shorter one sorts 1335 earlier; 1337 2. If two keys have the same length, the one with the lower value in 1338 (byte-wise) lexical order sorts earlier. 1340 For example, under the length-first core deterministic encoding 1341 requirements, the following keys are sorted correctly: 1343 1. 10, encoded as 0x0a. 1345 2. -1, encoded as 0x20. 1347 3. false, encoded as 0xf4. 1349 4. 100, encoded as 0x1864. 1351 5. "z", encoded as 0x617a. 1353 6. [-1], encoded as 0x8120. 1355 7. "aa", encoded as 0x626161. 1357 8. [100], encoded as 0x811864. 1359 (Although [RFC7049] used the term "Canonical CBOR" for its form of 1360 requirements on deterministic encoding, this document avoids this 1361 term because "canonicalization" is often associated with specific 1362 uses of deterministic encoding only. The terms are essentially 1363 exchangeable, however, and the set of core requirements in this 1364 document could also be called "Canonical CBOR", while the length- 1365 first-ordered version of that could be called "Old Canonical CBOR".) 1367 5. Creating CBOR-Based Protocols 1369 Data formats such as CBOR are often used in environments where there 1370 is no format negotiation. A specific design goal of CBOR is to not 1371 need any included or assumed schema: a decoder can take a CBOR item 1372 and decode it with no other knowledge. 1374 Of course, in real-world implementations, the encoder and the decoder 1375 will have a shared view of what should be in a CBOR data item. For 1376 example, an agreed-to format might be "the item is an array whose 1377 first value is a UTF-8 string, second value is an integer, and 1378 subsequent values are zero or more floating-point numbers" or "the 1379 item is a map that has byte strings for keys and contains at least 1380 one pair whose key is 0xab01". 1382 CBOR-based protocols MUST specify how their decoders handle invalid 1383 and other unexpected data. CBOR-based protocols MAY specify that 1384 they treat arbitrary valid data as unexpected. Encoders for CBOR- 1385 based protocols MUST produce only valid items, that is, the protocol 1386 cannot be designed to make use of invalid items. An encoder can be 1387 capable of encoding as many or as few types of values as is required 1388 by the protocol in which it is used; a decoder can be capable of 1389 understanding as many or as few types of values as is required by the 1390 protocols in which it is used. This lack of restrictions allows CBOR 1391 to be used in extremely constrained environments. 1393 This section discusses some considerations in creating CBOR-based 1394 protocols. With few exceptions, it is advisory only and explicitly 1395 excludes any language from BCP 14 other than words that could be 1396 interpreted as "MAY" in the sense of BCP 14. The exceptions aim at 1397 facilitating interoperability of CBOR-based protocols while making 1398 use of a wide variety of both generic and application-specific 1399 encoders and decoders. 1401 5.1. CBOR in Streaming Applications 1403 In a streaming application, a data stream may be composed of a 1404 sequence of CBOR data items concatenated back-to-back. In such an 1405 environment, the decoder immediately begins decoding a new data item 1406 if data is found after the end of a previous data item. 1408 Not all of the bytes making up a data item may be immediately 1409 available to the decoder; some decoders will buffer additional data 1410 until a complete data item can be presented to the application. 1411 Other decoders can present partial information about a top-level data 1412 item to an application, such as the nested data items that could 1413 already be decoded, or even parts of a byte string that hasn't 1414 completely arrived yet. 1416 Note that some applications and protocols will not want to use 1417 indefinite-length encoding. Using indefinite-length encoding allows 1418 an encoder to not need to marshal all the data for counting, but it 1419 requires a decoder to allocate increasing amounts of memory while 1420 waiting for the end of the item. This might be fine for some 1421 applications but not others. 1423 5.2. Generic Encoders and Decoders 1425 A generic CBOR decoder can decode all well-formed CBOR data and 1426 present them to an application. See Appendix C. 1428 Even though CBOR attempts to minimize these cases, not all well- 1429 formed CBOR data is valid: for example, the encoded text string 1430 "0x62c0ae" does not contain valid UTF-8 and so is not a valid CBOR 1431 item. Also, specific tags may make semantic constraints that may be 1432 violated, such as a bignum tag enclosing another tag, or an instance 1433 of tag number 0 containing a byte string or a text string with 1434 contents that do not match [RFC3339]'s "date-time" production. There 1435 is no requirement that generic encoders and decoders make unnatural 1436 choices for their application interface to enable the processing of 1437 invalid data. Generic encoders and decoders are expected to forward 1438 simple values and tags even if their specific codepoints are not 1439 registered at the time the encoder/decoder is written (Section 5.4). 1441 Generic decoders provide ways to present well-formed CBOR values, 1442 both valid and invalid, to an application. The diagnostic notation 1443 (Section 8) may be used to present well-formed CBOR values to humans. 1445 Generic encoders provide an application interface that allows the 1446 application to specify any well-formed value, including simple values 1447 and tags unknown to the encoder. 1449 5.3. Invalid Items 1451 A well-formed but invalid CBOR data item presents a problem with 1452 interpreting the data encoded in it in the CBOR data model. A CBOR- 1453 based protocol could be specified in several layers, in which the 1454 lower layers don't process the semantics of some of the CBOR data 1455 they forward. These layers can't notice the invalidity in data they 1456 don't process and MUST forward that data as-is. The first layer that 1457 does process the semantics of an invalid CBOR item MUST take one of 1458 two choices: 1460 1. Replace the problematic item with an error marker and continue 1461 with the next item, or 1463 2. Issue an error and stop processing altogether. 1465 A CBOR-based protocol MUST specify which of these options its 1466 decoders take, for each kind of invalid item they might encounter. 1468 Such problems might include: 1470 Duplicate keys in a map: Generic decoders (Section 5.2) make data 1471 available to applications using the native CBOR data model. That 1472 data model includes maps (key-value mappings with unique keys), 1473 not multimaps (key-value mappings where multiple entries can have 1474 the same key). Thus, a generic decoder that gets a CBOR map item 1475 that has duplicate keys will decode to a map with only one 1476 instance of that key, or it might stop processing altogether. On 1477 the other hand, a "streaming decoder" may not even be able to 1478 notice (Section 5.6). 1480 Inadmissible type on the value enclosed by a tag: Tags (Section 3.4) 1481 specify what type of data item is supposed to be enclosed by the 1482 tag; for example, the tags for positive or negative bignums are 1483 supposed to be put on byte strings. A decoder that decodes the 1484 tagged data item into a native representation (a native big 1485 integer in this example) is expected to check the type of the data 1486 item being tagged. Even decoders that don't have such native 1487 representations available in their environment may perform the 1488 check on those tags known to them and react appropriately. 1490 Invalid UTF-8 string: A decoder might or might not want to verify 1491 that the sequence of bytes in a UTF-8 string (major type 3) is 1492 actually valid UTF-8 and react appropriately. 1494 5.4. Handling Unknown Simple Values and Tags 1496 A decoder that comes across a simple value (Section 3.3) that it does 1497 not recognize, such as a value that was added to the IANA registry 1498 after the decoder was deployed or a value that the decoder chose not 1499 to implement, might issue a warning, might stop processing 1500 altogether, might handle the error by making the unknown value 1501 available to the application as such (as is expected of generic 1502 decoders), or take some other type of action. 1504 A decoder that comes across a tag number (Section 3.4) that it does 1505 not recognize, such as a tag number that was added to the IANA 1506 registry after the decoder was deployed or a tag number that the 1507 decoder chose not to implement, might issue a warning, might stop 1508 processing altogether, might handle the error and present the unknown 1509 tag number together with the enclosed data item to the application 1510 (as is expected of generic decoders), might ignore the tag and simply 1511 present the contained data item only to the application, or take some 1512 other type of action. 1514 5.5. Numbers 1516 CBOR-based protocols should take into account that different language 1517 environments pose different restrictions on the range and precision 1518 of numbers that are representable. For example, the JavaScript 1519 number system treats all numbers as floating point, which may result 1520 in silent loss of precision in decoding integers with more than 53 1521 significant bits. A protocol that uses numbers should define its 1522 expectations on the handling of non-trivial numbers in decoders and 1523 receiving applications. 1525 A CBOR-based protocol that includes floating-point numbers can 1526 restrict which of the three formats (half-precision, single- 1527 precision, and double-precision) are to be supported. For an 1528 integer-only application, a protocol may want to completely exclude 1529 the use of floating-point values. 1531 A CBOR-based protocol designed for compactness may want to exclude 1532 specific integer encodings that are longer than necessary for the 1533 application, such as to save the need to implement 64-bit integers. 1534 There is an expectation that encoders will use the most compact 1535 integer representation that can represent a given value. However, a 1536 compact application should accept values that use a longer-than- 1537 needed encoding (such as encoding "0" as 0b000_11001 followed by two 1538 bytes of 0x00) as long as the application can decode an integer of 1539 the given size. 1541 The preferred encoding for a floating-point value is the shortest 1542 floating-point encoding that preserves its value, e.g., 0xf94580 for 1543 the number 5.5, and 0xfa45ad9c00 for the number 5555.5, unless the 1544 CBOR-based protocol specifically excludes the use of the shorter 1545 floating-point encodings. For NaN values, a shorter encoding is 1546 preferred if zero-padding the shorter significand towards the right 1547 reconstitutes the original NaN value (for many applications, the 1548 single NaN encoding 0xf97e00 will suffice). 1550 5.6. Specifying Keys for Maps 1552 The encoding and decoding applications need to agree on what types of 1553 keys are going to be used in maps. In applications that need to 1554 interwork with JSON-based applications, keys probably should be 1555 limited to UTF-8 strings only; otherwise, there has to be a specified 1556 mapping from the other CBOR types to Unicode characters, and this 1557 often leads to implementation errors. In applications where keys are 1558 numeric in nature and numeric ordering of keys is important to the 1559 application, directly using the numbers for the keys is useful. 1561 If multiple types of keys are to be used, consideration should be 1562 given to how these types would be represented in the specific 1563 programming environments that are to be used. For example, in 1564 JavaScript Maps [ECMA262], a key of integer 1 cannot be distinguished 1565 from a key of floating-point 1.0. This means that, if integer keys 1566 are used, the protocol needs to avoid use of floating-point keys the 1567 values of which happen to be integer numbers in the same map. 1569 Decoders that deliver data items nested within a CBOR data item 1570 immediately on decoding them ("streaming decoders") often do not keep 1571 the state that is necessary to ascertain uniqueness of a key in a 1572 map. Similarly, an encoder that can start encoding data items before 1573 the enclosing data item is completely available ("streaming encoder") 1574 may want to reduce its overhead significantly by relying on its data 1575 source to maintain uniqueness. 1577 A CBOR-based protocol MUST define what to do when a receiving 1578 application does see multiple identical keys in a map. The resulting 1579 rule in the protocol MUST respect the CBOR data model: it cannot 1580 prescribe a specific handling of the entries with the identical keys, 1581 except that it might have a rule that having identical keys in a map 1582 indicates a malformed map and that the decoder has to stop with an 1583 error. Duplicate keys are also prohibited by CBOR decoders that are 1584 using strict mode (Section 5.8). 1586 The CBOR data model for maps does not allow ascribing semantics to 1587 the order of the key/value pairs in the map representation. Thus, a 1588 CBOR-based protocol MUST NOT specify that changing the key/value pair 1589 order in a map would change the semantics, except to specify that 1590 some, orders are disallowed, for example where they would not meet 1591 the requirements of a deterministic encoding (Section 4.2). (Any 1592 secondary effects of map ordering such as on timing, cache usage, and 1593 other potential side channels are not considered part of the 1594 semantics but may be enough reason on its own for a protocol to 1595 require a deterministic encoding format.) 1597 Applications for constrained devices that have maps with 24 or fewer 1598 frequently used keys should consider using small integers (and those 1599 with up to 48 frequently used keys should consider also using small 1600 negative integers) because the keys can then be encoded in a single 1601 byte. 1603 5.6.1. Equivalence of Keys 1605 The specific data model applying to a CBOR data item is used to 1606 determine whether keys occurring in maps are duplicates or distinct. 1608 At the generic data model level, numerically equivalent integer and 1609 floating-point values are distinct from each other, as they are from 1610 the various big numbers (Tags 2 to 5). Similarly, text strings are 1611 distinct from byte strings, even if composed of the same bytes. A 1612 tagged value is distinct from an untagged value or from a value 1613 tagged with a different tag. 1615 Within each of these groups, numeric values are distinct unless they 1616 are numerically equal (specifically, -0.0 is equal to 0.0); for the 1617 purpose of map key equivalence, NaN (not a number) values are 1618 equivalent if they have the same significand after zero-extending 1619 both significands at the right to 64 bits. 1621 (Byte and text) strings are compared byte by byte, arrays element by 1622 element, and are equal if they have the same number of bytes/elements 1623 and the same values at the same positions. Two maps are equal if 1624 they have the same set of pairs regardless of their order; pairs are 1625 equal if both the key and value are equal. 1627 Tagged values are equal if both the tag number and the enclosed item 1628 are equal. Simple values are equal if they simply have the same 1629 value. Nothing else is equal in the generic data model, a simple 1630 value 2 is not equivalent to an integer 2 and an array is never 1631 equivalent to a map. 1633 As discussed in Section 2.2, specific data models can make values 1634 equivalent for the purpose of comparing map keys that are distinct in 1635 the generic data model. Note that this implies that a generic 1636 decoder may deliver a decoded map to an application that needs to be 1637 checked for duplicate map keys by that application (alternatively, 1638 the decoder may provide a programming interface to perform this 1639 service for the application). Specific data models cannot 1640 distinguish values for map keys that are equal for this purpose at 1641 the generic data model level. 1643 5.7. Undefined Values 1645 In some CBOR-based protocols, the simple value (Section 3.3) of 1646 Undefined might be used by an encoder as a substitute for a data item 1647 with an encoding problem, in order to allow the rest of the enclosing 1648 data items to be encoded without harm. 1650 5.8. Strict Decoding Mode 1652 Some areas of application of CBOR do not require deterministic 1653 encoding (Section 4.2) but may require that different decoders reach 1654 the same (semantically equivalent) results, even in the presence of 1655 potentially malicious data. This can be required if one application 1656 (such as a firewall or other protecting entity) makes a decision 1657 based on the data that another application, which independently 1658 decodes the data, relies on. 1660 Normally, it is the responsibility of the sender to avoid ambiguously 1661 decodable data. However, the sender might be an attacker specially 1662 making up CBOR data such that it will be interpreted differently by 1663 different decoders in an attempt to exploit that as a vulnerability. 1664 Generic decoders used in applications where this might be a problem 1665 need to support a strict mode in which it is also the responsibility 1666 of the receiver to reject ambiguously decodable data. It is expected 1667 that firewalls and other security systems that decode CBOR will only 1668 decode in strict mode. 1670 A decoder in strict mode will reliably reject any data that could be 1671 interpreted by other decoders in different ways. It will expend the 1672 effort to reliably detect invalid data items (Section 5.3). For 1673 example, a strict decoder needs to have an API that reports an error 1674 (and does not return data) for a CBOR data item that contains any of 1675 the following: 1677 o a map (major type 5) that has more than one entry with the same 1678 key 1680 o a tag that is used on a data item of the incorrect type 1682 o a data item that is incorrectly formatted for the type given to 1683 it, such as invalid UTF-8 or data that cannot be interpreted with 1684 the specific tag number that it has been tagged with 1686 A decoder in strict mode can do one of two things when it encounters 1687 a tag number or simple value that it does not recognize: 1689 o It can report an error (and not return data). 1691 o It can emit the unknown item (type, value, and, for tags, the 1692 decoded tagged data item) to the application calling the decoder 1693 with an indication that the decoder did not recognize that tag 1694 number or simple value. 1696 The latter approach, which is also appropriate for non-strict 1697 decoders, supports forward compatibility with newly registered tags 1698 and simple values without the requirement to update the encoder at 1699 the same time as the calling application. (For this, the API for the 1700 decoder needs to have a way to mark unknown items so that the calling 1701 application can handle them in a manner appropriate for the program.) 1702 Since some of this processing may have an appreciable cost (in 1703 particular with duplicate detection for maps), support of strict mode 1704 is not a requirement placed on all CBOR decoders. 1706 Some encoders will rely on their applications to provide input data 1707 in such a way that unambiguously decodable CBOR results. A generic 1708 encoder also may want to provide a strict mode where it reliably 1709 limits its output to unambiguously decodable CBOR, independent of 1710 whether or not its application is providing API-conformant data. 1712 6. Converting Data between CBOR and JSON 1714 This section gives non-normative advice about converting between CBOR 1715 and JSON. Implementations of converters are free to use whichever 1716 advice here they want. 1718 It is worth noting that a JSON text is a sequence of characters, not 1719 an encoded sequence of bytes, while a CBOR data item consists of 1720 bytes, not characters. 1722 6.1. Converting from CBOR to JSON 1724 Most of the types in CBOR have direct analogs in JSON. However, some 1725 do not, and someone implementing a CBOR-to-JSON converter has to 1726 consider what to do in those cases. The following non-normative 1727 advice deals with these by converting them to a single substitute 1728 value, such as a JSON null. 1730 o An integer (major type 0 or 1) becomes a JSON number. 1732 o A byte string (major type 2) that is not embedded in a tag that 1733 specifies a proposed encoding is encoded in base64url without 1734 padding and becomes a JSON string. 1736 o A UTF-8 string (major type 3) becomes a JSON string. Note that 1737 JSON requires escaping certain characters ([RFC8259], Section 7): 1738 quotation mark (U+0022), reverse solidus (U+005C), and the "C0 1739 control characters" (U+0000 through U+001F). All other characters 1740 are copied unchanged into the JSON UTF-8 string. 1742 o An array (major type 4) becomes a JSON array. 1744 o A map (major type 5) becomes a JSON object. This is possible 1745 directly only if all keys are UTF-8 strings. A converter might 1746 also convert other keys into UTF-8 strings (such as by converting 1747 integers into strings containing their decimal representation); 1748 however, doing so introduces a danger of key collision. Note also 1749 that, if tags on UTF-8 strings are ignored as proposed below, this 1750 will cause a key collision if the tags are different but the 1751 strings are the same. 1753 o False (major type 7, additional information 20) becomes a JSON 1754 false. 1756 o True (major type 7, additional information 21) becomes a JSON 1757 true. 1759 o Null (major type 7, additional information 22) becomes a JSON 1760 null. 1762 o A floating-point value (major type 7, additional information 25 1763 through 27) becomes a JSON number if it is finite (that is, it can 1764 be represented in a JSON number); if the value is non-finite (NaN, 1765 or positive or negative Infinity), it is represented by the 1766 substitute value. 1768 o Any other simple value (major type 7, any additional information 1769 value not yet discussed) is represented by the substitute value. 1771 o A bignum (major type 6, tag number 2 or 3) is represented by 1772 encoding its byte string in base64url without padding and becomes 1773 a JSON string. For tag number 3 (negative bignum), a "~" (ASCII 1774 tilde) is inserted before the base-encoded value. (The conversion 1775 to a binary blob instead of a number is to prevent a likely 1776 numeric overflow for the JSON decoder.) 1778 o A byte string with an encoding hint (major type 6, tag number 21 1779 through 23) is encoded as described and becomes a JSON string. 1781 o For all other tags (major type 6, any other tag number), the 1782 enclosed CBOR item is represented as a JSON value; the tag number 1783 is ignored. 1785 o Indefinite-length items are made definite before conversion. 1787 6.2. Converting from JSON to CBOR 1789 All JSON values, once decoded, directly map into one or more CBOR 1790 values. As with any kind of CBOR generation, decisions have to be 1791 made with respect to number representation. In a suggested 1792 conversion: 1794 o JSON numbers without fractional parts (integer numbers) are 1795 represented as integers (major types 0 and 1, possibly major type 1796 6 tag number 2 and 3), choosing the shortest form; integers longer 1797 than an implementation-defined threshold (which is usually either 1798 32 or 64 bits) may instead be represented as floating-point 1799 values. (If the JSON was generated from a JavaScript 1800 implementation, its precision is already limited to 53 bits 1801 maximum.) 1803 o Numbers with fractional parts are represented as floating-point 1804 values. Preferably, the shortest exact floating-point 1805 representation is used; for instance, 1.5 is represented in a 1806 16-bit floating-point value (not all implementations will be 1807 capable of efficiently finding the minimum form, though). There 1808 may be an implementation-defined limit to the precision that will 1809 affect the precision of the represented values. Decimal 1810 representation should only be used if that is specified in a 1811 protocol. 1813 CBOR has been designed to generally provide a more compact encoding 1814 than JSON. One implementation strategy that might come to mind is to 1815 perform a JSON-to-CBOR encoding in place in a single buffer. This 1816 strategy would need to carefully consider a number of pathological 1817 cases, such as that some strings represented with no or very few 1818 escapes and longer (or much longer) than 255 bytes may expand when 1819 encoded as UTF-8 strings in CBOR. Similarly, a few of the binary 1820 floating-point representations might cause expansion from some short 1821 decimal representations (1.1, 1e9) in JSON. This may be hard to get 1822 right, and any ensuing vulnerabilities may be exploited by an 1823 attacker. 1825 7. Future Evolution of CBOR 1827 Successful protocols evolve over time. New ideas appear, 1828 implementation platforms improve, related protocols are developed and 1829 evolve, and new requirements from applications and protocols are 1830 added. Facilitating protocol evolution is therefore an important 1831 design consideration for any protocol development. 1833 For protocols that will use CBOR, CBOR provides some useful 1834 mechanisms to facilitate their evolution. Best practices for this 1835 are well known, particularly from JSON format development of JSON- 1836 based protocols. Therefore, such best practices are outside the 1837 scope of this specification. 1839 However, facilitating the evolution of CBOR itself is very well 1840 within its scope. CBOR is designed to both provide a stable basis 1841 for development of CBOR-based protocols and to be able to evolve. 1842 Since a successful protocol may live for decades, CBOR needs to be 1843 designed for decades of use and evolution. This section provides 1844 some guidance for the evolution of CBOR. It is necessarily more 1845 subjective than other parts of this document. It is also necessarily 1846 incomplete, lest it turn into a textbook on protocol development. 1848 7.1. Extension Points 1850 In a protocol design, opportunities for evolution are often included 1851 in the form of extension points. For example, there may be a 1852 codepoint space that is not fully allocated from the outset, and the 1853 protocol is designed to tolerate and embrace implementations that 1854 start using more codepoints than initially allocated. 1856 Sizing the codepoint space may be difficult because the range 1857 required may be hard to predict. An attempt should be made to make 1858 the codepoint space large enough so that it can slowly be filled over 1859 the intended lifetime of the protocol. 1861 CBOR has three major extension points: 1863 o the "simple" space (values in major type 7). Of the 24 efficient 1864 (and 224 slightly less efficient) values, only a small number have 1865 been allocated. Implementations receiving an unknown simple data 1866 item may be able to process it as such, given that the structure 1867 of the value is indeed simple. The IANA registry in Section 9.1 1868 is the appropriate way to address the extensibility of this 1869 codepoint space. 1871 o the "tag" space (values in major type 6). Again, only a small 1872 part of the codepoint space has been allocated, and the space is 1873 abundant (although the early numbers are more efficient than the 1874 later ones). Implementations receiving an unknown tag number can 1875 choose to simply ignore it or to process it as an unknown tag 1876 number wrapping the enclosed data item. The IANA registry in 1877 Section 9.2 is the appropriate way to address the extensibility of 1878 this codepoint space. 1880 o the "additional information" space. An implementation receiving 1881 an unknown additional information value has no way to continue 1882 decoding, so allocating codepoints to this space is a major step. 1883 There are also very few codepoints left. 1885 7.2. Curating the Additional Information Space 1887 The human mind is sometimes drawn to filling in little perceived gaps 1888 to make something neat. We expect the remaining gaps in the 1889 codepoint space for the additional information values to be an 1890 attractor for new ideas, just because they are there. 1892 The present specification does not manage the additional information 1893 codepoint space by an IANA registry. Instead, allocations out of 1894 this space can only be done by updating this specification. 1896 For an additional information value of n >= 24, the size of the 1897 additional data typically is 2**(n-24) bytes. Therefore, additional 1898 information values 28 and 29 should be viewed as candidates for 1899 128-bit and 256-bit quantities, in case a need arises to add them to 1900 the protocol. Additional information value 30 is then the only 1901 additional information value available for general allocation, and 1902 there should be a very good reason for allocating it before assigning 1903 it through an update of this protocol. 1905 8. Diagnostic Notation 1907 CBOR is a binary interchange format. To facilitate documentation and 1908 debugging, and in particular to facilitate communication between 1909 entities cooperating in debugging, this section defines a simple 1910 human-readable diagnostic notation. All actual interchange always 1911 happens in the binary format. 1913 Note that this truly is a diagnostic format; it is not meant to be 1914 parsed. Therefore, no formal definition (as in ABNF) is given in 1915 this document. (Implementers looking for a text-based format for 1916 representing CBOR data items in configuration files may also want to 1917 consider YAML [YAML].) 1919 The diagnostic notation is loosely based on JSON as it is defined in 1920 RFC 8259, extending it where needed. 1922 The notation borrows the JSON syntax for numbers (integer and 1923 floating point), True (>true<), False (>false<), Null (>null<), UTF-8 1924 strings, arrays, and maps (maps are called objects in JSON; the 1925 diagnostic notation extends JSON here by allowing any data item in 1926 the key position). Undefined is written >undefined< as in 1927 JavaScript. The non-finite floating-point numbers Infinity, 1928 -Infinity, and NaN are written exactly as in this sentence (this is 1929 also a way they can be written in JavaScript, although JSON does not 1930 allow them). A tagged item is written as an integer number for the 1931 tag, followed by the item in parentheses; for instance, an RFC 3339 1932 (ISO 8601) date could be notated as: 1934 0("2013-03-21T20:04:00Z") 1936 or the equivalent relative time as 1938 1(1363896240) 1940 Byte strings are notated in one of the base encodings, without 1941 padding, enclosed in single quotes, prefixed by >h< for base16, >b32< 1942 for base32, >h32< for base32hex, >b64< for base64 or base64url (the 1943 actual encodings do not overlap, so the string remains unambiguous). 1944 For example, the byte string 0x12345678 could be written h'12345678', 1945 b32'CI2FM6A', or b64'EjRWeA'. 1947 Unassigned simple values are given as "simple()" with the appropriate 1948 integer in the parentheses. For example, "simple(42)" indicates 1949 major type 7, value 42. 1951 8.1. Encoding Indicators 1953 Sometimes it is useful to indicate in the diagnostic notation which 1954 of several alternative representations were actually used; for 1955 example, a data item written >1.5< by a diagnostic decoder might have 1956 been encoded as a half-, single-, or double-precision float. 1958 The convention for encoding indicators is that anything starting with 1959 an underscore and all following characters that are alphanumeric or 1960 underscore, is an encoding indicator, and can be ignored by anyone 1961 not interested in this information. Encoding indicators are always 1962 optional. 1964 A single underscore can be written after the opening brace of a map 1965 or the opening bracket of an array to indicate that the data item was 1966 represented in indefinite-length format. For example, [_ 1, 2] 1967 contains an indicator that an indefinite-length representation was 1968 used to represent the data item [1, 2]. 1970 An underscore followed by a decimal digit n indicates that the 1971 preceding item (or, for arrays and maps, the item starting with the 1972 preceding bracket or brace) was encoded with an additional 1973 information value of 24+n. For example, 1.5_1 is a half-precision 1974 floating-point number, while 1.5_3 is encoded as double precision. 1975 This encoding indicator is not shown in Appendix A. (Note that the 1976 encoding indicator "_" is thus an abbreviation of the full form "_7", 1977 which is not used.) 1979 As a special case, byte and text strings of indefinite length can be 1980 notated in the form (_ h'0123', h'4567') and (_ "foo", "bar"). 1982 9. IANA Considerations 1984 IANA has created two registries for new CBOR values. The registries 1985 are separate, that is, not under an umbrella registry, and follow the 1986 rules in [RFC8126]. IANA has also assigned a new MIME media type and 1987 an associated Constrained Application Protocol (CoAP) Content-Format 1988 entry. 1990 9.1. Simple Values Registry 1992 IANA has created the "Concise Binary Object Representation (CBOR) 1993 Simple Values" registry at [IANA.cbor-simple-values]. The initial 1994 values are shown in Table 3. 1996 New entries in the range 0 to 19 are assigned by Standards Action. 1997 It is suggested that these Standards Actions allocate values starting 1998 with the number 16 in order to reserve the lower numbers for 1999 contiguous blocks (if any). 2001 New entries in the range 32 to 255 are assigned by Specification 2002 Required. 2004 9.2. Tags Registry 2006 IANA has created the "Concise Binary Object Representation (CBOR) 2007 Tags" registry at [IANA.cbor-tags]. The tags that were defined in 2008 [RFC7049] are described in detail in Section 3.4, but other tags have 2009 already been defined. 2011 New entries in the range 0 to 23 are assigned by Standards Action. 2012 New entries in the range 24 to 255 are assigned by Specification 2013 Required. New entries in the range 256 to 18446744073709551615 are 2014 assigned by First Come First Served. The template for registration 2015 requests is: 2017 o Data item 2019 o Semantics (short form) 2021 In addition, First Come First Served requests should include: 2023 o Point of contact 2025 o Description of semantics (URL) - This description is optional; the 2026 URL can point to something like an Internet-Draft or a web page. 2028 9.3. Media Type ("MIME Type") 2030 The Internet media type [RFC6838] for a single encoded CBOR data item 2031 is application/cbor. 2033 Type name: application 2034 Subtype name: cbor 2036 Required parameters: n/a 2038 Optional parameters: n/a 2040 Encoding considerations: binary 2042 Security considerations: See Section 10 of this document 2044 Interoperability considerations: n/a 2046 Published specification: This document 2048 Applications that use this media type: None yet, but it is expected 2049 that this format will be deployed in protocols and applications. 2051 Additional information: 2052 Magic number(s): n/a 2053 File extension(s): .cbor 2054 Macintosh file type code(s): n/a 2056 Person & email address to contact for further information: 2057 Carsten Bormann 2058 cabo@tzi.org 2060 Intended usage: COMMON 2062 Restrictions on usage: none 2064 Author: 2065 Carsten Bormann 2067 Change controller: 2068 The IESG 2070 9.4. CoAP Content-Format 2072 Media Type: application/cbor 2074 Encoding: - 2076 Id: 60 2078 Reference: [RFCthis] 2080 9.5. The +cbor Structured Syntax Suffix Registration 2082 Name: Concise Binary Object Representation (CBOR) 2084 +suffix: +cbor 2086 References: [RFCthis] 2088 Encoding Considerations: CBOR is a binary format. 2090 Interoperability Considerations: n/a 2092 Fragment Identifier Considerations: 2093 The syntax and semantics of fragment identifiers specified for 2094 +cbor SHOULD be as specified for "application/cbor". (At 2095 publication of this document, there is no fragment identification 2096 syntax defined for "application/cbor".) 2098 The syntax and semantics for fragment identifiers for a specific 2099 "xxx/yyy+cbor" SHOULD be processed as follows: 2101 For cases defined in +cbor, where the fragment identifier resolves 2102 per the +cbor rules, then process as specified in +cbor. 2104 For cases defined in +cbor, where the fragment identifier does 2105 not resolve per the +cbor rules, then process as specified in 2106 "xxx/yyy+cbor". 2108 For cases not defined in +cbor, then process as specified in 2109 "xxx/yyy+cbor". 2111 Security Considerations: See Section 10 of this document 2113 Contact: 2114 Apps Area Working Group (apps-discuss@ietf.org) 2116 Author/Change Controller: 2117 The Apps Area Working Group. 2118 The IESG has change control over this registration. 2120 10. Security Considerations 2122 A network-facing application can exhibit vulnerabilities in its 2123 processing logic for incoming data. Complex parsers are well known 2124 as a likely source of such vulnerabilities, such as the ability to 2125 remotely crash a node, or even remotely execute arbitrary code on it. 2126 CBOR attempts to narrow the opportunities for introducing such 2127 vulnerabilities by reducing parser complexity, by giving the entire 2128 range of encodable values a meaning where possible. 2130 Because CBOR decoders are often used as a first step in processing 2131 unvalidated input, they need to be fully prepared for all types of 2132 hostile input that may be designed to corrupt, overrun, or achieve 2133 control of the system decoding the CBOR data item. A CBOR decoder 2134 needs to assume that all input may be hostile even if it has been 2135 checked by a firewall, has come over a secure channel such as TLS, is 2136 encrypted or signed, or has come from some other source that is 2137 presumed trusted. 2139 Hostile input may be constructed to overrun buffers, overflow or 2140 underflow integer arithmetic, or cause other decoding disruption. 2141 CBOR data items might have lengths or sizes that are intentionally 2142 extremely large or too short. Resource exhaustion attacks might 2143 attempt to lure a decoder into allocating very big data items 2144 (strings, arrays, maps, or even arbitrary precision numbers) or 2145 exhaust the stack depth by setting up deeply nested items. Decoders 2146 need to have appropriate resource management to mitigate these 2147 attacks. (Items for which very large sizes are given can also 2148 attempt to exploit integer overflow vulnerabilities.) 2150 A CBOR decoder, by definition, only accepts well-formed CBOR; this is 2151 the first step to its robustness. Input that is not well-formed CBOR 2152 causes no further processing from the point where the lack of well- 2153 formedness was detected. If possible, any data decoded up to this 2154 point should have no impact on the application using the CBOR 2155 decoder. 2157 In addition to ascertaining well-formedness, a CBOR decoder might 2158 also perform validity checks on the CBOR data. Alternatively, it can 2159 leave those checks to the application using the decoder. This choice 2160 needs to be clearly documented in the decoder. Beyond the validity 2161 at the CBOR level, an application also needs to ascertain that the 2162 input is in alignment with the application protocol that is 2163 serialized in CBOR. 2165 The input check itself may consume resources. This is usually linear 2166 in the size of the input, which means that an attacker has to spend 2167 resources that are commensurate to the resources spent by the 2168 defender on input validation. Processing for arbitrary-precision 2169 numbers may exceed linear effort. Also, some hash-table 2170 implementations that are used by decoders to build in-memory 2171 representations of maps can be attacked to spend quadratic effort, 2172 unless a secret key is employed (see Section 7 of [SIPHASH]). Such 2173 superlinear efforts can be employed by an attacker to exhaust 2174 resources at or before the input validator; they therefore need to be 2175 avoided in a CBOR decoder implementation. Note that Tag number 2176 definitions and their implementations can add security considerations 2177 of this kind; this should then be discussed in the security 2178 considerations of the Tag number definition. 2180 CBOR encoders do not receive input directly from the network and are 2181 thus not directly attackable in the same way as CBOR decoders. 2182 However, CBOR encoders often have an API that takes input from 2183 another level in the implementation and can be attacked through that 2184 API. The design and implementation of that API should assume the 2185 behavior of its caller may be based on hostile input or on coding 2186 mistakes. It should check inputs for buffer overruns, overflow and 2187 underflow of integer arithmetic, and other such errors that are aimed 2188 to disrupt the encoder. 2190 Protocols that are used in a security context should be defined in 2191 such a way that potential multiple interpretations are reliably 2192 reduced to a single interpretation. For example, an attacker could 2193 make use of invalid input such as duplicate keys in maps, or exploit 2194 different precision in processing numbers to make one application 2195 base its decisions on a different interpretation than the one that 2196 will be used by a second application. To facilitate consistent 2197 interpretation, encoder and decoder implementations used in such 2198 contexts should provide at least one strict mode of operation 2199 (Section 5.8). 2201 11. References 2203 11.1. Normative References 2205 [ECMA262] Ecma International, "ECMAScript 2018 Language 2206 Specification", ECMA Standard ECMA-262, 9th Edition, June 2207 2018, . 2211 [IEEE754] IEEE, "IEEE Standard for Floating-Point Arithmetic", IEEE 2212 Std 754-2008. 2214 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 2215 Extensions (MIME) Part One: Format of Internet Message 2216 Bodies", RFC 2045, DOI 10.17487/RFC2045, November 1996, 2217 . 2219 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2220 Requirement Levels", BCP 14, RFC 2119, 2221 DOI 10.17487/RFC2119, March 1997, 2222 . 2224 [RFC3339] Klyne, G. and C. Newman, "Date and Time on the Internet: 2225 Timestamps", RFC 3339, DOI 10.17487/RFC3339, July 2002, 2226 . 2228 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2229 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 2230 2003, . 2232 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 2233 Resource Identifier (URI): Generic Syntax", STD 66, 2234 RFC 3986, DOI 10.17487/RFC3986, January 2005, 2235 . 2237 [RFC4287] Nottingham, M., Ed. and R. Sayre, Ed., "The Atom 2238 Syndication Format", RFC 4287, DOI 10.17487/RFC4287, 2239 December 2005, . 2241 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 2242 Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, 2243 . 2245 [RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for 2246 Writing an IANA Considerations Section in RFCs", BCP 26, 2247 RFC 8126, DOI 10.17487/RFC8126, June 2017, 2248 . 2250 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2251 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 2252 May 2017, . 2254 [TIME_T] The Open Group Base Specifications, "Vol. 1: Base 2255 Definitions, Issue 7", Section 4.15 'Seconds Since the 2256 Epoch', IEEE Std 1003.1, 2013 Edition, 2013, 2257 . 2260 11.2. Informative References 2262 [ASN.1] International Telecommunication Union, "Information 2263 Technology -- ASN.1 encoding rules: Specification of Basic 2264 Encoding Rules (BER), Canonical Encoding Rules (CER) and 2265 Distinguished Encoding Rules (DER)", ITU-T Recommendation 2266 X.690, 1994. 2268 [BSON] Various, "BSON - Binary JSON", 2013, 2269 . 2271 [IANA.cbor-simple-values] 2272 IANA, "Concise Binary Object Representation (CBOR) Simple 2273 Values", 2274 . 2276 [IANA.cbor-tags] 2277 IANA, "Concise Binary Object Representation (CBOR) Tags", 2278 . 2280 [MessagePack] 2281 Furuhashi, S., "MessagePack", 2013, . 2283 [PCRE] Ho, A., "PCRE - Perl Compatible Regular Expressions", 2284 2018, . 2286 [RFC0713] Haverty, J., "MSDTP-Message Services Data Transmission 2287 Protocol", RFC 713, DOI 10.17487/RFC0713, April 1976, 2288 . 2290 [RFC6838] Freed, N., Klensin, J., and T. Hansen, "Media Type 2291 Specifications and Registration Procedures", BCP 13, 2292 RFC 6838, DOI 10.17487/RFC6838, January 2013, 2293 . 2295 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 2296 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 2297 October 2013, . 2299 [RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for 2300 Constrained-Node Networks", RFC 7228, 2301 DOI 10.17487/RFC7228, May 2014, 2302 . 2304 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 2305 Interchange Format", STD 90, RFC 8259, 2306 DOI 10.17487/RFC8259, December 2017, 2307 . 2309 [SIPHASH] Aumasson, J. and D. Bernstein, "SipHash: A Fast Short- 2310 Input PRF", Lecture Notes in Computer Science pp. 489-508, 2311 DOI 10.1007/978-3-642-34931-7_28, 2012. 2313 [YAML] Ben-Kiki, O., Evans, C., and I. Net, "YAML Ain't Markup 2314 Language (YAML[TM]) Version 1.2", 3rd Edition, October 2315 2009, . 2317 Appendix A. Examples 2319 The following table provides some CBOR-encoded values in hexadecimal 2320 (right column), together with diagnostic notation for these values 2321 (left column). Note that the string "\u00fc" is one form of 2322 diagnostic notation for a UTF-8 string containing the single Unicode 2323 character U+00FC, LATIN SMALL LETTER U WITH DIAERESIS (u umlaut). 2324 Similarly, "\u6c34" is a UTF-8 string in diagnostic notation with a 2325 single character U+6C34 (CJK UNIFIED IDEOGRAPH-6C34, often 2326 representing "water"), and "\ud800\udd51" is a UTF-8 string in 2327 diagnostic notation with a single character U+10151 (GREEK ACROPHONIC 2328 ATTIC FIFTY STATERS). (Note that all these single-character strings 2329 could also be represented in native UTF-8 in diagnostic notation, 2330 just not in an ASCII-only specification like the present one.) In 2331 the diagnostic notation provided for bignums, their intended numeric 2332 value is shown as a decimal number (such as 18446744073709551616) 2333 instead of showing a tagged byte string (such as 2334 2(h'010000000000000000')). 2336 +------------------------------+------------------------------------+ 2337 | Diagnostic | Encoded | 2338 +------------------------------+------------------------------------+ 2339 | 0 | 0x00 | 2340 | | | 2341 | 1 | 0x01 | 2342 | | | 2343 | 10 | 0x0a | 2344 | | | 2345 | 23 | 0x17 | 2346 | | | 2347 | 24 | 0x1818 | 2348 | | | 2349 | 25 | 0x1819 | 2350 | | | 2351 | 100 | 0x1864 | 2352 | | | 2353 | 1000 | 0x1903e8 | 2354 | | | 2355 | 1000000 | 0x1a000f4240 | 2356 | | | 2357 | 1000000000000 | 0x1b000000e8d4a51000 | 2358 | | | 2359 | 18446744073709551615 | 0x1bffffffffffffffff | 2360 | | | 2361 | 18446744073709551616 | 0xc249010000000000000000 | 2362 | | | 2363 | -18446744073709551616 | 0x3bffffffffffffffff | 2364 | | | 2365 | -18446744073709551617 | 0xc349010000000000000000 | 2366 | | | 2367 | -1 | 0x20 | 2368 | | | 2369 | -10 | 0x29 | 2370 | | | 2371 | -100 | 0x3863 | 2372 | | | 2373 | -1000 | 0x3903e7 | 2374 | | | 2375 | 0.0 | 0xf90000 | 2376 | | | 2377 | -0.0 | 0xf98000 | 2378 | | | 2379 | 1.0 | 0xf93c00 | 2380 | | | 2381 | 1.1 | 0xfb3ff199999999999a | 2382 | | | 2383 | 1.5 | 0xf93e00 | 2384 | | | 2385 | 65504.0 | 0xf97bff | 2386 | | | 2387 | 100000.0 | 0xfa47c35000 | 2388 | | | 2389 | 3.4028234663852886e+38 | 0xfa7f7fffff | 2390 | | | 2391 | 1.0e+300 | 0xfb7e37e43c8800759c | 2392 | | | 2393 | 5.960464477539063e-8 | 0xf90001 | 2394 | | | 2395 | 0.00006103515625 | 0xf90400 | 2396 | | | 2397 | -4.0 | 0xf9c400 | 2398 | | | 2399 | -4.1 | 0xfbc010666666666666 | 2400 | | | 2401 | Infinity | 0xf97c00 | 2402 | | | 2403 | NaN | 0xf97e00 | 2404 | | | 2405 | -Infinity | 0xf9fc00 | 2406 | | | 2407 | Infinity | 0xfa7f800000 | 2408 | | | 2409 | NaN | 0xfa7fc00000 | 2410 | | | 2411 | -Infinity | 0xfaff800000 | 2412 | | | 2413 | Infinity | 0xfb7ff0000000000000 | 2414 | | | 2415 | NaN | 0xfb7ff8000000000000 | 2416 | | | 2417 | -Infinity | 0xfbfff0000000000000 | 2418 | | | 2419 | false | 0xf4 | 2420 | | | 2421 | true | 0xf5 | 2422 | | | 2423 | null | 0xf6 | 2424 | | | 2425 | undefined | 0xf7 | 2426 | | | 2427 | simple(16) | 0xf0 | 2428 | | | 2429 | simple(255) | 0xf8ff | 2430 | | | 2431 | 0("2013-03-21T20:04:00Z") | 0xc074323031332d30332d32315432303a | 2432 | | 30343a30305a | 2433 | | | 2434 | 1(1363896240) | 0xc11a514b67b0 | 2435 | | | 2436 | 1(1363896240.5) | 0xc1fb41d452d9ec200000 | 2437 | | | 2438 | 23(h'01020304') | 0xd74401020304 | 2439 | | | 2440 | 24(h'6449455446') | 0xd818456449455446 | 2441 | | | 2442 | 32("http://www.example.com") | 0xd82076687474703a2f2f7777772e6578 | 2443 | | 616d706c652e636f6d | 2444 | | | 2445 | h'' | 0x40 | 2446 | | | 2447 | h'01020304' | 0x4401020304 | 2448 | | | 2449 | "" | 0x60 | 2450 | | | 2451 | "a" | 0x6161 | 2452 | | | 2453 | "IETF" | 0x6449455446 | 2454 | | | 2455 | "\"\\" | 0x62225c | 2456 | | | 2457 | "\u00fc" | 0x62c3bc | 2458 | | | 2459 | "\u6c34" | 0x63e6b0b4 | 2460 | | | 2461 | "\ud800\udd51" | 0x64f0908591 | 2462 | | | 2463 | [] | 0x80 | 2464 | | | 2465 | [1, 2, 3] | 0x83010203 | 2466 | | | 2467 | [1, [2, 3], [4, 5]] | 0x8301820203820405 | 2468 | | | 2469 | [1, 2, 3, 4, 5, 6, 7, 8, 9, | 0x98190102030405060708090a0b0c0d0e | 2470 | 10, 11, 12, 13, 14, 15, 16, | 0f101112131415161718181819 | 2471 | 17, 18, 19, 20, 21, 22, 23, | | 2472 | 24, 25] | | 2473 | | | 2474 | {} | 0xa0 | 2475 | | | 2476 | {1: 2, 3: 4} | 0xa201020304 | 2477 | | | 2478 | {"a": 1, "b": [2, 3]} | 0xa26161016162820203 | 2479 | | | 2480 | ["a", {"b": "c"}] | 0x826161a161626163 | 2481 | | | 2482 | {"a": "A", "b": "B", "c": | 0xa5616161416162614261636143616461 | 2483 | "C", "d": "D", "e": "E"} | 4461656145 | 2484 | | | 2485 | (_ h'0102', h'030405') | 0x5f42010243030405ff | 2486 | | | 2487 | (_ "strea", "ming") | 0x7f657374726561646d696e67ff | 2488 | | | 2489 | [_ ] | 0x9fff | 2490 | | | 2491 | [_ 1, [2, 3], [_ 4, 5]] | 0x9f018202039f0405ffff | 2492 | | | 2493 | [_ 1, [2, 3], [4, 5]] | 0x9f01820203820405ff | 2494 | | | 2495 | [1, [2, 3], [_ 4, 5]] | 0x83018202039f0405ff | 2496 | | | 2497 | [1, [_ 2, 3], [4, 5]] | 0x83019f0203ff820405 | 2498 | | | 2499 | [_ 1, 2, 3, 4, 5, 6, 7, 8, | 0x9f0102030405060708090a0b0c0d0e0f | 2500 | 9, 10, 11, 12, 13, 14, 15, | 101112131415161718181819ff | 2501 | 16, 17, 18, 19, 20, 21, 22, | | 2502 | 23, 24, 25] | | 2503 | | | 2504 | {_ "a": 1, "b": [_ 2, 3]} | 0xbf61610161629f0203ffff | 2505 | | | 2506 | ["a", {_ "b": "c"}] | 0x826161bf61626163ff | 2507 | | | 2508 | {_ "Fun": true, "Amt": -2} | 0xbf6346756ef563416d7421ff | 2509 +------------------------------+------------------------------------+ 2511 Table 5: Examples of Encoded CBOR Data Items 2513 Appendix B. Jump Table 2515 For brevity, this jump table does not show initial bytes that are 2516 reserved for future extension. It also only shows a selection of the 2517 initial bytes that can be used for optional features. (All unsigned 2518 integers are in network byte order.) 2520 +------------+------------------------------------------------------+ 2521 | Byte | Structure/Semantics | 2522 +------------+------------------------------------------------------+ 2523 | 0x00..0x17 | Integer 0x00..0x17 (0..23) | 2524 | | | 2525 | 0x18 | Unsigned integer (one-byte uint8_t follows) | 2526 | | | 2527 | 0x19 | Unsigned integer (two-byte uint16_t follows) | 2528 | | | 2529 | 0x1a | Unsigned integer (four-byte uint32_t follows) | 2530 | | | 2531 | 0x1b | Unsigned integer (eight-byte uint64_t follows) | 2532 | | | 2533 | 0x20..0x37 | Negative integer -1-0x00..-1-0x17 (-1..-24) | 2534 | | | 2535 | 0x38 | Negative integer -1-n (one-byte uint8_t for n | 2536 | | follows) | 2537 | | | 2538 | 0x39 | Negative integer -1-n (two-byte uint16_t for n | 2539 | | follows) | 2540 | | | 2541 | 0x3a | Negative integer -1-n (four-byte uint32_t for n | 2542 | | follows) | 2543 | | | 2544 | 0x3b | Negative integer -1-n (eight-byte uint64_t for n | 2545 | | follows) | 2546 | | | 2547 | 0x40..0x57 | byte string (0x00..0x17 bytes follow) | 2548 | | | 2549 | 0x58 | byte string (one-byte uint8_t for n, and then n | 2550 | | bytes follow) | 2551 | | | 2552 | 0x59 | byte string (two-byte uint16_t for n, and then n | 2553 | | bytes follow) | 2554 | | | 2555 | 0x5a | byte string (four-byte uint32_t for n, and then n | 2556 | | bytes follow) | 2557 | | | 2558 | 0x5b | byte string (eight-byte uint64_t for n, and then n | 2559 | | bytes follow) | 2560 | | | 2561 | 0x5f | byte string, byte strings follow, terminated by | 2562 | | "break" | 2563 | | | 2564 | 0x60..0x77 | UTF-8 string (0x00..0x17 bytes follow) | 2565 | | | 2566 | 0x78 | UTF-8 string (one-byte uint8_t for n, and then n | 2567 | | bytes follow) | 2568 | | | 2569 | 0x79 | UTF-8 string (two-byte uint16_t for n, and then n | 2570 | | bytes follow) | 2571 | | | 2572 | 0x7a | UTF-8 string (four-byte uint32_t for n, and then n | 2573 | | bytes follow) | 2574 | | | 2575 | 0x7b | UTF-8 string (eight-byte uint64_t for n, and then n | 2576 | | bytes follow) | 2577 | | | 2578 | 0x7f | UTF-8 string, UTF-8 strings follow, terminated by | 2579 | | "break" | 2580 | | | 2581 | 0x80..0x97 | array (0x00..0x17 data items follow) | 2582 | | | 2583 | 0x98 | array (one-byte uint8_t for n, and then n data items | 2584 | | follow) | 2585 | | | 2586 | 0x99 | array (two-byte uint16_t for n, and then n data | 2587 | | items follow) | 2588 | | | 2589 | 0x9a | array (four-byte uint32_t for n, and then n data | 2590 | | items follow) | 2591 | | | 2592 | 0x9b | array (eight-byte uint64_t for n, and then n data | 2593 | | items follow) | 2594 | | | 2595 | 0x9f | array, data items follow, terminated by "break" | 2596 | | | 2597 | 0xa0..0xb7 | map (0x00..0x17 pairs of data items follow) | 2598 | | | 2599 | 0xb8 | map (one-byte uint8_t for n, and then n pairs of | 2600 | | data items follow) | 2601 | | | 2602 | 0xb9 | map (two-byte uint16_t for n, and then n pairs of | 2603 | | data items follow) | 2604 | | | 2605 | 0xba | map (four-byte uint32_t for n, and then n pairs of | 2606 | | data items follow) | 2607 | | | 2608 | 0xbb | map (eight-byte uint64_t for n, and then n pairs of | 2609 | | data items follow) | 2610 | | | 2611 | 0xbf | map, pairs of data items follow, terminated by | 2612 | | "break" | 2613 | | | 2614 | 0xc0 | Text-based date/time (data item follows; see | 2615 | | Section 3.4.2) | 2616 | | | 2617 | 0xc1 | Epoch-based date/time (data item follows; see | 2618 | | Section 3.4.3) | 2619 | | | 2620 | 0xc2 | Positive bignum (data item "byte string" follows) | 2621 | | | 2622 | 0xc3 | Negative bignum (data item "byte string" follows) | 2623 | | | 2624 | 0xc4 | Decimal Fraction (data item "array" follows; see | 2625 | | Section 3.4.5) | 2626 | | | 2627 | 0xc5 | Bigfloat (data item "array" follows; see | 2628 | | Section 3.4.5) | 2629 | | | 2630 | 0xc6..0xd4 | (tagged item) | 2631 | | | 2632 | 0xd5..0xd7 | Expected Conversion (data item follows; see | 2633 | | Section 3.4.6.2) | 2634 | | | 2635 | 0xd8..0xdb | (more tagged items, 1/2/4/8 bytes and then a data | 2636 | | item follow) | 2637 | | | 2638 | 0xe0..0xf3 | (simple value) | 2639 | | | 2640 | 0xf4 | False | 2641 | | | 2642 | 0xf5 | True | 2643 | | | 2644 | 0xf6 | Null | 2645 | | | 2646 | 0xf7 | Undefined | 2647 | | | 2648 | 0xf8 | (simple value, one byte follows) | 2649 | | | 2650 | 0xf9 | Half-Precision Float (two-byte IEEE 754) | 2651 | | | 2652 | 0xfa | Single-Precision Float (four-byte IEEE 754) | 2653 | | | 2654 | 0xfb | Double-Precision Float (eight-byte IEEE 754) | 2655 | | | 2656 | 0xff | "break" stop code | 2657 +------------+------------------------------------------------------+ 2659 Table 6: Jump Table for Initial Byte 2661 Appendix C. Pseudocode 2663 The well-formedness of a CBOR item can be checked by the pseudocode 2664 in Figure 1. The data is well-formed if and only if: 2666 o the pseudocode does not "fail"; 2668 o after execution of the pseudocode, no bytes are left in the input 2669 (except in streaming applications) 2671 The pseudocode has the following prerequisites: 2673 o take(n) reads n bytes from the input data and returns them as a 2674 byte string. If n bytes are no longer available, take(n) fails. 2676 o uint() converts a byte string into an unsigned integer by 2677 interpreting the byte string in network byte order. 2679 o Arithmetic works as in C. 2681 o All variables are unsigned integers of sufficient range. 2683 Note that "well_formed" returns the major type for well-formed 2684 definite length items, but 0 for an indefinite length item (or -1 for 2685 a break stop code, only if "breakable" is set). This is used in 2686 "well_formed_indefinite" to ascertain that indefinite length strings 2687 only contain definite length strings as chunks. 2689 well_formed (breakable = false) { 2690 // process initial bytes 2691 ib = uint(take(1)); 2692 mt = ib >> 5; 2693 val = ai = ib & 0x1f; 2694 switch (ai) { 2695 case 24: val = uint(take(1)); break; 2696 case 25: val = uint(take(2)); break; 2697 case 26: val = uint(take(4)); break; 2698 case 27: val = uint(take(8)); break; 2699 case 28: case 29: case 30: fail(); 2700 case 31: 2701 return well_formed_indefinite(mt, breakable); 2702 } 2703 // process content 2704 switch (mt) { 2705 // case 0, 1, 7 do not have content; just use val 2706 case 2: case 3: take(val); break; // bytes/UTF-8 2707 case 4: for (i = 0; i < val; i++) well_formed(); break; 2708 case 5: for (i = 0; i < val*2; i++) well_formed(); break; 2709 case 6: well_formed(); break; // 1 embedded data item 2710 case 7: if (ai == 24 && val < 32) fail(); // bad simple 2711 } 2712 return mt; // finite data item 2713 } 2715 well_formed_indefinite(mt, breakable) { 2716 switch (mt) { 2717 case 2: case 3: 2718 while ((it = well_formed(true)) != -1) 2719 if (it != mt) // need finite-length chunk 2720 fail(); // of same type 2721 break; 2722 case 4: while (well_formed(true) != -1); break; 2723 case 5: while (well_formed(true) != -1) well_formed(); break; 2724 case 7: 2725 if (breakable) 2726 return -1; // signal break out 2727 else fail(); // no enclosing indefinite 2728 default: fail(); // wrong mt 2729 } 2730 return 0; // no break out 2731 } 2733 Figure 1: Pseudocode for Well-Formedness Check 2735 Note that the remaining complexity of a complete CBOR decoder is 2736 about presenting data that has been decoded to the application in an 2737 appropriate form. 2739 Major types 0 and 1 are designed in such a way that they can be 2740 encoded in C from a signed integer without actually doing an if-then- 2741 else for positive/negative (Figure 2). This uses the fact that 2742 (-1-n), the transformation for major type 1, is the same as ~n 2743 (bitwise complement) in C unsigned arithmetic; ~n can then be 2744 expressed as (-1)^n for the negative case, while 0^n leaves n 2745 unchanged for non-negative. The sign of a number can be converted to 2746 -1 for negative and 0 for non-negative (0 or positive) by arithmetic- 2747 shifting the number by one bit less than the bit length of the number 2748 (for example, by 63 for 64-bit numbers). 2750 void encode_sint(int64_t n) { 2751 uint64t ui = n >> 63; // extend sign to whole length 2752 mt = ui & 0x20; // extract major type 2753 ui ^= n; // complement negatives 2754 if (ui < 24) 2755 *p++ = mt + ui; 2756 else if (ui < 256) { 2757 *p++ = mt + 24; 2758 *p++ = ui; 2759 } else 2760 ... 2762 Figure 2: Pseudocode for Encoding a Signed Integer 2764 Appendix D. Half-Precision 2766 As half-precision floating-point numbers were only added to IEEE 754 2767 in 2008 [IEEE754], today's programming platforms often still only 2768 have limited support for them. It is very easy to include at least 2769 decoding support for them even without such support. An example of a 2770 small decoder for half-precision floating-point numbers in the C 2771 language is shown in Figure 3. A similar program for Python is in 2772 Figure 4; this code assumes that the 2-byte value has already been 2773 decoded as an (unsigned short) integer in network byte order (as 2774 would be done by the pseudocode in Appendix C). 2776 #include 2778 double decode_half(unsigned char *halfp) { 2779 int half = (halfp[0] << 8) + halfp[1]; 2780 int exp = (half >> 10) & 0x1f; 2781 int mant = half & 0x3ff; 2782 double val; 2783 if (exp == 0) val = ldexp(mant, -24); 2784 else if (exp != 31) val = ldexp(mant + 1024, exp - 25); 2785 else val = mant == 0 ? INFINITY : NAN; 2786 return half & 0x8000 ? -val : val; 2787 } 2789 Figure 3: C Code for a Half-Precision Decoder 2791 import struct 2792 from math import ldexp 2794 def decode_single(single): 2795 return struct.unpack("!f", struct.pack("!I", single))[0] 2797 def decode_half(half): 2798 valu = (half & 0x7fff) << 13 | (half & 0x8000) << 16 2799 if ((half & 0x7c00) != 0x7c00): 2800 return ldexp(decode_single(valu), 112) 2801 return decode_single(valu | 0x7f800000) 2803 Figure 4: Python Code for a Half-Precision Decoder 2805 Appendix E. Comparison of Other Binary Formats to CBOR's Design 2806 Objectives 2808 The proposal for CBOR follows a history of binary formats that is as 2809 long as the history of computers themselves. Different formats have 2810 had different objectives. In most cases, the objectives of the 2811 format were never stated, although they can sometimes be implied by 2812 the context where the format was first used. Some formats were meant 2813 to be universally usable, although history has proven that no binary 2814 format meets the needs of all protocols and applications. 2816 CBOR differs from many of these formats due to it starting with a set 2817 of objectives and attempting to meet just those. This section 2818 compares a few of the dozens of formats with CBOR's objectives in 2819 order to help the reader decide if they want to use CBOR or a 2820 different format for a particular protocol or application. 2822 Note that the discussion here is not meant to be a criticism of any 2823 format: to the best of our knowledge, no format before CBOR was meant 2824 to cover CBOR's objectives in the priority we have assigned them. A 2825 brief recap of the objectives from Section 1.1 is: 2827 1. unambiguous encoding of most common data formats from Internet 2828 standards 2830 2. code compactness for encoder or decoder 2832 3. no schema description needed 2834 4. reasonably compact serialization 2836 5. applicability to constrained and unconstrained applications 2838 6. good JSON conversion 2840 7. extensibility 2842 E.1. ASN.1 DER, BER, and PER 2844 [ASN.1] has many serializations. In the IETF, DER and BER are the 2845 most common. The serialized output is not particularly compact for 2846 many items, and the code needed to decode numeric items can be 2847 complex on a constrained device. 2849 Few (if any) IETF protocols have adopted one of the several variants 2850 of Packed Encoding Rules (PER). There could be many reasons for 2851 this, but one that is commonly stated is that PER makes use of the 2852 schema even for parsing the surface structure of the data stream, 2853 requiring significant tool support. There are different versions of 2854 the ASN.1 schema language in use, which has also hampered adoption. 2856 E.2. MessagePack 2858 [MessagePack] is a concise, widely implemented counted binary 2859 serialization format, similar in many properties to CBOR, although 2860 somewhat less regular. While the data model can be used to represent 2861 JSON data, MessagePack has also been used in many remote procedure 2862 call (RPC) applications and for long-term storage of data. 2864 MessagePack has been essentially stable since it was first published 2865 around 2011; it has not yet had a transition. The evolution of 2866 MessagePack is impeded by an imperative to maintain complete 2867 backwards compatibility with existing stored data, while only few 2868 bytecodes are still available for extension. Repeated requests over 2869 the years from the MessagePack user community to separate out binary 2870 and text strings in the encoding recently have led to an extension 2871 proposal that would leave MessagePack's "raw" data ambiguous between 2872 its usages for binary and text data. The extension mechanism for 2873 MessagePack remains unclear. 2875 E.3. BSON 2877 [BSON] is a data format that was developed for the storage of JSON- 2878 like maps (JSON objects) in the MongoDB database. Its major 2879 distinguishing feature is the capability for in-place update, which 2880 prevents a compact representation. BSON uses a counted 2881 representation except for map keys, which are null-byte terminated. 2882 While BSON can be used for the representation of JSON-like objects on 2883 the wire, its specification is dominated by the requirements of the 2884 database application and has become somewhat baroque. The status of 2885 how BSON extensions will be implemented remains unclear. 2887 E.4. MSDTP: RFC 713 2889 Message Services Data Transmission (MSDTP) is a very early example of 2890 a compact message format; it is described in [RFC0713], written in 2891 1976. It is included here for its historical value, not because it 2892 was ever widely used. 2894 E.5. Conciseness on the Wire 2896 While CBOR's design objective of code compactness for encoders and 2897 decoders is a higher priority than its objective of conciseness on 2898 the wire, many people focus on the wire size. Table 7 shows some 2899 encoding examples for the simple nested array [1, [2, 3]]; where some 2900 form of indefinite-length encoding is supported by the encoding, 2901 [_ 1, [2, 3]] (indefinite length on the outer array) is also shown. 2903 +-------------+--------------------------+--------------------------+ 2904 | Format | [1, [2, 3]] | [_ 1, [2, 3]] | 2905 +-------------+--------------------------+--------------------------+ 2906 | RFC 713 | c2 05 81 c2 02 82 83 | | 2907 | | | | 2908 | ASN.1 BER | 30 0b 02 01 01 30 06 02 | 30 80 02 01 01 30 06 02 | 2909 | | 01 02 02 01 03 | 01 02 02 01 03 00 00 | 2910 | | | | 2911 | MessagePack | 92 01 92 02 03 | | 2912 | | | | 2913 | BSON | 22 00 00 00 10 30 00 01 | | 2914 | | 00 00 00 04 31 00 13 00 | | 2915 | | 00 00 10 30 00 02 00 00 | | 2916 | | 00 10 31 00 03 00 00 00 | | 2917 | | 00 00 | | 2918 | | | | 2919 | CBOR | 82 01 82 02 03 | 9f 01 82 02 03 ff | 2920 +-------------+--------------------------+--------------------------+ 2922 Table 7: Examples for Different Levels of Conciseness 2924 Appendix F. Changes from RFC 7049 2926 The following is a list of known changes from RFC 7049. This list is 2927 non-authoritative. It is meant to help reviewers see the significant 2928 differences. 2930 o Updated reference for [RFC4627] to [RFC8259] in many places 2932 o Updated reference for [CNN-TERMS] to [RFC7228] 2934 o Added a comment to the last example in Section 2.2.1 (added 2935 "Second value") 2937 o Fixed a bug in the example in Section 2.4.2 ("29" -> "49") 2939 o Fixed a bug in the last paragraph of Section 3.6 ("0b000_11101" -> 2940 "0b000_11001") 2942 Acknowledgements 2944 CBOR was inspired by MessagePack. MessagePack was developed and 2945 promoted by Sadayuki Furuhashi ("frsyuki"). This reference to 2946 MessagePack is solely for attribution; CBOR is not intended as a 2947 version of or replacement for MessagePack, as it has different design 2948 goals and requirements. 2950 The need for functionality beyond the original MessagePack 2951 Specification became obvious to many people at about the same time 2952 around the year 2012. BinaryPack is a minor derivation of 2953 MessagePack that was developed by Eric Zhang for the binaryjs 2954 project. A similar, but different, extension was made by Tim Caswell 2955 for his msgpack-js and msgpack-js-browser projects. Many people have 2956 contributed to the discussion about extending MessagePack to separate 2957 text string representation from byte string representation. 2959 The encoding of the additional information in CBOR was inspired by 2960 the encoding of length information designed by Klaus Hartke for CoAP. 2962 This document also incorporates suggestions made by many people, 2963 notably Dan Frost, James Manger, Jeffrey Yaskin, Joe Hildebrand, 2964 Keith Moore, Laurence Lundblade, Matthew Lepinski, Michael 2965 Richardson, Nico Williams, Peter Occil, Phillip Hallam-Baker, Ray 2966 Polk, Tim Bray, Tony Finch, Tony Hansen, and Yaron Sheffer. 2968 Authors' Addresses 2970 Carsten Bormann 2971 Universitaet Bremen TZI 2972 Postfach 330440 2973 D-28359 Bremen 2974 Germany 2976 Phone: +49-421-218-63921 2977 EMail: cabo@tzi.org 2979 Paul Hoffman 2980 ICANN 2982 EMail: paul.hoffman@icann.org