Internet-Draft | CBOR Serialization | July 2025 |
Mahy | Expires 28 January 2026 | [Page] |
This document renames and clarifies the serialization options defined in the CBOR specification and adds one additional serialization option, presenting them concisely and clearly.¶
This note is to be removed before publishing as an RFC.¶
The latest revision of this draft can be found at https://rohanmahy.github.io/cbor-serialization/draft-mahy-cbor-serialization.html. Status information for this document may be found at https://datatracker.ietf.org/doc/draft-mahy-cbor-serialization/.¶
Discussion of this document takes place on the Concise Binary Object Representation Maintenance and Extensions Working Group mailing list (mailto:cbor@ietf.org), which is archived at https://www.ietf.org/mail-archive/web/cbor/current/maillist.html. Subscribe at https://www.ietf.org/mailman/listinfo/cbor/.¶
Source for this draft and an issue tracker can be found at https://github.com/rohanmahy/cbor-serialization.¶
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.¶
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."¶
This Internet-Draft will expire on 28 January 2026.¶
Copyright (c) 2025 IETF Trust and the persons identified as the document authors. All rights reserved.¶
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Revised BSD License.¶
The CBOR specification [RFC8949] allows applications to define their own profiles of CBOR, including creating their own serialization rules. It also defines two specific serialization options ("Preferred Serialization" and "Core Deterministic Encoding") and gives a new name ("Length-First Map Key Ordering") for the serialization described in [RFC7049].¶
The serialization options for CBOR have been a source of confusion both among implementers and inside the IETF community. Some reasons for this confusion include the following.¶
Map ordering recommendations changed between [RFC7049] and [RFC8949].¶
[RFC8949] mixes advice for serialization in application-defined profiles and serializations in the standard in the same section.¶
The non-normative nature of some of the guidance.¶
Ambiguous language such as "preferred" and "might need to" used inside descriptions of the serializations.¶
A large number of terms, some of which share the same initialisms (ex: common deterministic encoding, core deterministic encoding, and CBOR deterministic encoding) or include the name of one of the serializations in the description of other serializations.¶
The verbosity of the descriptions¶
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.¶
This document creates new names for "Preferred Serialization" and "Core Deterministic Encoding" serializations defined in [RFC8949], and defines a third serialization. Each of these serializations builds on the previous serialization. These three serializations are suitable for general use and can be referenced by application profiles and other specifications.¶
Compact Serialization: Uses the most compact size, form, or variant of every CBOR major type, and forbids bigints that can be expressed as integers.¶
Definite Serialization: Includes the requirements of Compact Serialization, but only allows definite-length encoding.¶
Sorted Serialization: Includes the requirements of Definite Serialization, but also sorts map keys according to Section 4.2.1 bullet point 3 of [RFC8949].¶
Applications may require one of these serializations or define their own (either from scratch or based on any of the standard serializations).¶
The Compact Serialization option was defined in [RFC8949], where it was referred to as Preferred Serialization.¶
Below is a summary of the rules for Compact Serialization:¶
CBOR integer and tag types are always expressed using the smallest size representation possible.¶
Unsigned integers smaller than 2^64 or negative integers smaller than -(2^64 + 1) MUST NOT be expressed as bigints. They are encoded using the corresponding integer types instead.¶
The byte containing the major type for definite-length byte strings, text strings, arrays, and maps is always the selected to represent the length using the smallest number of bytes possible.¶
Floating point values are expressed using smallest of the three sizes (16-bits, 32-bits, or 64-bits) which can represent that value. This requirement includes using the smallest representation of NaN values.¶
Floating point numbers which are mathematically integers (ex: 5.0 or -3.0) are expressed as floating point numbers.¶
Floating point negative zero (-0.0) is distinct from floating point positive zero (0.0).¶
Floating point NaN values with payloads are distinct from one another.¶
Unlike for integers, Compact Serialization does not place any restriction on the expression of bigfloats or decimal fractions.¶
This document defines Definite Serialization, which did not exist in [RFC8949]. It includes all the requirements of Compact serialization and adds one more requirement:¶
Indefinite-length encoding is forbidden.¶
This was formerly called "Deterministic Encoding" (which was confusing as the community often described any of these three serializations, and occasionally application-defined profiles, collectively as CBOR Deterministic Encoding, Core Deterministic Encoding, or Common Deterministic; or using the initialism CDE).¶
Ordered Serialization includes all the requirements of Definite Serialization and adds one additional requirement:¶
CBOR maps are sorted bytewise lexicographically by the CBOR Ordered Serialization of their map keys. See Section 4.2.1 of [RFC8949] bullet point 3 for examples of correctly sorted map keys.¶
Note that a CBOR map key can be another map. Therefore, to use ordered serialization, a CBOR map key which contains maps must be processed recursively and itself represented using Ordered Serialization.¶
[RFC7049] defined a form of serialization similar to Ordered Serialization, but which used a different sorting algorithm. It is now referred to as Length-First Map Key Ordering Serialization. Use of Length-First Map Key Ordering Serialization is discouraged.¶
Applications can define their own serialization rules, which may build from any of the three concrete serializations defined in this document, or from none of them.¶
TODO Security¶
This document has no IANA actions.¶
TODO acknowledge.¶