ステータス:
INTERNET STANDARD
廃止:
RFC7049
原文:
RFC 8949
その他の情報:
Datatracker|Info page

RFC 8949

Concise Binary Object Representation (CBOR)

RFC 8949

コンパクトなバイナリーオブジェクト表現(CBOR:Concise Binary Object Representation)

Abstract

概要

The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. These design goals make it different from earlier binary serializations such as ASN.1 and MessagePack.

コンパクトなバイナリーオブジェクト表現(CBOR:Concise Binary Object Representation)は、非常に小さなコードサイズ、かなり小さなメッセージサイズ、およびバージョンネゴシエーションの必要性がない拡張性を可能にするデータ形式です。これらの設計目標により、ASN.1やMessagePackなどの以前のバイナリーシリアル化とは異なります。

This document obsoletes RFC 7049, providing editorial improvements, new details, and errata fixes while keeping full compatibility with the interchange format of RFC 7049. It does not create a new version of the format.

この文書はRFC 7049を廃止し、編集上の改善、新しい詳細、および勘定訂正を提供しながら、RFC 7049の交換形式と完全な互換性を維持します。この文書は、フォーマットの新しいバージョンを作成するものではありません。

This is an Internet Standards Track document.

これは、インターネット標準トラック文書です。

This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841.

この文書は、インターネット技術標準化委員会(IETF)の成果物です。IETFコミュニティの合意を表しており、公開レビューを受け、インターネット技術指導委員会(IESG)によって公開が承認されました。インターネット標準に関する詳細は、RFC 7841のセクション2を参照してください。

Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at https://www.rfc-editor.org/info/rfc8949.

この文書の現在のステータス、正誤表、およびフィードバックの提供方法に関する情報は、https://www.rfc-editor.org/info/rfc8949で入手できます。

Copyright (c) 2020 IETF Trust and the persons identified as the document authors. All rights reserved.

Copyright (c) 2020 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 Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.

この文書は、BCP 78およびIETFドキュメントに関するIETFトラストの法的規定(https://trustee.ietf.org/license-info)にしたがう必要があります。これらの文書をよく確認し、この文書に関するあなたの権利と制限を説明しています。この文書から抽出されたコードコンポーネントには、Trust Legal Provisionsのセクション4.eに記載されているSimplified BSD Licenseのテキストが含まれている必要があり、Simplified BSD Licenseに記載されているように保証なしで提供されます。

There are hundreds of standardized formats for binary representation of structured data (also known as binary serialization formats). Of those, some are for specific domains of information, while others are generalized for arbitrary data. In the IETF, probably the best-known formats in the latter category are ASN.1's BER and DER [ASN.1].

構造化データのバイナリー表現のための標準化されたフォーマットは数百あります(バイナリーシリアル化フォーマットとも呼ばれます)。そのうち、いくつかは特定の情報ドメイン向けであり、他のものは任意のデータに対して一般化されています。IETFでは、後者のカテゴリーでもっともよく知られているフォーマットは、ASN.1のBERおよびDER[ASN.1]です。

The format defined here follows some specific design goals that are not well met by current formats. The underlying data model is an extended version of the JSON data model [RFC8259]. It is important to note that this is not a proposal that the grammar in RFC 8259 be extended in general, since doing so would cause a significant backwards incompatibility with already deployed JSON documents. Instead, this document simply defines its own data model that starts from JSON.

ここで定義されたフォーマットは、現在のフォーマットでは十分に満たされていないいくつかの特定の設計目標にしたがっています。基礎となるデータモデルは、JSONデータモデルの拡張版です[RFC8259]。RFC 8259の文法を一般的に拡張することを提案するものではないことに注意することが重要です。なぜなら、すでに展開されているJSONドキュメントとの間で重大な後方互換性の問題が発生するためです。代わりに、この文書はJSONから始まる独自のデータモデルを定義するだけです。

Appendix E lists some existing binary formats and discusses how well they do or do not fit the design objectives of the Concise Binary Object Representation (CBOR).

Appendix Eでは、既存のバイナリーフォーマットをいくつかリストし、コンパクトなバイナリーオブジェクト表現(CBOR)の設計目標にどの程度適合しているかについて説明しています。

This document obsoletes [RFC7049], providing editorial improvements, new details, and errata fixes while keeping full compatibility with the interchange format of RFC 7049. It does not create a new version of the format.

この文書は、RFC 7049を廃止します。編集上の改善、新しい詳細、および勘定訂正を提供しながら、RFC 7049の交換形式と完全な互換性を維持します。この文書は、フォーマットの新しいバージョンを作成するものではありません。

The objectives of CBOR, roughly in decreasing order of importance, are:

CBORの目的は、おおよそ重要度の低い順に以下のとおりです。

  1. The representation must be able to unambiguously encode most common data formats used in Internet standards.

    • It must represent a reasonable set of basic data types and structures using binary encoding. "Reasonable" here is largely influenced by the capabilities of JSON, with the major addition of binary byte strings. The structures supported are limited to arrays and trees; loops and lattice-style graphs are not supported.
    • There is no requirement that all data formats be uniquely encoded; that is, it is acceptable that the number "7" might be encoded in multiple different ways.
  2. The code for an encoder or decoder must be able to be compact in order to support systems with very limited memory, processor power, and instruction sets.

    • An encoder and a decoder need to be implementable in a very small amount of code (for example, in class 1 constrained nodes as defined in [RFC7228]).
    • The format should use contemporary machine representations of data (for example, not requiring binary-to-decimal conversion).
  3. Data must be able to be decoded without a schema description.

    • Similar to JSON, encoded data should be self-describing so that a generic decoder can be written.
  4. The serialization must be reasonably compact, but data compactness is secondary to code compactness for the encoder and decoder.

    • "Reasonable" here is bounded by JSON as an upper bound in size and by the implementation complexity, which limits the amount of effort that can go into achieving that compactness. Using either general compression schemes or extensive bit-fiddling violates the complexity goals.
  5. The format must be applicable to both constrained nodes and high-volume applications.

    • This means it must be reasonably frugal in CPU usage for both encoding and decoding. This is relevant both for constrained nodes and for potential usage in applications with a very high volume of data.
  6. The format must support all JSON data types for conversion to and from JSON.

    • It must support a reasonable level of conversion as long as the data represented is within the capabilities of JSON. It must be possible to define a unidirectional mapping towards JSON for all types of data.
  7. The format must be extensible, and the extended data must be decodable by earlier decoders.

    • The format is designed for decades of use.
    • The format must support a form of extensibility that allows fallback so that a decoder that does not understand an extension can still decode the message.
    • The format must be able to be extended in the future by later IETF standards.
  1. 表現は、インターネット標準で使用される一般的なデータ形式のほとんどを明確に符号化できる必要があります。

    • バイナリーエンコーディングを使用して、合理的な基本データ型と構造のセットを表現する必要があります。ここでの「合理的」とは、主にJSONの機能に大きく影響を受け、バイナリーバイトストリングの主要な追加を含みます。サポートされる構造は、配列とツリーに限定されており、ループや格子状のグラフはサポートされていません。
    • すべてのデータ形式が一意にエンコードされる必要はありません。つまり、数字の「7」が複数の異なる方法でエンコードされることが許容されます。
  2. エンコーダーまたはデコーダーのコードは、非常に限られたメモリ、プロセッサのパワー、および命令セットを持つシステムをサポートするためにコンパクトである必要があります。

    • エンコーダーまたはデコーダーは、非常に小さなコードで実装できる必要があります(たとえば、[RFC7228]で定義されたクラス1制約ノードで)。
    • フォーマットは、データの現代的なマシン表現を使用する必要があります(たとえば、バイナリーから10進数への変換を必要としない)。
  3. スキーマの説明なしでデータをデコードできる必要があります。

    • JSONと同様に、エンコードされたデータは自己記述的である必要があり、汎用デコーダーを記述できるようにする必要があります。
  4. シリアル化は、比較的コンパクトである必要がありますが、エンコーダーとデコーダーのコードのコンパクトさが優先されます。

    • ここでの「合理的」とは、JSONを上限としたサイズであり、実装の複雑さによっても制限されます。コンパクトさを実現するために投入できる労力が制限されるため、一般的な圧縮スキームや広範なビット操作を使用することは、複雑性の目標に反します。
  5. フォーマットは、制約ノードと高容量アプリケーションの両方に適用できる必要があります。

    • つまり、エンコードとデコードの両方でCPU使用量が比較的少なくなければなりません。これは、制約ノードと非常に高いデータ量のアプリケーションでの使用に関連しています。
  6. フォーマットは、JSONデータ型をすべてサポートし、JSONからの変換およびJSONへの変換を行う必要があります。

    • JSONの機能に大きく影響を受け、表現されたデータがJSONの機能範囲内である限り、合理的な変換レベルをサポートする必要があります。すべてのデータ型に対してJSONへの単方向マッピングを定義することができる必要があります。
  7. フォーマットは拡張可能であり、拡張されたデータは以前のデコーダーでデコードできる必要があります。

    • このフォーマットは、数十年にわたる使用を想定しています。
    • フォーマットは、拡張機能をサポートする必要があり、拡張機能を理解できないデコーダーでもメッセージをデコードできるようにフォールバックすることができる形式をサポートする必要があります。
    • フォーマットは、将来のIETF標準によって拡張できる必要があります。

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.

キーワード「しなければなりません(MUST)」、「してはなりません(MUST NOT)」、 「要求されています(REQUIRED)」、 「することになります(SHALL)」、「することはありません(SHALL NOT)」、 「すべきです(SHOULD)」、「すべきではありません(SHOULD NOT)」、 「推奨されます(RECOMMENDED)」、「推奨されません(NOT RECOMMENDED)」、 「してもよいです(MAY)」、「選択できます(OPTIONAL)」は、 BCP 14 [RFC2119] [RFC8174]に記載されているとおりに解釈されるものとします。 ただし、ここに示すようにすべて大文字で表示される場合に限ります。

The term "byte" is used in its now-customary sense as a synonym for "octet". All multi-byte values are encoded in network byte order (that is, most significant byte first, also known as "big-endian").

「バイト(byte)」という用語は、現在の慣習的な意味で「オクテット(octet)」の同義語として使用されます。すべてのマルチバイト値は、ネットワークバイトオーダー(つまり、最上位バイトが先に来る「ビッグエンディアン」とも呼ばれる)でエンコードされます。

This specification makes use of the following terminology:

This specification makes use of the following terminology:

Data item:
A single piece of CBOR data. The structure of a data item may contain zero, one, or more nested data items. The term is used both for the data item in representation format and for the abstract idea that can be derived from that by a decoder; the former can be addressed specifically by using the term "encoded data item".
Decoder:
A process that decodes a well-formed encoded CBOR data item and makes it available to an application. Formally speaking, a decoder contains a parser to break up the input using the syntax rules of CBOR, as well as a semantic processor to prepare the data in a form suitable to the application.
Encoder:
A process that generates the (well-formed) representation format of a CBOR data item from application information.
Data Stream:
A sequence of zero or more data items, not further assembled into a larger containing data item (see [RFC8742] for one application). The independent data items that make up a data stream are sometimes also referred to as "top-level data items".
Well-formed:
A data item that follows the syntactic structure of CBOR. A well-formed data item uses the initial bytes and the byte strings and/or data items that are implied by their values as defined in CBOR and does not include following extraneous data. CBOR decoders by definition only return contents from well-formed data items.
Valid:
A data item that is well-formed and also follows the semantic restrictions that apply to CBOR data items (Section 5.3).
Expected:
Besides its normal English meaning, the term "expected" is used to describe requirements beyond CBOR validity that an application has on its input data. Well-formed (processable at all), valid (checked by a validity-checking generic decoder), and expected (checked by the application) form a hierarchy of layers of acceptability.
Stream decoder:
A process that decodes a data stream and makes each of the data items in the sequence available to an application as they are received.
データアイテム(Data Item):
単一のCBORデータ。データアイテムの構造には、ゼロ、1つ、または複数のネストされたデータアイテムが含まれる場合があります。この用語は、表現形式のデータアイテムと、デコーダーによって得られる抽象的なアイデアの両方に使用されます。前者は「エンコードされたデータアイテム」という用語を使用して特定できます。
デコーダー(Decoder):
ウェルフォームされたエンコードされたCBORデータアイテムをデコードし、アプリケーションで使用できるようにします。形式的には、デコーダーには、CBORの構文規則を使用して入力を分割するパーサーと、アプリケーションに適した形式でデータを準備する意味処理器が含まれます。
エンコーダー(Encoder):
アプリケーション情報からCBORデータアイテムの(ウェルフォームされた)表現形式を生成するプロセス。
データストリーム(Data Stream):
より大きな含まれるデータアイテムにさらに組み立てられていない、ゼロ個以上のデータアイテムのシーケンス(1つのアプリケーションについては、[RFC8742]を参照)。データストリームを構成する独立したデータアイテムは、時に「トップレベルのデータアイテム」とも呼ばれます。
ウェルフォーム(Well-formed):
CBORの構文構造にしたがうデータアイテム。ウェルフォームなデータアイテムは、CBORで定義された初期バイトと、その値によって暗示されるバイト文字列および/またはデータアイテムを使用し、その後の余分なデータを含みません。CBORデコーダーは、定義上、ウェルフォームなデータアイテムからのコンテンツのみを返します。
有効(Valid):
CBORデータアイテムに適用される意味的制限にしたがう、ウェルフォームであるデータアイテム (Section 5.3を参照)。
期待される(Expected):
通常の英語の意味に加えて、「期待される」という用語は、アプリケーションが入力データに対して持つCBORの有効性を超えた要件を説明するために使用されます。ウェルフォーム(処理可能)、有効(有効性チェックを行う汎用デコーダーによってチェックされる)、期待される(アプリケーションによってチェックされる)は、受け入れ可能性のレイヤーの階層を形成します (Section 5.3を参照)。
ストリームデコーダー:
データストリームをデコードし、データアイテムが受信されるたびにアプリケーションで利用可能にします。

Terms and concepts for floating-point values such as Infinity, NaN (not a number), negative zero, and subnormal are defined in [IEEE754].

無限大、NaN(非数)、負のゼロ、および非正規化数などの浮動小数点値に関する用語や概念は、[IEEE754]で定義されています。

Where bit arithmetic or data types are explained, this document uses the notation familiar from the programming language C [C], except that ".." denotes a range that includes both ends given, and superscript notation denotes exponentiation. For example, 2 to the power of 64 is notated: 264. In the plain-text version of this specification, superscript notation is not available and therefore is rendered by a surrogate notation. That notation is not optimized for this RFC; it is unfortunately ambiguous with C's exclusive-or (which is only used in the appendices, which in turn do not use exponentiation) and requires circumspection from the reader of the plain-text version.

ビット演算やデータ型の説明において、本文書ではCプログラミング言語でお馴染みの表記法を使用しています ([C])。ただし、".."は両端を含む範囲を表し、上付き文字は累乗を表します。たとえば、2の64乗は264と表記されます。 この仕様書のプレーンテキスト版では、上付き文字は使用できないため、代替表記でレンダリングされます。この表記法はRFCに最適化されておらず、Cの排他的論理和と曖昧になることがあります(これは付録でのみ使用され、さらに累乗は使用されません)。プレーンテキスト版の読者は注意が必要です。

Examples and pseudocode assume that signed integers use two's complement representation and that right shifts of signed integers perform sign extension; these assumptions are also specified in Sections 6.8.1 (basic.fundamental) and 7.6.7 (expr.shift) of the 2020 version of C++ (currently available as a final draft, [Cplusplus20]).

例と疑似コード 符号付き整数が2の補数表現を使用し、符号付き整数の右シフトが符号拡張することを前提とします。これらの前提条件は、C++の2020年版のセクション6.8.1(basic.fundamental)および7.6.7(expr.shift)でも指定されています(現在、最終ドラフトとして[Cplusplus20]が利用可能です)。

Similar to the "0x" notation for hexadecimal numbers, numbers in binary notation are prefixed with "0b". Underscores can be added to a number solely for readability, so 0b00100001 (0x21) might be written 0b001_00001 to emphasize the desired interpretation of the bits in the byte; in this case, it is split into three bits and five bits. Encoded CBOR data items are sometimes given in the "0x" or "0b" notation; these values are first interpreted as numbers as in C and are then interpreted as byte strings in network byte order, including any leading zero bytes expressed in the notation.

16進数の"0x"表記法にならって、"0b"接頭辞を2進数の表記法として使用します。可読性を向上させるために、数字にアンダースコアを追加することがあります。たとえば、0b00100001 (0x21) は、バイト内のビットの解釈を強調するために、0b001_00001 のように書くことがあります。この場合、3ビットと5ビットに分割されます。エンコードされたCBORデータアイテムは、ときには"0x"または"0b"表記法で与えられます。これらの値は、まずC言語の数値として解釈され、次にネットワークバイトオーダーでバイト文字列として解釈されます。表記法で表される先頭のゼロバイトも含まれます。

Words may be italicized for emphasis; in the plain text form of this specification, this is indicated by surrounding words with underscore characters. Verbatim text (e.g., names from a programming language) may be set in monospace type; in plain text, this is approximated somewhat ambiguously by surrounding the text in double quotes (which also retain their usual meaning).

強調するために、単語を斜体にすることがあります。この仕様書のプレーンテキスト版では、これは単語をアンダースコアで囲むことで示されます。プログラミング言語の名前などの原文のままのテキストは、等幅フォントで表示されることがあります。プレーンテキストでは、テキストを二重引用符で囲むことで、やや曖昧に近似されます(二重引用符は通常の意味も保持します)。

CBOR is explicit about its generic data model, which defines the set of all data items that can be represented in CBOR. Its basic generic data model is extensible by the registration of "simple values" and tags. Applications can then create a subset of the resulting extended generic data model to build their specific data models.

CBORは、CBORで表現できるすべてのデータアイテムのセットを定義するジェネリックデータモデルについて明示的に述べています。基本ジェネリックデータモデルは、「シンプル値」とタグの登録によって拡張可能です。アプリケーションは、その結果の拡張されたジェネリックデータモデルのサブセットを作成して、特定データモデルを構築できます。

Within environments that can represent the data items in the generic data model, generic CBOR encoders and decoders can be implemented (which usually involves defining additional implementation data types for those data items that do not already have a natural representation in the environment). The ability to provide generic encoders and decoders is an explicit design goal of CBOR; however, many applications will provide their own application-specific encoders and/or decoders.

ジェネリックデータモデルでデータアイテムを表現できる環境では、一般的なCBORエンコーダーとデコーダーを実装できます(通常、環境に自然な表現がないデータアイテムに対して追加の実装データ型を定義する必要があります)。一般的なエンコーダーとデコーダーを提供することは、CBORの明示的な設計目標の1つです。ただし、多くのアプリケーションでは、独自のアプリケーション固有のエンコーダーやデコーダーを提供します。

In the basic (unextended) generic data model defined in Section 3, a data item is one of the following:

拡張されていないジェネリックデータモデルでは、Section 3で定義されているように、データアイテムは次のいずれかです。

  • an integer in the range -264..264-1 inclusive
  • a simple value, identified by a number between 0 and 255, but distinct from that number itself
  • a floating-point value, distinct from an integer, out of the set representable by IEEE 754 binary64 (including non-finites) [IEEE754]
  • a sequence of zero or more bytes ("byte string")
  • a sequence of zero or more Unicode code points ("text string")
  • a sequence of zero or more data items ("array")
  • a mapping (mathematical function) from zero or more data items ("keys") each to a data item ("values"), ("map")
  • a tagged data item ("tag"), comprising a tag number (an integer in the range 0..264-1) and the tag content (a data item)
  • -264から264-1までの範囲の整数
  • 単純な値。0から255までの数値で識別されますが、その数値自体とは異なります
  • 浮動小数点値。整数とは区別されます。IEEE 754 binary64 [IEEE754] で表現できない要素を含みます(非有限数を含む)
  • 0バイト以上のバイトのシーケンス(「バイト文字列」)
  • 0個以上のUnicodeコードポイントのシーケンス(「テキスト文字列」)
  • 0個以上のデータアイテムのシーケンス(「配列」)
  • 0個以上のデータアイテム(「キー」)から各々1つのデータアイテム(「値」)への写像(数学的関数)(「マップ」)
  • タグ付きデータアイテム(「タグ」)。タグ番号(0から264-1の範囲の整数)とタグコンテンツ(データアイテム)から構成されます

Note that integer and floating-point values are distinct in this model, even if they have the same numeric value.

このモデルでは、整数値と浮動小数点値は異なることに注意してください。たとえ数値が同じであっても、それらは別々のデータアイテムとして扱われます。

Also note that serialization variants are not visible at the generic data model level. This deliberate absence of visibility includes the number of bytes of the encoded floating-point value. It also includes the choice of encoding for an "argument" (see Section 3) such as the encoding for an integer, the encoding for the length of a text or byte string, the encoding for the number of elements in an array or pairs in a map, or the encoding for a tag number.

また、シリアル化のバリアントは、ジェネリックデータモデルレベルでは見えません。この意図的な不在には、符号付き浮動小数点値のエンコードされたバイト数も含まれます。整数のエンコード、テキストまたはバイト文字列の長さのエンコード、配列内の要素数またはマップ内のペア数のエンコード、またはタグ番号のエンコードなどの「引数」(Section 3を参照)のエンコードの選択肢も含まれます。

This basic generic data model has been extended in this document by the registration of a number of simple values and tag numbers, such as:

基本ジェネリックデータモデルは、このドキュメントによって、次のようなシンプル値とタグ番号の登録によって拡張されています。

  • false, true, null, and undefined (simple values identified by 20..23, Section 3.3)
  • integer and floating-point values with a larger range and precision than the above (tag numbers 2 to 5, Section 3.4)
  • application data types such as a point in time or date/time string defined in RFC 3339 (tag numbers 1 and 0, Section 3.4)
  • falsetruenull、およびundefined(20..23で識別されるシンプル値、Section 3.3
  • 上記よりも大きな範囲と精度を持つ整数値および浮動小数点値 (タグ番号2から5、Section 3.4
  • RFC 3339で定義された時刻または日付/時刻文字列などのアプリケーションデータ型 (タグ番号1および0、Section 3.4

Additional elements of the extended generic data model can be (and have been) defined via the IANA registries created for CBOR. Even if such an extension is unknown to a generic encoder or decoder, data items using that extension can be passed to or from the application by representing them at the application interface within the basic generic data model, i.e., as generic simple values or generic tags.

拡張ジェネリックデータモデルの追加要素は、CBORのために作成されたIANAレジストリを介して定義されることができます(実際に定義されています)。このような拡張が一般的なエンコーダーやデコーダーには不明でも、その拡張を使用するデータアイテムは、基本ジェネリックデータモデル内のジェネリックなシンプル値またはジェネリックなタグとして、アプリケーションインタフェース内で表現することによって、アプリケーションによって受け渡すことができます。

In other words, the basic generic data model is stable as defined in this document, while the extended generic data model expands by the registration of new simple values or tag numbers, but never shrinks.

つまり、基本ジェネリックデータモデルは、このドキュメントで定義されたものとして安定しています。一方、拡張ジェネリックデータモデルは、新しいシンプル値またはタグ番号の登録によって拡張されますが、縮小することはありません。

While there is a strong expectation that generic encoders and decoders can represent false, true, and null (undefined is intentionally omitted) in the form appropriate for their programming environment, the implementation of the data model extensions created by tags is truly optional and a matter of implementation quality.

ジェネリックなエンコーダーやデコーダーが、プログラミング環境に適した形式でfalsetrue、およびnullundefinedは意図的に省略されています)を表現できることが強く期待されていますが、タグによって作成されたデータモデルの拡張の実装は本当にオプションであり、実装品質の問題です。

The specific data model for a CBOR-based protocol usually takes a subset of the extended generic data model and assigns application semantics to the data items within this subset and its components. When documenting such specific data models and specifying the types of data items, it is preferable to identify the types by their generic data model names ("negative integer", "array") instead of referring to aspects of their CBOR representation ("major type 1", "major type 4").

CBORベースのプロトコルの特定データモデルは、通常、拡張ジェネリックデータモデルのサブセットを取り、このサブセットとそのコンポーネント内のデータアイテムにアプリケーションの意味を割り当てます。 このような特定データモデルを文書化し、データアイテムのタイプを指定する場合、CBOR表現の側面(「メジャータイプ1」、「メジャータイプ4」)ではなく、ジェネリックデータモデルの名前(「負の整数」、「配列」)でタイプを識別することが望ましいです。

Specific data models can also specify value equivalency (including values of different types) for the purposes of map keys and encoder freedom. For example, in the generic data model, a valid map MAY have both 0 and 0.0 as keys, and an encoder MUST NOT encode 0.0 as an integer (major type 0, Section 3.1). However, if a specific data model declares that floating-point and integer representations of integral values are equivalent, using both map keys 0 and 0.0 in a single map would be considered duplicates, even while encoded as different major types, and so invalid; and an encoder could encode integral-valued floats as integers or vice versa, perhaps to save encoded bytes.

特定データモデルでは、マップキーとエンコーダーの自由度のために、値の等価性(異なる型の値を含む)を指定できます。たとえば、ジェネリックデータモデルでは、有効なマップには00.0の両方がキーとして含まれる場合があります(MAY)。エンコーダーは0.0を整数(メジャータイプ0、Section 3.1)としてエンコードしてはなりません(MUST NOT)
ただし、特定データモデルが整数値の浮動小数点表現と整数表現を等価と宣言する場合、単一のマップ内で両方のマップキー00.0を使用することは、重複とみなされます。異なるメジャータイプとしてエンコードされていても無効になります。なぜなら、エンコードされたバイトを節約するために、エンコーダーは整数値を持つ浮動小数点数を整数としてエンコードできるためです。その逆を行うこともできます。

A CBOR data item (Section 2) is encoded to or decoded from a byte string carrying a well-formed encoded data item as described in this section. The encoding is summarized in Table 7 in Appendix B, indexed by the initial byte. An encoder MUST produce only well-formed encoded data items. A decoder MUST NOT return a decoded data item when it encounters input that is not a well-formed encoded CBOR data item (this does not detract from the usefulness of diagnostic and recovery tools that might make available some information from a damaged encoded CBOR data item).

このセクションでは、CBORデータアイテム(Section 2)をウェルフォームなバイト文字列へエンコード、もしくはバイト文字列からデコードする方法を説明します。Appendix BTable 7にまとめられているように、エンコーディングは最初のバイトによってインデックス化されています。エンコーダーはウェルフォームなエンコード済みデータアイテムのみを生成しなければなりません(MUST)。デコーダーはウェルフォームでない入力に遭遇した場合、デコード済みデータアイテムを返してはなりません(MUST NOT)。(これは、損傷したエンコード済みCBORデータアイテムから情報を利用可能にする診断回復ツールの有用性を損なうものではありません)。

The initial byte of each encoded data item contains both information about the major type (the high-order 3 bits, described in Section 3.1) and additional information (the low-order 5 bits). With a few exceptions, the additional information's value describes how to load an unsigned integer "argument":

エンコード済みデータアイテムの最初のバイトには、メジャータイプに関する情報(上位3ビット、Section 3.1で説明されています)と追加情報(下位5ビット)の両方が含まれます。いくつかの例外を除いて、追加情報の値は、符号なし整数の「引数」をどのようにロードするかを説明します。

Less than 24:
The argument's value is the value of the additional information.
24, 25, 26, or 27:
The argument's value is held in the following 1, 2, 4, or 8 bytes, respectively, in network byte order. For major type 7 and additional information value 25, 26, 27, these bytes are not used as an integer argument, but as a floating-point value (see Section 3.3).
28, 29, 30:
These values are reserved for future additions to the CBOR format. In the present version of CBOR, the encoded item is not well-formed.
31:
No argument value is derived. If the major type is 0, 1, or 6, the encoded item is not well-formed. For major types 2 to 5, the item's length is indefinite, and for major type 7, the byte does not constitute a data item at all but terminates an indefinite-length item; all are described in Section 3.2.
24未満:
引数の値は、追加情報の値そのものです。
24、25、26、または27:
引数の値は、次の1、2、4、または8バイトに、それぞれネットワークバイトオーダーで保持されます。メジャータイプ7および追加情報値25、26、27の場合、これらのバイトは整数引数として使用されず、浮動小数点値として使用されます(Section 3.3を参照)。
28、29、30:
これらの値は、将来のCBORフォーマットの追加のために予約されています。CBORの現在のバージョンでは、エンコードされたアイテムはウェルフォームではありません。
31:
引数値は導出されません。 メジャータイプが0、1、または6の場合、エンコードされたアイテムはウェルフォームではありません。メジャータイプ2から5の場合、アイテムの長さは不定であり、メジャータイプ7の場合、バイトはデータアイテムを構成せず、不定長アイテムを終了します。これらについてはSection 3.2で説明されています。

The initial byte and any additional bytes consumed to construct the argument are collectively referred to as the head of the data item.

初期バイトと構築に消費される追加バイトは、データアイテムのヘッドとして集合的に参照されます。

The meaning of this argument depends on the major type. For example, in major type 0, the argument is the value of the data item itself (and in major type 1, the value of the data item is computed from the argument); in major type 2 and 3, it gives the length of the string data in bytes that follow; and in major types 4 and 5, it is used to determine the number of data items enclosed.

この引数の意味は、メジャータイプに依存します。 たとえば、メジャータイプ0では、引数はデータアイテム自体の値です(メジャータイプ1では、データアイテムの値は引数から計算されます)。メジャータイプ2および3では、後続する文字列データのバイト数を指定します。メジャータイプ4および5では、囲まれたデータアイテムの数を決定するために使用されます。

If the encoded sequence of bytes ends before the end of a data item, that item is not well-formed. If the encoded sequence of bytes still has bytes remaining after the outermost encoded item is decoded, that encoding is not a single well-formed CBOR item. Depending on the application, the decoder may either treat the encoding as not well-formed or just identify the start of the remaining bytes to the application.

エンコードされたバイト列がデータアイテムの終わりよりも前に終了した場合、そのアイテムはウェルフォームではありません。外側のエンコードされたアイテムがデコードされた後に、バイトが残っている場合、そのエンコードは単一のウェルフォームCBORアイテムではありません。アプリケーションによっては、デコーダーがエンコードをウェルフォームでないとして扱うか、残りのバイトの開始をアプリケーションに識別するだけで済む場合があります。

A CBOR decoder implementation can be based on a jump table with all 256 defined values for the initial byte (Table 7). A decoder in a constrained implementation can instead use the structure of the initial byte and following bytes for more compact code (see Appendix C for a rough impression of how this could look).

CBORデコーダーの実装は、初期バイトのすべての256定義値を持つジャンプテーブルに基づくことができます(Table 7)。制約のある実装のデコーダーは、代わりに初期バイトと後続するバイトの構造をよりコンパクトなコードに使用できます(これがどのように見えるかの大まかな印象については、Appendix Cを参照してください)。

The following lists the major types and the additional information and other bytes associated with the type.

以下は、メジャータイプとタイプに関連する追加情報およびその他のバイトを示しています。

Major type 0:
An unsigned integer in the range 0..264-1 inclusive. The value of the encoded item is the argument itself. For example, the integer 10 is denoted as the one byte 0b000_01010 (major type 0, additional information 10). The integer 500 would be 0b000_11001 (major type 0, additional information 25) followed by the two bytes 0x01f4, which is 500 in decimal.
Major type 1:
A negative integer in the range -264..-1 inclusive. The value of the item is -1 minus the argument. For example, the integer -500 would be 0b001_11001 (major type 1, additional information 25) followed by the two bytes 0x01f3, which is 499 in decimal.
Major type 2:
A byte string. The number of bytes in the string is equal to the argument. For example, a byte string whose length is 5 would have an initial byte of 0b010_00101 (major type 2, additional information 5 for the length), followed by 5 bytes of binary content. A byte string whose length is 500 would have 3 initial bytes of 0b010_11001 (major type 2, additional information 25 to indicate a two-byte length) followed by the two bytes 0x01f4 for a length of 500, followed by 500 bytes of binary content.
Major type 3:
A text string (Section 2) encoded as UTF-8 [RFC3629]. The number of bytes in the string is equal to the argument. A string containing an invalid UTF-8 sequence is well-formed but invalid (Section 1.2). This type is provided for systems that need to interpret or display human-readable text, and allows the differentiation between unstructured bytes and text that has a specified repertoire (that of Unicode) and encoding (UTF-8). In contrast to formats such as JSON, the Unicode characters in this type are never escaped. Thus, a newline character (U+000A) is always represented in a string as the byte 0x0a, and never as the bytes 0x5c6e (the characters "\" and "n") nor as 0x5c7530303061 (the characters "\", "u", "0", "0", "0", and "a").
Major type 4:
An array of data items. In other formats, arrays are also called lists, sequences, or tuples (a "CBOR sequence" is something slightly different, though [RFC8742]). The argument is the number of data items in the array. Items in an array do not need to all be of the same type. For example, an array that contains 10 items of any type would have an initial byte of 0b100_01010 (major type 4, additional information 10 for the length) followed by the 10 remaining items.
Major type 5:
A map of pairs of data items. Maps are also called tables, dictionaries, hashes, or objects (in JSON). A map is comprised of pairs of data items, each pair consisting of a key that is immediately followed by a value. The argument is the number of pairs of data items in the map. For example, a map that contains 9 pairs would have an initial byte of 0b101_01001 (major type 5, additional information 9 for the number of pairs) followed by the 18 remaining items. The first item is the first key, the second item is the first value, the third item is the second key, and so on. Because items in a map come in pairs, their total number is always even: a map that contains an odd number of items (no value data present after the last key data item) is not well-formed. A map that has duplicate keys may be well-formed, but it is not valid, and thus it causes indeterminate decoding; see also Section 5.6.
Major type 6:
A tagged data item ("tag") whose tag number, an integer in the range 0..264-1 inclusive, is the argument and whose enclosed data item (tag content) is the single encoded data item that follows the head. See Section 3.4.
Major type 7:
Floating-point numbers and simple values, as well as the "break" stop code. See Section 3.3.
メジャータイプ0:
0から264-1までの範囲の符号なし整数。エンコードされたアイテムの値は引数自体です。たとえば、整数10は1バイトの0b000_01010(メジャータイプ0、追加情報10)として表されます。整数500は0b000_11001(メジャータイプ0、追加情報25)に続いて、10進数で500を表す2バイトの0x01f4が続きます。
メジャータイプ1:
-264から-1までの範囲の負の整数。アイテムの値は、-1から引数を引いたものです。たとえば、整数-500は0b001_11001(メジャータイプ1、追加情報25)に続いて、10進数で499を表す2バイトの0x01f3が続きます。
メジャータイプ2:
バイト文字列。文字列のバイト数は引数と等しい。たとえば、長さが5のバイト文字列は、初期バイトが0b010_00101(メジャータイプ2、追加情報5で長さを示す)であるバイナリコンテンツの5バイトに続きます。長さが500のバイト文字列は、長さを示すための2バイトの0x01f4に続く3つの初期バイト0b010_11001(メジャータイプ2、追加情報25)を持ち、500バイトのバイナリコンテンツが続きます。
メジャータイプ3:
UTF-8でエンコードされたテキスト文字列(Section 2)。文字列のバイト数は引数と等しい。無効なUTF-8シーケンスを含む文字列は、ウェルフォームではあるが無効である(Section 1.2)。このタイプは、人間が読めるテキストを解釈または表示する必要があるシステム向けに提供され、構造化されていないバイトと、指定されたレパートリー(Unicodeのレパートリー)とエンコーディング(UTF-8)を持つテキストとの区別を可能にします。JSONなどのフォーマットとは異なり、このタイプのUnicode文字はエスケープされません。したがって、改行文字(U+000A)は常にバイト0x0aとして表され、文字"\"と"n"のバイト0x5c6eや、文字"\"、"u"、"0"、"0"、"0"、および"a"のバイト0x5c7530303061として表されることはありません。
メジャータイプ4:
データアイテムの配列。他のフォーマットでは、配列はリスト、シーケンス、またはタプルとも呼ばれます(「CBORシーケンス」は、[RFC8742]でわずかに異なるものです)。 引数は、配列内のデータアイテムの数です。 配列内のアイテムはすべて同じタイプである必要はありません。たとえば、任意のタイプの10個のアイテムを含む配列は、初期バイトが0b100_01010(メジャータイプ4、追加情報10で長さを示す)であることに続き、残りの10個のアイテムが続きます。
メジャータイプ5:
データアイテムのペアのマップ。マップは、テーブル、ディクショナリ、ハッシュ、またはオブジェクト(JSONでは)とも呼ばれます。マップは、キーと値のペアで構成され、各ペアはすぐに値が続くキーで構成されます。引数は、マップ内のデータアイテムのペア数です。たとえば、9つのペアを含むマップは、初期バイトが0b101_01001(メジャータイプ5、追加情報9でペア数を示す)であることに続き、残りの18個のアイテムが続きます。最初のアイテムは最初のキー、2番目のアイテムは最初の値、3番目のアイテムは2番目のキーであり、以降続きます。マップ内のアイテムはペアであるため、その総数は常に偶数です。アイテムの数が奇数であるマップ(最後のキーデータアイテムの後に値データが存在しない場合)はウェルフォームではありません。重複するキーを持つマップはウェルフォームである場合がありますが、有効ではなく、したがって不確定なデコードを引き起こします。詳細については、Section 5.6も参照してください。
メジャータイプ6:
タグ番号が引数であるタグ付きデータアイテム(「タグ」)であり、タグ番号は0から264-1までの範囲の整数であり、タグコンテンツはヘッドに続く単一のエンコードされたデータアイテムです。 Section 3.4を参照してください。
メジャータイプ7:
浮動小数点数と単純な値、および「break」ストップコード。詳細については、Section 3.3を参照してください。

These eight major types lead to a simple table showing which of the 256 possible values for the initial byte of a data item are used (Table 7).

これらの8つのメジャータイプにより、データアイテムの初期バイトの256個の可能な値のうち、どの値が使用されるかを示す簡単な表が作成されます(Table 7)。

In major types 6 and 7, many of the possible values are reserved for future specification. See Section 9 for more information on these values.

メジャータイプ6および7では、多くの可能な値が将来の仕様のために予約されています。これらの値に関する詳細については、Section 9を参照してください。

Table 1 summarizes the major types defined by CBOR, ignoring Section 3.2 for now. The number N in this table stands for the argument.

Table 1は、CBORで定義されたメジャータイプを、Section 3.2を無視してまとめたものです。この表のNは引数を表します。

Table 1: Overview over the Definite-Length Use of CBOR Major Types (N = Argument)
Major Type Meaning Content
0 unsigned integer N -
1 negative integer -1-N -
2 byte string N bytes
3 text string N bytes (UTF-8 text)
4 array N data items (elements)
5 map 2N data items (key/value pairs)
6 tag of number N 1 data item
7 simple/float -
表 1: CBORメジャータイプの定義長使用の概要(N =引数)
メジャータイプ 意味 内容
0 非負整数N -
1 負の整数-1-N -
2 バイト文字列 Nバイト
3 テキスト文字列 Nバイト(UTF-8テキスト)
4 配列 Nデータアイテム(要素)
5 マップ 2Nデータアイテム(キー/値のペア)
6 数値Nのタグ 1データアイテム
7 シンプル/フロート -

Four CBOR items (arrays, maps, byte strings, and text strings) can be encoded with an indefinite length using additional information value 31. This is useful if the encoding of the item needs to begin before the number of items inside the array or map, or the total length of the string, is known. (The ability to start sending a data item before all of it is known is often referred to as "streaming" within that data item.)

配列、マップ、バイト文字列、およびテキスト文字列の4つのCBORアイテムは、追加情報値31を使用して長さを決定せずにエンコードできます。これは、配列またはマップ内のアイテムの数、または文字列の総長がわからない場合に、アイテムのエンコードを開始する必要がある場合に便利です。 (データアイテムのすべてがわかる前にデータアイテムを送信を開始できる能力は、しばしばそのデータアイテム内で「ストリーミング」と呼ばれます。)

Indefinite-length arrays and maps are dealt with differently than indefinite-length strings (byte strings and text strings).

不定長の配列とマップは、不定長の文字列(バイト文字列とテキスト文字列)とは異なる方法で処理されます。

The "break" stop code is encoded with major type 7 and additional information value 31 (0b111_11111). It is not itself a data item: it is just a syntactic feature to close an indefinite-length item.

「break」ストップコードは、メジャータイプ7および追加情報値31(0b111_11111)でエンコードされます。それ自体はデータアイテムではありません。不定長アイテムを閉じるための構文的な機能です。

If the "break" stop code appears where a data item is expected, other than directly inside an indefinite-length string, array, or map -- for example, directly inside a definite-length array or map -- the enclosing item is not well-formed.

データアイテムが期待される場所で「break」ストップコードが現れた場合、不定長文字列、配列、またはマップの直接内部以外の場所で(たとえば、定義済み長の配列またはマップの直接内部でない場合)、囲んでいるアイテムはウェルフォームではありません。

Indefinite-length arrays and maps are represented using their major type with the additional information value of 31, followed by an arbitrary-length sequence of zero or more items for an array or key/value pairs for a map, followed by the "break" stop code (Section 3.2.1). In other words, indefinite-length arrays and maps look identical to other arrays and maps except for beginning with the additional information value of 31 and ending with the "break" stop code.

不定長の配列とマップは、追加情報値31を使用してメジャータイプを表し、配列の場合は任意長の0個以上のアイテムのシーケンス、マップの場合はキー/値のペアのシーケンスが続き、「break」ストップコード(Section 3.2.1)で終了します。つまり、不定長の配列とマップは、追加情報値31で始まり、「break」ストップコードで終わる以外は、他の配列とマップと同じように見えます。

If the "break" stop code appears after a key in a map, in place of that key's value, the map is not well-formed.

キーの値の代わりに、マップ内のキーの後に「break」ストップコードが現れた場合、マップはウェルフォームではありません。

There is no restriction against nesting indefinite-length array or map items. A "break" only terminates a single item, so nested indefinite-length items need exactly as many "break" stop codes as there are type bytes starting an indefinite-length item.

不定長配列またはマップアイテムをネストする制限はありません。「break」は単一のアイテムを終了するだけであるため、不定長アイテムを開始するタイプバイトがあるだけ、ネストされた不定長アイテムには正確に同じ数の「break」ストップコードが必要です。

For example, assume an encoder wants to represent the abstract array [1, [2, 3], [4, 5]]. The definite-length encoding would be 0x8301820203820405:

たとえば、エンコーダーが抽象的な配列[1、[2、3]、[4、5]]を表現したい場合、定義済み長エンコーディングは0x8301820203820405となります。

83        -- Array of length 3
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   82     -- Array of length 2
      04  -- 4
      05  -- 5
83        -- 長さ3の配列
   01     -- 1
   82     -- 長さ2の配列
      02  -- 2
      03  -- 3
   82     -- 長さ2の配列
      04  -- 4
      05  -- 5

Indefinite-length encoding could be applied independently to each of the three arrays encoded in this data item, as required, leading to representations such as:

このデータアイテムでエンコードされた3つの配列それぞれに対して、必要に応じて不定長エンコーディングを独立して適用でき、次のような表現が得られます。

0x9f018202039f0405ffff
9F        -- Start indefinite-length array
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   9F     -- Start indefinite-length array
      04  -- 4
      05  -- 5
      FF  -- "break" (inner array)
   FF     -- "break" (outer array)
0x9f018202039f0405ffff
9F        -- 不定長配列の開始
   01     -- 1
   82     -- 長さ2の配列
      02  -- 2
      03  -- 3
   9F     -- 不定長配列の開始
      04  -- 4
      05  -- 5
      FF  -- 「break」ストップコード(内側の配列)
   FF     -- 「break」ストップコード(外側の配列)
0x9f01820203820405ff
9F        -- Start indefinite-length array
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   82     -- Array of length 2
      04  -- 4
      05  -- 5
   FF     -- "break"
0x9f01820203820405ff
9F        -- 不定長配列の開始
   01     -- 1
   82     -- 長さ2の配列
      02  -- 2
      03  -- 3
   82     -- 長さ2の配列
      04  -- 4
      05  -- 5
   FF     -- 「break」ストップコード
0x83018202039f0405ff
83        -- Array of length 3
   01     -- 1
   82     -- Array of length 2
      02  -- 2
      03  -- 3
   9F     -- Start indefinite-length array
      04  -- 4
      05  -- 5
      FF  -- "break"
0x83018202039f0405ff
83        -- 長さ3の配列
   01     -- 1
   82     -- 長さ2の配列
      02  -- 2
      03  -- 3
   9F     -- 不定長配列の開始
      04  -- 4
      05  -- 5
      FF  -- 「break」ストップコード
0x83019f0203ff820405
83        -- Array of length 3
   01     -- 1
   9F     -- Start indefinite-length array
      02  -- 2
      03  -- 3
      FF  -- "break"
   82     -- Array of length 2
      04  -- 4
      05  -- 5
0x83019f0203ff820405
83        -- 長さ3の配列
   01     -- 1
   9F     -- 不定長配列の開始
      02  -- 2
      03  -- 3
      FF  -- 「break」ストップコード
   82     -- 長さ2の配列
      04  -- 4
      05  -- 5

An example of an indefinite-length map (that happens to have two key/value pairs) might be:

不定長マップの例(2つのキー/値ペアを持つ)は次のようになります。

0xbf6346756ef563416d7421ff
BF           -- Start indefinite-length map
   63        -- First key, UTF-8 string length 3
      46756e --   "Fun"
   F5        -- First value, true
   63        -- Second key, UTF-8 string length 3
      416d74 --   "Amt"
   21        -- Second value, -2
   FF        -- "break"
0xbf6346756ef563416d7421ff
BF           -- 不定長マップの開始
   63        -- 最初のキー、UTF-8文字列長3
      46756e --   "Fun"
   F5        -- 最初の値、true
   63        -- 2番目のキー、UTF-8文字列長3
      416d74 --   "Amt"
   21        -- 2番目の値、-2
   FF        -- 「break」ストップコード

Indefinite-length strings are represented by a byte containing the major type for byte string or text string with an additional information value of 31, followed by a series of zero or more strings of the specified type ("chunks") that have definite lengths, and finished by the "break" stop code (Section 3.2.1). The data item represented by the indefinite-length string is the concatenation of the chunks. If no chunks are present, the data item is an empty string of the specified type. Zero-length chunks, while not particularly useful, are permitted.

不定長文字列は、バイト文字列またはテキスト文字列のメジャータイプを表すバイトと、追加情報値31を含むシリーズのゼロ個以上の指定されたタイプの文字列(「チャンク」)に続いて、「break」ストップコード(Section 3.2.1)で終了します。不定長文字列で表されるデータアイテムは、チャンクの連結です。チャンクが存在しない場合、データアイテムは指定されたタイプの空の文字列です。長さゼロのチャンクは、とくに有用ではありませんが、許可されています。

If any item between the indefinite-length string indicator (0b010_11111 or 0b011_11111) and the "break" stop code is not a definite-length string item of the same major type, the string is not well-formed.

不定長文字列指示子(0b010_11111または0b011_11111)と「break」ストップコードの間にあるアイテムのうち、同じメジャータイプの定長文字列アイテムでないものがある場合、文字列はウェルフォームではありません。

The design does not allow nesting indefinite-length strings as chunks into indefinite-length strings. If it were allowed, it would require decoder implementations to keep a stack, or at least a count, of nesting levels. It is unnecessary on the encoder side because the inner indefinite-length string would consist of chunks, and these could instead be put directly into the outer indefinite-length string.

この設計では、不定長文字列をチャンクとして不定長文字列にネストすることはできません。許可された場合、デコーダーの実装にはスタック、または少なくともネストレベルのカウントを保持する必要があります。内部の不定長文字列はチャンクで構成されているため、エンコーダー側では不要であり、これらは代わりに外部の不定長文字列に直接配置できます。

If any definite-length text string inside an indefinite-length text string is invalid, the indefinite-length text string is invalid. Note that this implies that the UTF-8 bytes of a single Unicode code point (scalar value) cannot be spread between chunks: a new chunk of a text string can only be started at a code point boundary.

不定長テキスト文字列内の定長テキスト文字列のいずれかが無効な場合、不定長テキスト文字列は無効です。これは、単一のUnicodeコードポイント(スカラー値)のUTF-8バイトがチャンク間に分散されることはできないことを意味します。つまり、テキスト文字列の新しいチャンクは、コードポイントの境界でのみ開始できます。

For example, assume an encoded data item consisting of the bytes:

たとえば、次のバイトから構成される符号化されたデータアイテムを想定してください。

0b010_11111 0b010_00100 0xaabbccdd 0b010_00011 0xeeff99 0b111_11111
5F              -- Start indefinite-length byte string
   44           -- Byte string of length 4
      aabbccdd  -- Bytes content
   43           -- Byte string of length 3
      eeff99    -- Bytes content
   FF           -- "break"
0b010_11111 0b011_11111 0b010_00100 0xaabbccdd 0b010_00011 0xeeff99 0b111_11111
5F              -- Start indefinite-length byte string
   44           -- Byte string of length 4
      aabbccdd  -- Bytes content
   43           -- Byte string of length 3
      eeff99    -- Bytes content
   FF           -- "break"

After decoding, this results in a single byte string with seven bytes: 0xaabbccddeeff99.

デコード後、これにより7バイトの単一のバイト文字列が生成されます:0xaabbccddeeff99。

Table 2 summarizes the major types defined by CBOR as used for indefinite-length encoding (with additional information set to 31).

Table 2 は、追加情報値31を使用して不定長エンコーディングに使用されるCBORによって定義されたメジャータイプをまとめたものです。

Table 2: Overview of the Indefinite-Length Use of CBOR Major Types (Additional Information = 31)
Major Type Meaning Enclosed up to "break" Stop Code
0 (not well-formed) -
1 (not well-formed) -
2 byte string definite-length byte strings
3 text string definite-length text strings
4 array data items (elements)
5 map data items (key/value pairs)
6 (not well-formed) -
7 "break" stop code -
表 2: CBORメジャータイプの不定長使用の概要(追加情報=31)
メジャータイプ 意味 「break」ストップコードまでの内容
0 (not well-formed) -
1 (not well-formed) -
2 byte string definite-length byte strings
3 text string definite-length text strings
4 array data items (elements)
5 map data items (key/value pairs)
6 (not well-formed) -
7 "break" stop code -

Major type 7 is for two types of data: floating-point numbers and "simple values" that do not need any content. Each value of the 5-bit additional information in the initial byte has its own separate meaning, as defined in Table 3. Like the major types for integers, items of this major type do not carry content data; all the information is in the initial bytes (the head).

メジャータイプ7は、浮動小数点数とコンテンツを必要としない「シンプル値」の2つのデータタイプに使用されます。初期バイトの5ビットの追加情報値の各値には、Table 3で定義された独自の意味があります。整数のメジャータイプと同様に、このメジャータイプのアイテムにはコンテンツデータが含まれていません。すべての情報は初期バイト(ヘッド)に含まれています。

Table 3: Values for Additional Information in Major Type 7
5-Bit Value Semantics
0..23 Simple value (value 0..23)
24 Simple value (value 32..255 in following byte)
25 IEEE 754 Half-Precision Float (16 bits follow)
26 IEEE 754 Single-Precision Float (32 bits follow)
27 IEEE 754 Double-Precision Float (64 bits follow)
28-30 Reserved, not well-formed in the present document
31 "break" stop code for indefinite-length items (Section 3.2.1)
表 3: メジャータイプ7における追加情報の値
5ビット値 意味
0..23 シンプル値(値0..23)
24 シンプル値(値32..255は次のバイトにある)
25 IEEE 754半精度浮動小数点数(16ビットが続く)
26 IEEE 754単精度浮動小数点数(32ビットが続く)
27 IEEE 754倍精度浮動小数点数(64ビットが続く)
28-30 予約済み、現在の文書ではウェルフォームではありません
31 不定長アイテムの「break」ストップコード(Section 3.2.1参照)

As with all other major types, the 5-bit value 24 signifies a single-byte extension: it is followed by an additional byte to represent the simple value. (To minimize confusion, only the values 32 to 255 are used.) This maintains the structure of the initial bytes: as for the other major types, the length of these always depends on the additional information in the first byte. Table 4 lists the numeric values assigned and available for simple values.

他のすべてのメジャータイプと同様に、5ビット値24は単一バイト拡張を示します。これに続いて、追加のバイトが続き、シンプル値を表します(混乱を最小限に抑えるため、値32から255のみが使用されます)。これにより、初期バイトの構造が維持されます。他のメジャータイプと同様に、これらの長さは常に最初のバイトの追加情報に依存します。Table 4 には、シンプル値に割り当てられた数値値と使用可能な値がリストされています。

Table 4: Simple Values
Value Semantics
0..19 (unassigned)
20 false
21 true
22 null
23 undefined
24..31 (reserved)
32..255 (unassigned)
表 4: シンプル値
意味
0..19 (未割り当て)
20 false
21 true
22 null
23 undefined
24..31 (予約済み)
32..255 (未割り当て)

An encoder MUST NOT issue two-byte sequences that start with 0xf8 (major type 7, additional information 24) and continue with a byte less than 0x20 (32 decimal). Such sequences are not well-formed. (This implies that an encoder cannot encode false, true, null, or undefined in two-byte sequences and that only the one-byte variants of these are well-formed; more generally speaking, each simple value only has a single representation variant).

エンコーダーは、0xf8(メジャータイプ7、追加情報値24)で始まり、0x20(10進数32)未満のバイトで続く2バイトシーケンスを発行してはなりません(MUST NOT)。このようなシーケンスはウェルフォームではありません。(これは、エンコーダーが2バイトシーケンスでfalsetruenull、またはundefinedをエンコードできないことを意味し、これらの1バイトバリアントのみがウェルフォームであることを意味します。より一般的には、各シンプル値には単一の表現バリアントしかありません。)

The 5-bit values of 25, 26, and 27 are for 16-bit, 32-bit, and 64-bit IEEE 754 binary floating-point values [IEEE754]. These floating-point values are encoded in the additional bytes of the appropriate size. (See Appendix D for some information about 16-bit floating-point numbers.)

メジャータイプ25、26、27の5ビット値は、16ビット、32ビット、64ビットのIEEE 754バイナリ浮動小数点値[IEEE754]に使用されます。これらの浮動小数点値は、適切なサイズの追加バイトでエンコードされます。 (16ビット浮動小数点数に関する情報については、Appendix Dを参照してください。)

In CBOR, a data item can be enclosed by a tag to give it some additional semantics, as uniquely identified by a tag number. The tag is major type 6, its argument (Section 3) indicates the tag number, and it contains a single enclosed data item, the tag content. (If a tag requires further structure to its content, this structure is provided by the enclosed data item.) We use the term tag for the entire data item consisting of both a tag number and the tag content: the tag content is the data item that is being tagged.

CBORでは、データアイテムにタグを付けることで、タグ番号によって一意に識別されるいくつかの追加セマンティクスを付与できます。タグはメジャータイプ6であり、その引数(Section 3で定義されている)はタグ番号を示し、単一の囲まれたデータアイテムであるタグコンテンツを含みます。 (タグにコンテンツのさらなる構造が必要な場合は、この構造は囲まれたデータアイテムによって提供されます。)私たちは、タグ番号とタグコンテンツの両方から構成されるデータアイテム全体をタグと呼びます:タグコンテンツは、タグが付けられているデータアイテムです。

For example, assume that a byte string of length 12 is marked with a tag of number 2 to indicate it is an unsigned bignum (Section 3.4.3). The encoded data item would start with a byte 0b110_00010 (major type 6, additional information 2 for the tag number) followed by the encoded tag content: 0b010_01100 (major type 2, additional information 12 for the length) followed by the 12 bytes of the bignum.

たとえば、長さ12のバイト文字列が、符号なしのbignumSection 3.4.3)であることを示すために、タグ番号2でマークされているとします。エンコードされたデータアイテムは、バイト0b110_00010(メジャータイプ6、タグ番号の追加情報2)で始まり、エンコードされたタグコンテンツが続きます:0b010_01100(長さの追加情報12のメジャータイプ2)に続いて、bignumの12バイトが続きます。

In the extended generic data model, a tag number's definition describes the additional semantics conveyed with the tag number. These semantics may include equivalence of some tagged data items with other data items, including some that can be represented in the basic generic data model. For instance, 0xc24101, a bignum the tag content of which is the byte string with the single byte 0x01, is equivalent to an integer 1, which could also be encoded as 0x01, 0x1801, or 0x190001. The tag definition may specify a preferred serialization (Section 4.1) that is recommended for generic encoders; this may prefer basic generic data model representations over ones that employ a tag.

拡張ジェネリックデータモデルでは、タグ番号の定義によって、タグ番号で伝達される追加のセマンティクスが説明されます。これらのセマンティクスには、基本的なジェネリックデータモデルで表現できるものを含め、タグ付きデータアイテムの一部を他のデータアイテムと同等にすることができます。たとえば、タグコンテンツが単一バイト0x01のバイト文字列である0xc24101のbignumは、整数1と等価であり、0x01、0x1801、または0x190001でエンコードすることもできます。タグの定義では、ジェネリックエンコーダーに推奨される優先シリアル化(Section 4.1)を指定できます。これにより、タグを使用するものよりも基本的なジェネリックデータモデルの表現が優先される場合があります。

The tag definition usually defines which nested data items are valid for such tags. Tag definitions may restrict their content to a very specific syntactic structure, as the tags defined in this document do, or they may define their content more semantically. An example for the latter is how tags 40 and 1040 accept multiple ways to represent arrays [RFC8746].

タグの定義では、通常、そのようなタグに対して有効なネストされたデータアイテムを定義します。タグの定義は、このドキュメントで定義されているタグのように、非常に特定の構文構造にその内容を制限することができます。また、より意味的な方法でその内容を定義することもできます。後者の例として、タグ40および1040が配列を表す複数の方法を受け入れる方法があります。[RFC8746]

As a matter of convention, many tags do not accept null or undefined values as tag content; instead, the expectation is that a null or undefined value can be used in place of the entire tag; Section 3.4.2 provides some further considerations for one specific tag about the handling of this convention in application protocols and in mapping to platform types.

多くのタグでは、nullまたはundefinedの値をタグコンテンツとして受け入れないことが慣例となっています。代わりに、nullまたはundefinedの値は、タグ全体の代わりに使用できることが期待されています。Section 3.4.2は、アプリケーションプロトコルおよびプラットフォームタイプへのマッピングにおけるこの慣例の扱いについて、1つの特定のタグに関するさらなる考慮事項を提供しています。

Decoders do not need to understand tags of every tag number, and tags may be of little value in applications where the implementation creating a particular CBOR data item and the implementation decoding that stream know the semantic meaning of each item in the data flow. The primary purpose of tags in this specification is to define common data types such as dates. A secondary purpose is to provide conversion hints when it is foreseen that the CBOR data item needs to be translated into a different format, requiring hints about the content of items. Understanding the semantics of tags is optional for a decoder; it can simply present both the tag number and the tag content to the application, without interpreting the additional semantics of the tag.

デコーダーは、すべてのタグ番号のタグを理解する必要はなく、特定のCBORデータアイテムを作成する実装と、そのストリームをデコードする実装がデータフロー内の各アイテムの意味を知っているアプリケーションでは、タグがあまり役に立たない場合があります。この仕様におけるタグの主な目的は、日付などの共通のデータ型を定義することです。2次的な目的は、アイテムの内容に関するヒントが必要な別の形式にCBORデータアイテムを変換する必要がある場合に、変換ヒントを提供することです。タグの意味を理解することは、デコーダーにとってオプションです。デコーダーは、単にタグ番号とタグコンテンツの両方をアプリケーションに提示し、タグの追加セマンティクスを解釈せずに済ませることができます。

A tag applies semantics to the data item it encloses. Tags can nest: if tag A encloses tag B, which encloses data item C, tag A applies to the result of applying tag B on data item C.

タグは、それが囲んでいるデータアイテムにセマンティクスを適用します。 タグはネストできます。つまり、タグAがタグBを囲み、タグBがデータアイテムCを囲む場合、タグAはデータアイテムCにタグBを適用した結果にタグを適用します。

IANA maintains a registry of tag numbers as described in Section 9.2. Table 5 provides a list of tag numbers that were defined in [RFC7049] with definitions in the rest of this section. (Tag number 35 was also defined in [RFC7049]; a discussion of this tag number follows in Section 3.4.5.3.) Note that many other tag numbers have been defined since the publication of [RFC7049]; see the registry described at Section 9.2 for the complete list.

IANAは、Section 9.2で説明されているように、タグ番号のレジストリを維持しています。 Table 5は、このセクションの残りの部分で定義されたタグ番号のリストを提供します。 (タグ番号35も RFC7049 で定義されています。このタグ番号に関する議論は、Section 3.4.5.3で続きます。) RFC7049 の発行以降、多くの他のタグ番号が定義されています。完全なリストについては、Section 9.2で説明されているレジストリを参照してください。

Table 5: Tag Numbers Defined in RFC 7049
Tag Data Item Semantics
0 text string Standard date/time string; see Section 3.4.1
1 integer or float Epoch-based date/time; see Section 3.4.2
2 byte string Unsigned bignum; see Section 3.4.3
3 byte string Negative bignum; see Section 3.4.3
4 array Decimal fraction; see Section 3.4.4
5 array Bigfloat; see Section 3.4.4
21 (any) Expected conversion to base64url encoding; see Section 3.4.5.2
22 (any) Expected conversion to base64 encoding; see Section 3.4.5.2
23 (any) Expected conversion to base16 encoding; see Section 3.4.5.2
24 byte string Encoded CBOR data item; see Section 3.4.5.1
32 text string URI; see Section 3.4.5.3
33 text string base64url; see Section 3.4.5.3
34 text string base64; see Section 3.4.5.3
36 text string MIME message; see Section 3.4.5.3
55799 (any) Self-described CBOR; see Section 3.4.6
表 5: RFC 7049で定義されているタグ番号
タグ データアイテム セマンティクス
0 テキスト文字列 標準的な日付/時刻文字列。詳細はSection 3.4.1を参照してください。
1 整数または浮動小数点数 エポックベースの日付/時刻。詳細はSection 3.4.2を参照してください。
2 バイト文字列 符号なしのビッグナンバー。詳細はSection 3.4.3を参照してください。
3 バイト文字列 負のビッグナンバー。詳細はSection 3.4.3を参照してください。
4 配列 10進数の小数。詳細はSection 3.4.4を参照してください。
5 配列 Bigfloat。詳細はSection 3.4.4を参照してください。
21 (任意) base64urlエンコーディングへの変換が期待されます。詳細はSection 3.4.5.2を参照してください。
22 (任意) base64エンコーディングへの変換が期待されます。詳細はSection 3.4.5.2を参照してください。
23 (任意) base16エンコーディングへの変換が期待されます。詳細はSection 3.4.5.2を参照してください。
24 バイト文字列 エンコードされたCBORデータアイテム。詳細はSection 3.4.5.1を参照してください。
32 テキスト文字列 URI。詳細はSection 3.4.5.3を参照してください。
33 テキスト文字列 base64url。詳細はSection 3.4.5.3を参照してください。
34 テキスト文字列 base64。詳細はSection 3.4.5.3を参照してください。
36 テキスト文字列 MIMEメッセージ。詳細はSection 3.4.5.3を参照してください。
55799 (任意) 自己記述CBOR。詳細はSection 3.4.6を参照してください。

Conceptually, tags are interpreted in the generic data model, not at (de-)serialization time. A small number of tags (at this time, tag number 25 and tag number 29 [IANA.cbor-tags]) have been registered with semantics that may require processing at (de-)serialization time: the decoder needs to be aware of, and the encoder needs to be in control of, the exact sequence in which data items are encoded into the CBOR data item. This means these tags cannot be implemented on top of an arbitrary generic CBOR encoder/decoder (which might not reflect the serialization order for entries in a map at the data model level and vice versa); their implementation therefore typically needs to be integrated into the generic encoder/decoder. The definition of new tags with this property is NOT RECOMMENDED.

概念的には、タグは一般的なデータモデルで解釈され、(de-)シリアル化時に解釈されます。少数のタグ(現時点では、タグ番号25とタグ番号29[IANA.cbor-tags])は、(de-)シリアル化時に処理が必要なセマンティクスで登録されています。デコーダーは、CBORデータアイテムにデータアイテムがエンコードされる正確なシーケンスを把握する必要があり、エンコーダーはその制御下にある必要があります。これは、これらのタグが任意の一般的なCBORエンコーダー/デコーダーの上に実装できないことを意味します(データモデルレベルのマップのエントリのシリアル化順序とその逆を反映しない可能性があるため)。そのため、これらのタグの実装は通常、一般的なエンコーダー/デコーダーに統合する必要があります。このようなプロパティを持つ新しいタグの定義は、推奨されません(NOT RECOMMENDED)

IANA allocated tag numbers 65535, 4294967295, and 18446744073709551615 (binary all-ones in 16-bit, 32-bit, and 64-bit). These can be used as a convenience for implementers who want a single-integer data structure to indicate either the presence of a specific tag or absence of a tag. That allocation is described in Section 10 of [CBOR-TAGS]. These tags are not intended to occur in actual CBOR data items; implementations MAY flag such an occurrence as an error.

IANAは、タグ番号65535、4294967295、および18446744073709551615(16ビット、32ビット、および64ビットのすべてが1であるバイナリ)を割り当てました。 これらは、特定のタグの存在またはタグの不在を示す単一の整数データ構造を実装者が必要とする場合の便宜のために使用できます。 この割り当てについては、[CBOR-TAGS]のSection 10で説明されています。 これらのタグは、実際のCBORデータアイテムには出現しないことが意図されています。 実装は、そのような出現をエラーとしてフラグ付けしてもよいです(MAY)

Protocols can extend the generic data model (Section 2) with data items representing points in time by using tag numbers 0 and 1, with arbitrarily sized integers by using tag numbers 2 and 3, and with floating-point values of arbitrary size and precision by using tag numbers 4 and 5.

プロトコルは、タグ番号0および1を使用して時間の点を表すデータアイテム、タグ番号2および3を使用して任意のサイズの整数、およびタグ番号4および5を使用して任意のサイズと精度の浮動小数点値を使用して、一般的なデータモデル(Section 2)を拡張することができます。

Tag number 0 contains a text string in the standard format described by the date-time production in [RFC3339], as refined by Section 3.3 of [RFC4287], representing the point in time described there. A nested item of another type or a text string that doesn't match the format described in [RFC4287] is invalid.

タグ番号0には、[RFC3339]で説明されている標準的なフォーマットのテキスト文字列が含まれます。このフォーマットは、[RFC4287]のSection 3.3によって改良され、そこで説明されている時点を表します。他のタイプのネストされたアイテムや、[RFC4287]で説明されているフォーマットに一致しないテキスト文字列は無効です。

Tag number 1 contains a numerical value counting the number of seconds from 1970-01-01T00:00Z in UTC time to the represented point in civil time.

タグ番号1には、UTC時間で1970年1月1日00:00Zから表される時点までの秒数を数える数値が含まれています。

The tag content MUST be an unsigned or negative integer (major types 0 and 1) or a floating-point number (major type 7 with additional information 25, 26, or 27). Other contained types are invalid.

タグの内容は、符号なしまたは負の整数(メジャータイプ0および1)または浮動小数点数(メジャータイプ7と追加情報25、26、または27)である必要があります(MUST)。それ以外の含まれる型は無効です。

Nonnegative values (major type 0 and nonnegative floating-point numbers) stand for time values on or after 1970-01-01T00:00Z UTC and are interpreted according to POSIX [TIME_T]. (POSIX time is also known as "UNIX Epoch time".) Leap seconds are handled specially by POSIX time, and this results in a 1-second discontinuity several times per decade. Note that applications that require the expression of times beyond early 2106 cannot leave out support of 64-bit integers for the tag content.

非負の値(メジャータイプ0および非負の浮動小数点数)は、1970-01-01T00:00Z UTC以降の時刻値を表し、POSIX [TIME_T]にしたがって解釈されます。 (POSIX時間は「UNIXエポック時間」としても知られています。) POSIX時間では、閏秒は特別に扱われ、数十年に数回1秒の不連続性が生じます。 なお、早期の2106年以降の時刻の表現を必要とするアプリケーションは、タグの内容に64ビット整数のサポートを省略できません。

Negative values (major type 1 and negative floating-point numbers) are interpreted as determined by the application requirements as there is no universal standard for UTC count-of-seconds time before 1970-01-01T00:00Z (this is particularly true for points in time that precede discontinuities in national calendars). The same applies to non-finite values.

負の値(メジャータイプ1および負の浮動小数点数)は、1970-01-01T00:00Z以前のUTC秒数の時間を決定するための普遍的な標準がないため、アプリケーションの要件によって解釈されます(これは、国民的なカレンダーの不連続性の前の時点にとくに当てはまります)。 非有限値についても同様です。

To indicate fractional seconds, floating-point values can be used within tag number 1 instead of integer values. Note that this generally requires binary64 support, as binary16 and binary32 provide nonzero fractions of seconds only for a short period of time around early 1970. An application that requires tag number 1 support may restrict the tag content to be an integer (or a floating-point value) only.

小数秒を示すために、整数値の代わりにタグ番号1内で浮動小数点値を使用できます。ただし、これには一般的にバイナリ64のサポートが必要であり、バイナリ16およびバイナリ32は1970年前後の短い期間にしか秒未満の小数を提供しません。タグ番号1のサポートが必要なアプリケーションは、タグの内容を整数値(または浮動小数点値)に制限することがあります。

Note that platform types for date/time may include null or undefined values, which may also be desirable at an application protocol level. While emitting tag number 1 values with non-finite tag content values (e.g., with NaN for undefined date/time values or with Infinity for an expiry date that is not set) may seem an obvious way to handle this, using untagged null or undefined avoids the use of non-finites and results in a shorter encoding. Application protocol designers are encouraged to consider these cases and include clear guidelines for handling them.

日付/時刻のプラットフォーム型には、アプリケーションプロトコルレベルで望ましい場合があるnullまたはundefinedの値が含まれる場合があります。 非有限のタグコンテンツ値(例:未定義の日付/時刻値にNaNを使用するか、設定されていない有効期限日にInfinityを使用する)でタグ番号1値を出力することは、これを処理する明らかな方法のように思えるかもしれませんが、非有限値の使用を避け、より短いエンコーディングを生成するために、タグのないnullまたはundefinedを使用できます。 アプリケーションプロトコルの設計者は、これらのケースを考慮し、それらを処理するための明確なガイドラインを含めることが推奨されます。

Protocols using tag numbers 2 and 3 extend the generic data model (Section 2) with "bignums" representing arbitrarily sized integers. In the basic generic data model, bignum values are not equal to integers from the same model, but the extended generic data model created by this tag definition defines equivalence based on numeric value, and preferred serialization (Section 4.1) never makes use of bignums that also can be expressed as basic integers (see below).

タグ番号2および3を使用するプロトコルは、任意のサイズの整数を表す「bignums」で一般的なデータモデル(Section 2)を拡張します。基本的な一般的なデータモデルでは、bignum値は同じモデルの整数と等しくありませんが、このタグ定義によって作成された拡張一般的なデータモデルは、数値値に基づく同等性を定義し、優先されるシリアル化(Section 4.1)は、基本的な整数として表現できるbignumsを使用しません(以下を参照)。

Bignums are encoded as a byte string data item, which is interpreted as an unsigned integer n in network byte order. Contained items of other types are invalid. For tag number 2, the value of the bignum is n. For tag number 3, the value of the bignum is -1 - n. The preferred serialization of the byte string is to leave out any leading zeroes (note that this means the preferred serialization for n = 0 is the empty byte string, but see below). Decoders that understand these tags MUST be able to decode bignums that do have leading zeroes. The preferred serialization of an integer that can be represented using major type 0 or 1 is to encode it this way instead of as a bignum (which means that the empty string never occurs in a bignum when using preferred serialization). Note that this means the non-preferred choice of a bignum representation instead of a basic integer for encoding a number is not intended to have application semantics (just as the choice of a longer basic integer representation than needed, such as 0x1800 for 0x00, does not).

bignumは、符号なし整数nとして解釈されるバイト文字列データアイテムとしてエンコードされます。他のタイプの含まれるアイテムは無効です。タグ番号2の場合、bignumの値はnです。タグ番号3の場合、bignumの値は-1-nです。バイト文字列の優先シリアル化は、先頭のゼロを省略することです(n = 0の場合、優先シリアル化は空のバイト文字列ですが、以下を参照してください)。 これらのタグを理解するデコーダーは、先頭にゼロがあるbignumをデコードできる必要があります。 メジャータイプ0または1で表現できる整数の優先シリアル化は、bignumとしてエンコードする代わりにこの方法でエンコードすることです(つまり、優先シリアル化を使用する場合、空の文字列はbignumには決して現れません)。 つまり、数値をエンコードするための基本的な整数の代わりにbignum表現を選択する非優先選択肢には、アプリケーションセマンティクスがあるわけではないことに注意してください(つまり、0x00の代わりに0x1800など、必要以上に長い基本的な整数表現を選択することと同様です)。

For example, the number 18446744073709551616 (264) is represented as 0b110_00010 (major type 6, tag number 2), followed by 0b010_01001 (major type 2, length 9), followed by 0x010000000000000000 (one byte 0x01 and eight bytes 0x00). In hexadecimal:

たとえば、数値18446744073709551616(264)は、0b110_00010(メジャータイプ6、タグ番号2)で表され、次に0b010_01001(メジャータイプ2、長さ9)が続き、その後に0x010000000000000000(1バイト0x01と8バイト0x00)が続きます。16進数で表すと:

C2                        -- Tag 2
   49                     -- Byte string of length 9
      010000000000000000  -- Bytes content
C2                        -- タグ2
   49                     -- 長さ9のバイト文字列
      010000000000000000  -- バイトの内容

Protocols using tag number 4 extend the generic data model with data items representing arbitrary-length decimal fractions of the form m*(10e). Protocols using tag number 5 extend the generic data model with data items representing arbitrary-length binary fractions of the form m*(2e). As with bignums, values of different types are not equal in the generic data model.

タグ番号4を使用するプロトコルは、m*(10e)の形式の任意長の10進小数を表すデータアイテムで一般的なデータモデルを拡張します。 タグ番号5を使用するプロトコルは、m*(2e)の形式の任意長の2進小数を表すデータアイテムで一般的なデータモデルを拡張します。 bignumと同様に、異なる型の値は一般的なデータモデルでは等しくありません。

Decimal fractions combine an integer mantissa with a base-10 scaling factor. They are most useful if an application needs the exact representation of a decimal fraction such as 1.1 because there is no exact representation for many decimal fractions in binary floating-point representations.

10進小数は、整数の仮数と10進のスケーリング因子を組み合わせたものです。多くの10進小数には、2進浮動小数点表現では正確な表現がないため、1.1のような10進小数の正確な表現が必要な場合にもっとも有用です。

"Bigfloats" combine an integer mantissa with a base-2 scaling factor. They are binary floating-point values that can exceed the range or the precision of the three IEEE 754 formats supported by CBOR (Section 3.3). Bigfloats may also be used by constrained applications that need some basic binary floating-point capability without the need for supporting IEEE 754.

「Bigfloats」は、整数の仮数と2進のスケーリング因子を組み合わせたものです。 これらは、CBORでサポートされている3つのIEEE 754フォーマットの範囲または精度を超えるバイナリ浮動小数点値です (Section 3.3)。Bigfloatsは、IEEE 754のサポートが必要なく、基本的なバイナリ浮動小数点機能が必要な制約されたアプリケーションでも使用できます。

A decimal fraction or a bigfloat is represented as a tagged array that contains exactly two integer numbers: an exponent e and a mantissa m. Decimal fractions (tag number 4) use base-10 exponents; the value of a decimal fraction data item is m*(10e). Bigfloats (tag number 5) use base-2 exponents; the value of a bigfloat data item is m*(2e). The exponent e MUST be represented in an integer of major type 0 or 1, while the mantissa can also be a bignum (Section 3.4.3). Contained items with other structures are invalid.

10進小数またはBigfloatは、正確に2つの整数値(指数eと仮数m)を含むタグ付き配列として表されます。 10進小数(タグ番号4)は、10進の指数を使用します。10進小数データアイテムの値はm*(10e)です。 Bigfloat(タグ番号5)は、2進の指数を使用します。Bigfloatデータアイテムの値はm*(2e)です。 指数eは、整数のメジャータイプ0または1で表現しなければなりません(MUST)。仮数はbignumであることもできます (Section 3.4.3)。他の構造を持つアイテムは無効です。

An example of a decimal fraction is the representation of the number 273.15 as 0b110_00100 (major type 6 for tag, additional information 4 for the tag number), followed by 0b100_00010 (major type 4 for the array, additional information 2 for the length of the array), followed by 0b001_00001 (major type 1 for the first integer, additional information 1 for the value of -2), followed by 0b000_11001 (major type 0 for the second integer, additional information 25 for a two-byte value), followed by 0b0110101010110011 (27315 in two bytes). In hexadecimal:

10進小数の例として、数値273.15の表現があります。これは、0b110_00100(メジャータイプ6のタグ、追加情報4のタグ番号)に続いて、0b100_00010(配列のメジャータイプ4、長さ2の追加情報)が続き、次に0b001_00001(最初の整数のメジャータイプ1、値-2の追加情報1)が続き、次に0b000_11001(2バイト値の追加情報25の第2整数のメジャータイプ0)が続き、最後に0b0110101010110011(2バイトの27315)が続きます。16進数で表すと:

C4             -- Tag 4
   82          -- Array of length 2
      21       -- -2
      19 6ab3  -- 27315
C4             -- タグ4
   82          -- 長さ2の配列
      21       -- -2
      19 6ab3  -- 27315

An example of a bigfloat is the representation of the number 1.5 as 0b110_00101 (major type 6 for tag, additional information 5 for the tag number), followed by 0b100_00010 (major type 4 for the array, additional information 2 for the length of the array), followed by 0b001_00000 (major type 1 for the first integer, additional information 0 for the value of -1), followed by 0b000_00011 (major type 0 for the second integer, additional information 3 for the value of 3). In hexadecimal:

Bigfloatの例として、数値1.5の表現があります。これは、0b110_00101(メジャータイプ6のタグ、追加情報5のタグ番号)に続いて、0b100_00010(配列のメジャータイプ4、長さ2の追加情報)が続き、次に0b001_00000(最初の整数のメジャータイプ1、値-1の追加情報0)が続き、次に0b000_00011(2番目の整数のメジャータイプ0、値3の追加情報3)が続きます。16進数で表すと:

C5             -- Tag 5
   82          -- Array of length 2
      20       -- -1
      03       -- 3
C5             -- タグ5
   82          -- 長さ2の配列
      20       -- -1
      03       -- 3

Decimal fractions and bigfloats provide no representation of Infinity, -Infinity, or NaN; if these are needed in place of a decimal fraction or bigfloat, the IEEE 754 half-precision representations from Section 3.3 can be used.

10進小数とBigfloatには、Infinity、-Infinity、またはNaNの表現がありません。これらが10進小数またはBigfloatの代わりに必要な場合は、IEEE 754半精度表現を使用できます (Section 3.3)。

The tags in this section are for content hints that might be used by generic CBOR processors. These content hints do not extend the generic data model.

このセクションのタグは、一般的なCBORプロセッサで使用される可能性のあるコンテンツのヒントです。これらのコンテンツのヒントは、一般的なデータモデルを拡張しません。

Sometimes it is beneficial to carry an embedded CBOR data item that is not meant to be decoded immediately at the time the enclosing data item is being decoded. Tag number 24 (CBOR data item) can be used to tag the embedded byte string as a single data item encoded in CBOR format. Contained items that aren't byte strings are invalid. A contained byte string is valid if it encodes a well-formed CBOR data item; validity checking of the decoded CBOR item is not required for tag validity (but could be offered by a generic decoder as a special option).

エンコード中の外側のデータアイテムをデコードする際に直ちにデコードすることが意図されていない埋め込みCBORデータアイテムを持つことが有益な場合があります。タグ番号24(CBORデータアイテム)は、埋め込みバイト文字列をCBOR形式でエンコードされた単一のデータアイテムとしてタグ付けするために使用できます。バイト文字列でない含まれるアイテムは無効です。含まれるバイト文字列は、適切に形成されたCBORデータアイテムをエンコードする場合に有効です。デコードされたCBORアイテムの妥当性チェックは、タグの妥当性のために必要ではありません(ただし、一般的なデコーダーによって特別なオプションとして提供される可能性があります)。

Tag numbers 21 to 23 indicate that a byte string might require a specific encoding when interoperating with a text-based representation. These tags are useful when an encoder knows that the byte string data it is writing is likely to be later converted to a particular JSON-based usage. That usage specifies that some strings are encoded as base64, base64url, and so on. The encoder uses byte strings instead of doing the encoding itself to reduce the message size, to reduce the code size of the encoder, or both. The encoder does not know whether or not the converter will be generic, and therefore wants to say what it believes is the proper way to convert binary strings to JSON.

タグ番号21から23は、バイト文字列がテキストベースの表現と相互運用する際に特定のエンコーディングが必要である可能性があることを示します。これらのタグは、エンコーダーが書き込んでいるバイト文字列データが後で特定のJSONベースの使用法に変換される可能性がある場合に有用です。その使用法では、一部の文字列がbase64、base64urlなどとしてエンコードされます。エンコーダーは、メッセージサイズを減らし、エンコーダーのコードサイズを減らすために、エンコード自体を行わずにバイト文字列を使用します。エンコーダーは、変換器が一般的かどうかを知らないため、バイナリ文字列をJSONに変換する適切な方法を示したいと考えています。

The data item tagged can be a byte string or any other data item. In the latter case, the tag applies to all of the byte string data items contained in the data item, except for those contained in a nested data item tagged with an expected conversion.

タグ付けされたデータアイテムは、バイト文字列または他のデータアイテムである可能性があります。後者の場合、タグは、期待される変換でタグ付けされたネストされたデータアイテムに含まれるバイト文字列データアイテムを除く、データアイテムに含まれるすべてのバイト文字列データアイテムに適用されます。

These three tag numbers suggest conversions to three of the base data encodings defined in [RFC4648]. Tag number 21 suggests conversion to base64url encoding (Section 5 of [RFC4648]) where padding is not used (see Section 3.2 of [RFC4648]); that is, all trailing equals signs ("=") are removed from the encoded string. Tag number 22 suggests conversion to classical base64 encoding (Section 4 of [RFC4648]) with padding as defined in RFC 4648. For both base64url and base64, padding bits are set to zero (see Section 3.5 of [RFC4648]), and the conversion to alternate encoding is performed on the contents of the byte string (that is, without adding any line breaks, whitespace, or other additional characters). Tag number 23 suggests conversion to base16 (hex) encoding with uppercase alphabetics (see Section 8 of [RFC4648]). Note that, for all three tag numbers, the encoding of the empty byte string is the empty text string.

これらの3つのタグ番号は、[RFC4648]で定義された3つの基本データエンコーディングに変換することを示唆しています。タグ番号21は、パディングが使用されないbase64urlエンコーディング ([RFC4648]のSection 5)に変換することを示唆しています。つまり、エンコードされた文字列からすべての末尾の等号("=")が削除されます。 タグ番号22は、RFC 4648で定義されたパディングを使用した古典的なbase64エンコーディング ([RFC4648]のSection 4)に変換することを示唆しています。 base64urlとbase64の両方の場合、パディングビットはゼロに設定されます([RFC4648]のSection 3.5を参照)、 そして、代替エンコーディングへの変換は、バイト文字列の内容に対して実行されます(つまり、改行、空白、または その他の追加文字を追加しないでください)。タグ番号23は、大文字のアルファベットを使用したbase16(hex)エンコーディングに変換することを示唆しています([RFC4648]のSection 8を参照)。 これらの3つのタグ番号すべてについて、空のバイト文字列のエンコーディングは空のテキスト文字列です。

Some text strings hold data that have formats widely used on the Internet, and sometimes those formats can be validated and presented to the application in appropriate form by the decoder. There are tags for some of these formats.

一部のテキスト文字列は、インターネットで広く使用されているフォーマットを持つデータを保持し、デコーダーによって適切な形式でアプリケーションに検証および表示される場合があります。これらのフォーマットのいくつかには、タグがあります。

  • Tag number 32 is for URIs, as defined in [RFC3986]. If the text string doesn't match the URI-reference production, the string is invalid.
  • Tag numbers 33 and 34 are for base64url- and base64-encoded text strings, respectively, as defined in [RFC4648]. If any of the following apply:

    • the encoded text string contains non-alphabet characters or only 1 alphabet character in the last block of 4 (where alphabet is defined by Section 5 of [RFC4648] for tag number 33 and Section 4 of [RFC4648] for tag number 34), or
    • the padding bits in a 2- or 3-character block are not 0, or
    • the base64 encoding has the wrong number of padding characters, or
    • the base64url encoding has padding characters,

    the string is invalid.

  • Tag number 36 is for MIME messages (including all headers), as defined in [RFC2045]. A text string that isn't a valid MIME message is invalid. (For this tag, validity checking may be particularly onerous for a generic decoder and might therefore not be offered. Note that many MIME messages are general binary data and therefore cannot be represented in a text string; [IANA.cbor-tags] lists a registration for tag number 257 that is similar to tag number 36 but uses a byte string as its tag content.)
  • タグ番号32は、[RFC3986]で定義されたURIに対して使用されます。テキスト文字列がURI-referenceプロダクションに一致しない場合、文字列は無効です。
  • タグ番号33と34は、それぞれbase64urlエンコードされたテキスト文字列とbase64エンコードされたテキスト文字列に対して使用されます。これらは、[RFC4648]で定義されています。次のいずれかが適用される場合:

    • エンコードされたテキスト文字列に、アルファベット以外の文字が含まれているか、または最後の4ブロックのうち1つだけがアルファベットの場合(アルファベットは、タグ番号33の場合は[RFC4648]のSection 5で定義されたものであり、タグ番号34の場合は[RFC4648]のSection 4で定義されたものである)。
    • 2文字または3文字のブロックのパディングビットが0でない場合、または
    • base64エンコーディングに誤った数のパディング文字が含まれる場合、または
    • base64urlエンコーディングにパディング文字が含まれる場合、

    文字列が無効です。

  • タグ番号36は、[RFC2045]で定義されたMIMEメッセージ(すべてのヘッダーを含む)に対して使用されます。有効なMIMEメッセージでないテキスト文字列は無効です。(このタグについては、汎用デコーダーにとって有効性チェックが特に困難である場合があり、提供されない場合があります。多くのMIMEメッセージは一般的なバイナリデータであり、テキスト文字列で表現することはできません。タグ番号257の登録が、タグ番号36に似ているが、タグコンテンツとしてバイト文字列を使用するものが、[IANA.cbor-tags]にリストされています。)

Note that tag numbers 33 and 34 differ from 21 and 22 in that the data is transported in base-encoded form for the former and in raw byte string form for the latter.

タグ番号33と34は、データが前者の場合はbaseエンコード形式で、後者の場合は生のバイト文字列形式で輸送されることを示す点で、タグ番号21と22とは異なります。

[RFC7049] also defined a tag number 35 for regular expressions that are in Perl Compatible Regular Expressions (PCRE/PCRE2) form [PCRE] or in JavaScript regular expression syntax [ECMA262]. The state of the art in these regular expression specifications has since advanced and is continually advancing, so this specification does not attempt to update the references. Instead, this tag remains available (as registered in [RFC7049]) for applications that specify the particular regular expression variant they use out-of-band (possibly by limiting the usage to a defined common subset of both PCRE and ECMA262). As this specification clarifies tag validity beyond [RFC7049], we note that due to the open way the tag was defined in [RFC7049], any contained string value needs to be valid at the CBOR tag level (but then may not be "expected" at the application level).

[RFC7049]は、Perl Compatible Regular Expressions (PCRE/PCRE2)形式[PCRE]またはJavaScript正規表現構文[ECMA262]で表される正規表現に対して、タグ番号35を定義しています。これらの正規表現仕様の最新の状況は進歩し続けており、この仕様書では参照を更新することは試みません。代わりに、このタグは([RFC7049]で登録されているように)利用可能であり、アプリケーションがPCREとECMA262の定義済みの共通サブセットを使用することによって、使用する特定の正規表現バリアントを指定することができます。この仕様書がタグの有効性を明確にするため、[RFC7049]を超えて、このタグに含まれる文字列値はCBORタグレベルで有効である必要があることに注意してください(ただし、アプリケーションレベルで「期待される」値である必要はありません)。

In many applications, it will be clear from the context that CBOR is being employed for encoding a data item. For instance, a specific protocol might specify the use of CBOR, or a media type is indicated that specifies its use. However, there may be applications where such context information is not available, such as when CBOR data is stored in a file that does not have disambiguating metadata. Here, it may help to have some distinguishing characteristics for the data itself.

多くのアプリケーションでは、データ項目をエンコードするためにCBORが使用されていることが文脈から明らかになる場合があります。たとえば、特定のプロトコルがCBORの使用を指定する場合や、使用を指定するメディアタイプが示される場合があります。ただし、CBORデータが区別可能なメタデータを持たないファイルに保存されている場合など、そのような文脈情報が利用できないアプリケーションがあるかもしれません。ここで、データ自体に識別可能な特徴があると役立つ場合があります。

Tag number 55799 is defined for this purpose, specifically for use at the start of a stored encoded CBOR data item as specified by an application. It does not impart any special semantics on the data item that it encloses; that is, the semantics of the tag content enclosed in tag number 55799 is exactly identical to the semantics of the tag content itself.

タグ番号55799は、アプリケーションによって指定された保存されたエンコードされたCBORデータ項目の先頭で使用するために特別に定義されています。これは、囲まれたデータ項目に特別な意味を与えるものではありません。つまり、タグ番号55799で囲まれたタグコンテンツの意味は、タグコンテンツ自体の意味とまったく同じです。

The serialization of this tag's head is 0xd9d9f7, which does not appear to be in use as a distinguishing mark for any frequently used file types. In particular, 0xd9d9f7 is not a valid start of a Unicode text in any Unicode encoding if it is followed by a valid CBOR data item.

このタグのヘッダーのシリアル化は0xd9d9f7であり、頻繁に使用されるファイルタイプの識別マークとして使用されているようには見えません。特に、0xd9d9f7は、有効なCBORデータ項目が続く場合、任意のUnicodeエンコーディングでUnicodeテキストの開始として有効ではありません。

For instance, a decoder might be able to decode both CBOR and JSON. Such a decoder would need to mechanically distinguish the two formats. An easy way for an encoder to help the decoder would be to tag the entire CBOR item with tag number 55799, the serialization of which will never be found at the beginning of a JSON text.

たとえば、デコーダーがCBORとJSONの両方をデコードできる場合、それらの形式を機械的に区別する必要があります。エンコーダーがデコーダーを支援するための簡単な方法は、タグ番号55799でCBOR項目全体をタグ付けすることです。このタグのシリアル化は、JSONテキストの先頭には決して見つからないため、デコーダーがCBOR項目を正しく識別できます。

For some values at the data model level, CBOR provides multiple serializations. For many applications, it is desirable that an encoder always chooses a preferred serialization (preferred encoding); however, the present specification does not put the burden of enforcing this preference on either the encoder or decoder.

データモデルレベルの一部の値について、CBORは複数のシリアル化を提供しています。 多くのアプリケーションでは、エンコーダーが常に優先されるシリアル化(優先エンコーディング)を選択することが望ましいですが、この仕様書では、この優先順位をエンコーダーまたはデコーダーのどちらにも課すことはありません。

Some constrained decoders may be limited in their ability to decode non-preferred serializations: for example, if only integers below 1_000_000_000 (one billion) are expected in an application, the decoder may leave out the code that would be needed to decode 64-bit arguments in integers. An encoder that always uses preferred serialization ("preferred encoder") interoperates with this decoder for the numbers that can occur in this application. Generally speaking, a preferred encoder is more universally interoperable (and also less wasteful) than one that, say, always uses 64-bit integers.

いくつかの制約のあるデコーダーは、非優先シリアル化をデコードする能力に制限がある場合があります。たとえば、アプリケーションで1_000_000_000(10億)未満の整数のみが想定されている場合、デコーダーは整数の64ビット引数をデコードするために必要なコードを省略する場合があります。常に優先シリアル化(「優先エンコーダー」)を使用するエンコーダーは、このアプリケーションで発生する可能性のある数値に対してこのデコーダーと相互運用します。一般的に、優先エンコーダーは、64ビット整数を常に使用するエンコーダーよりも普遍的に相互運用可能であり(また、無駄が少ない)、より望ましいです。

Similarly, a constrained encoder may be limited in the variety of representation variants it supports such that it does not emit preferred serializations ("variant encoder"). For instance, a constrained encoder could be designed to always use the 32-bit variant for an integer that it encodes even if a short representation is available (assuming that there is no application need for integers that can only be represented with the 64-bit variant). A decoder that does not rely on receiving only preferred serializations ("variation-tolerant decoder") can therefore be said to be more universally interoperable (it might very well optimize for the case of receiving preferred serializations, though). Full implementations of CBOR decoders are by definition variation tolerant; the distinction is only relevant if a constrained implementation of a CBOR decoder meets a variant encoder.

同様に、制約のあるエンコーダーは、優先シリアル化を出力しないように設計されることがあります(「バリアントエンコーダー」)。たとえば、制約のあるエンコーダーは、64ビットバリアントが必要ない場合でも、常に32ビットバリアントを使用するように設計されることがあります(64ビットバリアントでしか表現できない整数がアプリケーションで必要ない場合)。優先シリアル化のみを受信することを前提としないデコーダー(「バリエーショントレラントデコーダー」)は、より普遍的に相互運用可能であると言えます(ただし、優先シリアル化を受信することを最適化することもできます)。CBORデコーダーの完全な実装は、定義上、バリエーショントレラントであり、制約のあるCBORデコーダーがバリアントエンコーダーに対応する場合にのみ、この区別が重要です。

The preferred serialization always uses the shortest form of representing the argument (Section 3); it also uses the shortest floating-point encoding that preserves the value being encoded.

優先シリアル化は、常に引数を表現する最短の形式を使用します(Section 3)。また、エンコードされる値を保持する最短の浮動小数点エンコーディングも使用します。

The preferred serialization for a floating-point value is the shortest floating-point encoding that preserves its value, e.g., 0xf94580 for the number 5.5, and 0xfa45ad9c00 for the number 5555.5. For NaN values, a shorter encoding is preferred if zero-padding the shorter significand towards the right reconstitutes the original NaN value (for many applications, the single NaN encoding 0xf97e00 will suffice).

浮動小数点値の優先シリアル化は、その値を保持する最短の浮動小数点エンコーディングを使用します。たとえば、数値5.5の場合は0xf94580、数値5555.5の場合は0xfa45ad9c00が使用されます。NaN値の場合、元のNaN値を再構成するために右側に向かって短い有効桁数をゼロでパディングできる場合、より短いエンコーディングが優先されます(多くのアプリケーションでは、単一のNaNエンコーディング0xf97e00が十分です)。

Definite-length encoding is preferred whenever the length is known at the time the serialization of the item starts.

長さがアイテムのシリアル化が開始される時点で既知である場合、明示的長さエンコーディングが優先されます。

Some protocols may want encoders to only emit CBOR in a particular deterministic format; those protocols might also have the decoders check that their input is in that deterministic format. Those protocols are free to define what they mean by a "deterministic format" and what encoders and decoders are expected to do. This section defines a set of restrictions that can serve as the base of such a deterministic format.

一部のプロトコルでは、エンコーダーがCBORを特定の決定論的形式でのみ出力するように要求し、デコーダーが入力がその決定論的形式であることを確認することを望む場合があります。これらのプロトコルは、「決定論的形式」とは何を意味するか、エンコーダーとデコーダーが何をすることが期待されるかを定義できます。このセクションでは、そのような決定論的形式の基礎となる一連の制限を定義しています。

A CBOR encoding satisfies the "core deterministic encoding requirements" if it satisfies the following restrictions:

CBORエンコーディングが「コア決定論的エンコーディング要件」を満たす場合、以下の制限を満たす場合です。

  • Preferred serialization MUST be used. In particular, this means that arguments (see Section 3) for integers, lengths in major types 2 through 5, and tags MUST be as short as possible, for instance:

    • 0 to 23 and -1 to -24 MUST be expressed in the same byte as the major type;
    • 24 to 255 and -25 to -256 MUST be expressed only with an additional uint8_t;
    • 256 to 65535 and -257 to -65536 MUST be expressed only with an additional uint16_t;
    • 65536 to 4294967295 and -65537 to -4294967296 MUST be expressed only with an additional uint32_t.

    Floating-point values also MUST use the shortest form that preserves the value, e.g., 1.5 is encoded as 0xf93e00 (binary16) and 1000000.5 as 0xfa49742408 (binary32). (One implementation of this is to have all floats start as a 64-bit float, then do a test conversion to a 32-bit float; if the result is the same numeric value, use the shorter form and repeat the process with a test conversion to a 16-bit float. This also works to select 16-bit float for positive and negative Infinity as well.)

  • Indefinite-length items MUST NOT appear. They can be encoded as definite-length items instead.
  • The keys in every map MUST be sorted in the bytewise lexicographic order of their deterministic encodings. For example, the following keys are sorted correctly:

    1. 10, encoded as 0x0a.
    2. 100, encoded as 0x1864.
    3. -1, encoded as 0x20.
    4. "z", encoded as 0x617a.
    5. "aa", encoded as 0x626161.
    6. [100], encoded as 0x811864.
    7. [-1], encoded as 0x8120.
    8. false, encoded as 0xf4.
  • 優先シリアル化を使用しなければなりません(MUST)。とくに、整数の引数(Section 3を参照)、メジャータイプ2から5の長さ、およびタグは、できるだけ短くする必要があります。たとえば、次のようになります。

    • 0から23および-1から-24は、同じバイトで表現しなければなりません(MUST)
    • 24から255および-25から-256は、追加のuint8_tでのみ表現しなければなりません(MUST)
    • 256から65535および-257から-65536は、追加のuint16_tでのみ表現しなければなりません(MUST)
    • 65536から4294967295および-65537から-4294967296は、追加のuint32_tでのみ表現しなければなりません(MUST)

    浮動小数点値も、値を保持する最短の形式を使用しなければなりません(MUST)。たとえば、1.5は0xf93e00(binary16)としてエンコードされ、1000000.5は0xfa49742408(binary32)としてエンコードされます。 (これの1つの実装方法は、すべての浮動小数点数を64ビット浮動小数点数として開始し、32ビット浮動小数点数へのテスト変換を行います。結果が同じ数値である場合、より短い形式を使用して、16ビット浮動小数点数へのテスト変換を繰り返します。これは、正のおよび負の無限大に対して16ビット浮動小数点数を選択するためにも機能します。)

  • 不定長のアイテムは出現してはなりません(MUST NOT)。代わりに、定長のアイテムとしてエンコードします。
  • すべてのマップのキーは、その決定論的エンコーディングのバイト単位の辞書順序でソートしなければなりません(MUST)。たとえば、次のキーは正しくソートされます。

    1. 10は0x0aとしてエンコードされます。
    2. 100は0x1864としてエンコードされます。
    3. -1は0x20としてエンコードされます。
    4. "z"は0x617aとしてエンコードされます。
    5. "aa"は0x626161としてエンコードされます。
    6. [100]は0x811864としてエンコードされます。
    7. [-1]は0x8120としてエンコードされます。
    8. falseは0xf4としてエンコードされます。

CBOR tags present additional considerations for deterministic encoding. If a CBOR-based protocol were to provide the same semantics for the presence and absence of a specific tag (e.g., by allowing both tag 1 data items and raw numbers in a date/time position, treating the latter as if they were tagged), the deterministic format would not allow the presence of the tag, based on the "shortest form" principle. For example, a protocol might give encoders the choice of representing a URL as either a text string or, using Section 3.4.5.3, tag number 32 containing a text string. This protocol's deterministic encoding needs either to require that the tag is present or to require that it is absent, not allow either one.

CBORタグは、決定論的エンコーディングに追加の考慮事項を提供します。CBORベースのプロトコルが、特定のタグの存在と不在に対して同じセマンティクスを提供する場合(たとえば、日付/時刻の位置においてタグ1のデータ項目と生の数値の両方を許可し、後者をタグ付きであるかのように扱うことにより)、最短形式の原則に基づいて、決定論的形式ではタグの存在を許可しません。たとえば、プロトコルがURLをテキスト文字列またはテキスト文字列を含むタグ番号32として表現する選択肢をエンコーダーに与える場合、このプロトコルの決定論的エンコーディングは、タグが存在することを要求するか、存在しないことを要求するか、どちらかを要求する必要があります。

In a protocol that does require tags in certain places to obtain specific semantics, the tag needs to appear in the deterministic format as well. Deterministic encoding considerations also apply to the content of tags.

特定のセマンティクスを取得するために、特定の場所でタグが必要なプロトコルでは、タグは決定論的形式でも表示する必要があります。タグの内容にも決定論的エンコーディングの考慮事項が適用されます。

If a protocol includes a field that can express integers with an absolute value of 264 or larger using tag numbers 2 or 3 (Section 3.4.3), the protocol's deterministic encoding needs to specify whether smaller integers are also expressed using these tags or using major types 0 and 1. Preferred serialization uses the latter choice, which is therefore recommended.

プロトコルに2のタグ番号または3のタグ番号を使用して絶対値が264以上の整数を表現できるフィールドが含まれている場合、プロトコルの決定論的エンコーディングは、小さい整数もこれらのタグを使用して表現するか、major type 0および1を使用して表現するかを指定する必要があります。優先シリアル化は後者の選択肢を使用するため、推奨されます。

Protocols that include floating-point values, whether represented using basic floating-point values (Section 3.3) or using tags (or both), may need to define extra requirements on their deterministic encodings, such as:

基本的な浮動小数点値(Section 3.3を参照)またはタグを使用して表現される浮動小数点値を含むプロトコルは、決定論的エンコーディングに対して追加の要件を定義する必要がある場合があります。これらの要件には、次のようなものがあります。

  • Although IEEE floating-point values can represent both positive and negative zero as distinct values, the application might not distinguish these and might decide to represent all zero values with a positive sign, disallowing negative zero. (The application may also want to restrict the precision of floating-point values in such a way that there is never a need to represent 64-bit -- or even 32-bit -- floating-point values.)
  • If a protocol includes a field that can express floating-point values, with a specific data model that declares integer and floating-point values to be interchangeable, the protocol's deterministic encoding needs to specify whether, for example, the integer 1.0 is encoded as 0x01 (unsigned integer), 0xf93c00 (binary16), 0xfa3f800000 (binary32), or 0xfb3ff0000000000000 (binary64). Example rules for this are:

    1. Encode integral values that fit in 64 bits as values from major types 0 and 1, and other values as the preferred (smallest of 16-, 32-, or 64-bit) floating-point representation that accurately represents the value,
    2. Encode all values as the preferred floating-point representation that accurately represents the value, even for integral values, or
    3. Encode all values as 64-bit floating-point representations.

    Rule 1 straddles the boundaries between integers and floating-point values, and Rule 3 does not use preferred serialization, so Rule 2 may be a good choice in many cases.

  • If NaN is an allowed value, and there is no intent to support NaN payloads or signaling NaNs, the protocol needs to pick a single representation, typically 0xf97e00. If that simple choice is not possible, specific attention will be needed for NaN handling.
  • Subnormal numbers (nonzero numbers with the lowest possible exponent of a given IEEE 754 number format) may be flushed to zero outputs or be treated as zero inputs in some floating-point implementations. A protocol's deterministic encoding may want to specifically accommodate such implementations while creating an onus on other implementations by excluding subnormal numbers from interchange, interchanging zero instead.
  • The same number can be represented by different decimal fractions, by different bigfloats, and by different forms under other tags that may be defined to express numeric values. Depending on the implementation, it may not always be practical to determine whether any of these forms (or forms in the basic generic data model) are equivalent. An application protocol that presents choices of this kind for the representation format of numbers needs to be explicit about how the formats for deterministic encoding are to be chosen.
  • IEEE浮動小数点値は、正のゼロと負のゼロの両方を区別できる値として表現できますが、アプリケーションはこれらを区別せず、すべてのゼロ値を正の符号で表現することを決定し、負のゼロを許可しない場合があります。 (アプリケーションは、64ビットまたは32ビットの浮動小数点値を表現する必要がないように、浮動小数点値の精度を制限することもできます。)
  • プロトコルに、整数と浮動小数点値を相互変換可能であると宣言された特定のデータモデルを持つ浮動小数点値を表現できるフィールドが含まれている場合、プロトコルの決定論的エンコーディングは、たとえば、整数1.0が0x01(符号なし整数)、0xf93c00(binary16)、0xfa3f800000(binary32)、または0xfb3ff0000000000000(binary64)としてエンコードされるかを指定する必要があります。これに関する例のルールは以下のとおりです。

    1. 64ビットに収まる整数値は、major type 0および1の値としてエンコードし、その他の値は、値を正確に表現する最小の16ビット、32ビット、または64ビットの浮動小数点表現としてエンコードします。
    2. 整数値であっても、値を正確に表現する最小の浮動小数点表現として、すべての値をエンコードします。
    3. すべての値を64ビット浮動小数点表現としてエンコードします。

    ルール1は整数と浮動小数点値の境界をまたいでおり、ルール3は優先シリアル化を使用していないため、ルール2は多くの場合良い選択肢となります。

  • NaNが許容されており、NaNペイロードまたはシグナリングNaNをサポートする意図がない場合、プロトコルは通常、単一の表現(通常は0xf97e00)を選択する必要があります。この単純な選択ができない場合は、NaNの処理に特別な注意が必要です。
  • サブノーマル数(あるIEEE 754数値フォーマットの最低指数を持つゼロ以外の数値)は、一部の浮動小数点実装ではゼロにフラッシュされる出力として扱われる場合があります。プロトコルの決定論的エンコーディングは、サブノーマル数を交換から除外し、代わりにゼロを交換することで、そのような実装に特に対応することができます。
  • 同じ数値は、異なる小数、異なるbigfloat、および数値値を表現するために定義された他のタグの異なる形式によって表現することができます。実装によっては、これらの形式のいずれか(または基本的な一般的なデータモデルの形式)が等価であるかどうかを判断することが常に実用的ではない場合があります。数値の表現形式の選択肢を提示するアプリケーションプロトコルは、決定論的エンコーディングの形式がどのように選択されるかについて明示する必要があります。

The core deterministic encoding requirements (Section 4.2.1) sort map keys in a different order from the one suggested by Section 3.9 of [RFC7049] (called "Canonical CBOR" there). Protocols that need to be compatible with the order specified in [RFC7049] can instead be specified in terms of this specification's "length-first core deterministic encoding requirements":

コア決定論的エンコーディング要件(Section 4.2.1)は、[RFC7049]のSection 3.9で提案された順序(そこでは「Canonical CBOR」と呼ばれる)とは異なる順序でマップキーをソートします。RFC7049で指定された順序と互換性を持つ必要があるプロトコルは、代わりにこの仕様の「長さ優先のコア決定論的エンコーディング要件」で指定できます。

A CBOR encoding satisfies the "length-first core deterministic encoding requirements" if it satisfies the core deterministic encoding requirements except that the keys in every map MUST be sorted such that:

CBORエンコーディングが「長さ優先のコア決定論的エンコーディング要件」を満たす場合、コア決定論的エンコーディング要件を満たすが、すべてのマップのキーが次のようにソートされている必要があります(MUST)

  1. If two keys have different lengths, the shorter one sorts earlier;
  2. If two keys have the same length, the one with the lower value in (bytewise) lexical order sorts earlier.
  1. 2つのキーの長さが異なる場合、短い方が先にソートされます。
  2. 2つのキーの長さが同じ場合、(バイト単位の)レキシコグラフィック順序で値が低い方が先にソートされます。

For example, under the length-first core deterministic encoding requirements, the following keys are sorted correctly:

たとえば、長さ優先のコア決定論的エンコーディング要件の下では、次のキーが正しくソートされます。

  1. 10, encoded as 0x0a.
  2. -1, encoded as 0x20.
  3. false, encoded as 0xf4.
  4. 100, encoded as 0x1864.
  5. "z", encoded as 0x617a.
  6. [-1], encoded as 0x8120.
  7. "aa", encoded as 0x626161.
  8. [100], encoded as 0x811864.
  1. 10は、0x0aとしてエンコードされます。
  2. -1は、0x20としてエンコードされます。
  3. falseは、0xf4としてエンコードされます。
  4. 100は、0x1864としてエンコードされます。
  5. "z"は、0x617aとしてエンコードされます。
  6. [-1]は、0x8120としてエンコードされます。
  7. "aa"は、0x626161としてエンコードされます。
  8. [100]は、0x811864としてエンコードされます。

Data formats such as CBOR are often used in environments where there is no format negotiation. A specific design goal of CBOR is to not need any included or assumed schema: a decoder can take a CBOR item and decode it with no other knowledge.

CBORのようなデータフォーマットは、フォーマットのネゴシエーションがない環境でしばしば使用されます。CBORの特定の設計目標は、含まれるまたは想定されるスキーマが必要ないことです。つまり、デコーダーはCBORアイテムを取得し、他に何も知らなくてもデコードできます。

Of course, in real-world implementations, the encoder and the decoder will have a shared view of what should be in a CBOR data item. For example, an agreed-to format might be "the item is an array whose first value is a UTF-8 string, second value is an integer, and subsequent values are zero or more floating-point numbers" or "the item is a map that has byte strings for keys and contains a pair whose key is 0xab01".

実際の実装では、エンコーダーとデコーダーはCBORデータアイテムに何が含まれるべきかについて共有の見解を持っています。たとえば、合意されたフォーマットは「アイテムはUTF-8文字列が最初の値であり、2番目の値は整数であり、その後の値は0個以上の浮動小数点数である配列である」または「アイテムは、キーにバイト文字列を持ち、キーが0xab01であるペアを含むマップである」といったものがあります。

CBOR-based protocols MUST specify how their decoders handle invalid and other unexpected data. CBOR-based protocols MAY specify that they treat arbitrary valid data as unexpected. Encoders for CBOR-based protocols MUST produce only valid items, that is, the protocol cannot be designed to make use of invalid items. An encoder can be capable of encoding as many or as few types of values as is required by the protocol in which it is used; a decoder can be capable of understanding as many or as few types of values as is required by the protocols in which it is used. This lack of restrictions allows CBOR to be used in extremely constrained environments.

CBORベースのプロトコルは、そのデコーダーが無効なデータやその他の予期しないデータをどのように処理するかを指定しなければなりません(MUST)。CBORベースのプロトコルは、任意の有効なデータを予期しないデータとして扱うことをMAY指定することができます。CBORベースのプロトコルのエンコーダーは、無効なアイテムを使用することができないため、常に有効なアイテムのみを生成しなければなりません(MUST)。エンコーダーは、使用されるプロトコルで必要な種類の値を多くまたは少なくエンコードできます。デコーダーは、使用されるプロトコルで必要な種類の値を多くまたは少なく理解できます。これらの制限がないため、CBORは非常に制限された環境で使用できます。

The rest of this section discusses some considerations in creating CBOR-based protocols. With few exceptions, it is advisory only and explicitly excludes any language from BCP 14 [RFC2119] [RFC8174] other than words that could be interpreted as "MAY" in the sense of BCP 14. The exceptions aim at facilitating interoperability of CBOR-based protocols while making use of a wide variety of both generic and application-specific encoders and decoders.

このセクションの残りの部分では、CBORベースのプロトコルを作成する際の考慮事項について説明します。ほとんどの場合、これはアドバイザリーであり、BCP 14の言語を除いて、明示的に「MAY」と解釈できる言葉を使用します。例外は、一般的なものとアプリケーション固有のエンコーダーとデコーダーの両方を使用することを目的として、CBORベースのプロトコルの相互運用性を容易にすることを目的としています。

In a streaming application, a data stream may be composed of a sequence of CBOR data items concatenated back-to-back. In such an environment, the decoder immediately begins decoding a new data item if data is found after the end of a previous data item.

ストリーミングアプリケーションでは、データストリームは連結されたCBORデータアイテムのシーケンスで構成される場合があります。このような環境では、デコーダーは前のデータアイテムの終わりの後にデータが見つかった場合、すぐに新しいデータアイテムのデコードを開始します。

Not all of the bytes making up a data item may be immediately available to the decoder; some decoders will buffer additional data until a complete data item can be presented to the application. Other decoders can present partial information about a top-level data item to an application, such as the nested data items that could already be decoded, or even parts of a byte string that hasn't completely arrived yet. Such an application also MUST have a matching streaming security mechanism, where the desired protection is available for incremental data presented to the application.

データアイテムを構成するバイトのすべてがデコーダーにすぐに利用可能であるとは限りません。一部のデコーダーは、完全なデータアイテムがアプリケーションに提供されるまで、追加のデータをバッファリングします。他のデコーダーは、すでにデコードされたネストされたデータアイテムや、まだ完全に到着していないバイト文字列の一部など、トップレベルのデータアイテムに関する部分的な情報をアプリケーションに提供できます。 このようなアプリケーションは、ストリーミングセキュリティーメカニズムを持つ必要があります。この場合、アプリケーションに提供されるインクリメンタルデータに対して、必要な保護が利用可能である必要があります(MUST)

Note that some applications and protocols will not want to use indefinite-length encoding. Using indefinite-length encoding allows an encoder to not need to marshal all the data for counting, but it requires a decoder to allocate increasing amounts of memory while waiting for the end of the item. This might be fine for some applications but not others.

一部のアプリケーションやプロトコルでは、不定長エンコーディングを使用したくない場合があります。不定長エンコーディングを使用すると、エンコーダーはすべてのデータをカウントするためにマーシャリングする必要がなくなりますが、デコーダーはアイテムの終わりを待ちながら増加する量のメモリを割り当てる必要があります。これは、一部のアプリケーションにとっては問題ないかもしれませんが、他のアプリケーションには適していない場合があります。

A generic CBOR decoder can decode all well-formed encoded CBOR data items and present the data items to an application. See Appendix C. (The diagnostic notation, Section 8, may be used to present well-formed CBOR values to humans.)

一般的なCBORデコーダーは、すべての形式が正しいエンコードされたCBORデータアイテムをデコードし、アプリケーションにデータアイテムを提供できます。詳細は、Appendix Cを参照してください。 (診断表記法であるSection 8は、形式が正しいCBOR値を人間に提示するために使用できます。)

Generic CBOR encoders provide an application interface that allows the application to specify any well-formed value to be encoded as a CBOR data item, including simple values and tags unknown to the encoder.

一般的なCBORエンコーダーは、アプリケーションがエンコーダーに未知の単純な値やタグを含む、任意の形式が正しい値をCBORデータアイテムとしてエンコードするよう指定できるアプリケーションインタフェースを提供します。

Even though CBOR attempts to minimize these cases, not all well-formed CBOR data is valid: for example, the encoded text string 0x62c0ae does not contain valid UTF-8 (because [RFC3629] requires always using the shortest form) and so is not a valid CBOR item. Also, specific tags may make semantic constraints that may be violated, for instance, by a bignum tag enclosing another tag or by an instance of tag number 0 containing a byte string or containing a text string with contents that do not match the date-time production of [RFC3339]. There is no requirement that generic encoders and decoders make unnatural choices for their application interface to enable the processing of invalid data. Generic encoders and decoders are expected to forward simple values and tags even if their specific codepoints are not registered at the time the encoder/decoder is written (Section 5.4).

CBORはこれらのケースを最小限に抑えようとしますが、すべての形式が正しいCBORデータが有効であるわけではありません。たとえば、エンコードされたテキスト文字列0x62c0aeは有効なUTF-8を含んでいないため([RFC3629]は常に最短の形式を使用することを要求するため)、有効なCBORアイテムではありません。 また、特定のタグは、別のタグを囲む大きな数値タグや、バイト文字列を含むタグ番号0のインスタンス、または内容が[RFC3339]date-timeプロダクションに一致しないテキスト文字列を含むテキスト文字列など、違反する可能性がある意味の制約を設ける場合があります。一般的なエンコーダーとデコーダーが、無効なデータの処理を可能にするために、アプリケーションインタフェースで不自然な選択をする必要はありません。一般的なエンコーダーとデコーダーは、特定のコードポイントがエンコーダー/デコーダーが書かれた時点で登録されていなくても、単純な値とタグを転送することが期待されます(Section 5.4)。

A well-formed but invalid CBOR data item (Section 1.2) presents a problem with interpreting the data encoded in it in the CBOR data model. A CBOR-based protocol could be specified in several layers, in which the lower layers don't process the semantics of some of the CBOR data they forward. These layers can't notice any validity errors in data they don't process and MUST forward that data as-is. The first layer that does process the semantics of an invalid CBOR item MUST pick one of two choices:

形式が正しいが無効なCBORデータアイテム(Section 1.2)は、CBORデータモデルでエンコードされたデータを解釈する際に問題が発生します。CBORベースのプロトコルは、下位レイヤーが転送するCBORデータの意味を処理しない場合があります。これらのレイヤーは、処理しないデータの妥当性エラーに気付くことができず、そのデータをそのまま転送しなければなりません(MUST)。無効なCBORアイテムの意味を処理する最初のレイヤーは、次の2つの選択肢のいずれかを選択しなければなりません(MUST)

  1. Replace the problematic item with an error marker and continue with the next item, or
  2. Issue an error and stop processing altogether.
  1. 問題のあるアイテムをエラーマーカーで置き換え、次のアイテムを続けるか、
  2. エラーを発行して処理を完全に停止するかのいずれかを行います。

A CBOR-based protocol MUST specify which of these options its decoders take for each kind of invalid item they might encounter.

CBORベースのプロトコルは、デコーダーが遭遇する可能性のある無効なアイテムの種類ごとに、どちらのオプションを取るかを指定しなければなりません(MUST)

Such problems might occur at the basic validity level of CBOR or in the context of tags (tag validity).

このような問題は、CBORの基本的な妥当性レベルやタグの文脈(タグの妥当性)で発生する可能性があります。

Two kinds of validity errors can occur in the basic generic data model:

基本的な汎用データモデルには、2種類の妥当性エラーが発生する可能性があります。

Duplicate keys in a map:
Generic decoders (Section 5.2) make data available to applications using the native CBOR data model. That data model includes maps (key-value mappings with unique keys), not multimaps (key-value mappings where multiple entries can have the same key). Thus, a generic decoder that gets a CBOR map item that has duplicate keys will decode to a map with only one instance of that key, or it might stop processing altogether. On the other hand, a "streaming decoder" may not even be able to notice. See Section 5.6 for more discussion of keys in maps.
Invalid UTF-8 string:
A decoder might or might not want to verify that the sequence of bytes in a UTF-8 string (major type 3) is actually valid UTF-8 and react appropriately.
マップ内の重複するキー:
汎用デコーダー(Section 5.2)は、ネイティブのCBORデータモデルを使用してアプリケーションにデータを提供します。このデータモデルには、ユニークなキーを持つマップ(キーと値のマッピング)が含まれていますが、複数のエントリが同じキーを持つマルチマップ(キーと値のマッピング)は含まれていません。したがって、重複するキーを持つCBORマップアイテムを取得する汎用デコーダーは、そのキーの1つのインスタンスを持つマップにデコードするか、処理を停止するかもしれません。一方、「ストリーミングデコーダー」は、それを気づくことさえできない場合があります。マップ内のキーについての詳細については、Section 5.6を参照してください。
無効なUTF-8文字列:
デコーダーは、UTF-8文字列(メジャータイプ3)のバイトシーケンスが実際に有効なUTF-8であるかどうかを検証し、適切に反応するかどうかは、デコーダーによって異なります。

Two additional kinds of validity errors are introduced by adding tags to the basic generic data model:

基本的な汎用データモデルにタグを追加することで、2種類の追加の妥当性エラーが導入されます。

Inadmissible type for tag content:
Tag numbers (Section 3.4) specify what type of data item is supposed to be used as their tag content; for example, the tag numbers for unsigned or negative bignums are supposed to be put on byte strings. A decoder that decodes the tagged data item into a native representation (a native big integer in this example) is expected to check the type of the data item being tagged. Even decoders that don't have such native representations available in their environment may perform the check on those tags known to them and react appropriately.
Inadmissible value for tag content:
The type of data item may be admissible for a tag's content, but the specific value may not be; e.g., a value of "yesterday" is not acceptable for the content of tag 0, even though it properly is a text string. A decoder that normally ingests such tags into equivalent platform types might present this tag to the application in a similar way to how it would present a tag with an unknown tag number (Section 5.4).
タグの内容に不適切なタイプ:
タグ番号(Section 3.4)は、タグの内容として使用されるデータアイテムのタイプを指定します。たとえば、符号なしまたは負のビッグナンのタグ番号は、バイト文字列に配置する必要があります。ネイティブ表現(この例ではネイティブビッグ整数)にタグ付けされたデータアイテムをデコードするデコーダーは、タグ付けされたデータアイテムのタイプをチェックすることが期待されます。環境にネイティブ表現がないデコーダーでも、彼らに知られているこれらのタグに対してチェックを実行し、適切に反応することができます。
タグの内容に不適切な値:
データアイテムのタイプは、タグの内容に適している場合がありますが、特定の値はそうではない場合があります。たとえば、「昨日」という値は、適切にテキスト文字列であるにもかかわらず、タグ0の内容としては受け入れられません。通常、このようなタグを同等のプラットフォームタイプに取り込むデコーダーは、タグ番号が不明なタグと同様に、このタグをアプリケーションに提示することができます(Section 5.4)。

A decoder with validity checking will expend the effort to reliably detect data items with validity errors. For example, such a decoder needs to have an API that reports an error (and does not return data) for a CBOR data item that contains any of the validity errors listed in the previous subsection.

妥当性チェックを行うデコーダーは、妥当性エラーを含むデータアイテムを信頼性高く検出するための努力を払います。たとえば、このようなデコーダーは、前のサブセクションにリストされている妥当性エラーのいずれかを含むCBORデータアイテムに対してエラーを報告するAPIを持つ必要があります(データを返さない)。

The set of tags defined in the "Concise Binary Object Representation (CBOR) Tags" registry (Section 9.2), as well as the set of simple values defined in the "Concise Binary Object Representation (CBOR) Simple Values" registry (Section 9.1), can grow at any time beyond the set understood by a generic decoder. A validity-checking decoder can do one of two things when it encounters such a case that it does not recognize:

「簡潔なバイナリオブジェクト表現(CBOR)タグ」レジストリ(Section 9.2)で定義されたタグのセット、および「簡潔なバイナリオブジェクト表現(CBOR)シンプルバリュー」レジストリ(Section 9.1)で定義されたシンプルバリューのセットは、汎用デコーダーが理解するセットを超えていつでも成長する可能性があります。妥当性チェックを行うデコーダーは、認識できない場合に2つのことを行うことができます。

  • It can report an error (and not return data). Note that treating this case as an error can cause ossification and is thus not encouraged. This error is not a validity error, per se. This kind of error is more likely to be raised by a decoder that would be performing validity checking if this were a known case.
  • It can emit the unknown item (type, value, and, for tags, the decoded tagged data item) to the application calling the decoder, and then give the application an indication that the decoder did not recognize that tag number or simple value.
  • デコーダーはエラーを報告することができます(データを返さない)。 この場合をエラーとして扱うことは、硬直化を引き起こす可能性があるため、推奨されません。このエラーは、本質的に妥当性エラーではありません。このようなエラーは、既知の場合に妥当性チェックを実行しているデコーダーによってより頻繁に発生する可能性があります。
  • デコーダーが認識できないタグ番号またはシンプルバリューがある場合、デコーダーは、未知のアイテム(タイプ、値、およびタグの場合はデコードされたタグ付きデータアイテム)を呼び出し元のアプリケーションに出力し、デコーダーがそのタグ番号またはシンプルバリューを認識できなかったことを示す指示をアプリケーションに与えることができます。

The latter approach, which is also appropriate for decoders that do not support validity checking, provides forward compatibility with newly registered tags and simple values without the requirement to update the encoder at the same time as the calling application. (For this, the decoder's API needs the ability to mark unknown items so that the calling application can handle them in a manner appropriate for the program.)

後者のアプローチは、妥当性チェックをサポートしていないデコーダーにも適しており、エンコーダーを呼び出すアプリケーションと同時に更新する必要がないまま、新しく登録されたタグやシンプルバリューとの前方互換性を提供します。 (これには、デコーダーのAPIが未知のアイテムをマークする機能が必要であり、呼び出し元のアプリケーションが適切な方法でそれらを処理できるようにする必要があります。)

Since some of the processing needed for validity checking may have an appreciable cost (in particular with duplicate detection for maps), support of validity checking is not a requirement placed on all CBOR decoders.

妥当性チェックに必要な処理の一部は、マップの重複検出に特にコストがかかる場合があるため、妥当性チェックのサポートはすべてのCBORデコーダーに要求される必要はありません。

Some encoders will rely on their applications to provide input data in such a way that valid CBOR results from the encoder. A generic encoder may also want to provide a validity-checking mode where it reliably limits its output to valid CBOR, independent of whether or not its application is indeed providing API-conformant data.

一部のエンコーダーは、アプリケーションがエンコーダーから有効なCBORを生成するように入力データを提供することを期待しています。汎用エンコーダーは、API準拠のデータを提供しているかどうかに関係なく、その出力を有効なCBORに限定する妥当性チェックモードを提供することも望むかもしれません。

CBOR-based protocols should take into account that different language environments pose different restrictions on the range and precision of numbers that are representable. For example, the basic JavaScript number system treats all numbers as floating-point values, which may result in the silent loss of precision in decoding integers with more than 53 significant bits. Another example is that, since CBOR keeps the sign bit for its integer representation in the major type, it has one bit more for signed numbers of a certain length (e.g., -264..264-1 for 1+8-byte integers) than the typical platform signed integer representation of the same length (-263..263-1 for 8-byte int64_t). A protocol that uses numbers should define its expectations on the handling of nontrivial numbers in decoders and receiving applications.

CBORベースのプロトコルは、異なる言語環境が表現可能な数値の範囲と精度に異なる制限を課すことを考慮する必要があります。たとえば、基本的なJavaScript数値システムは、すべての数値を浮動小数点値として扱うため、53ビット以上の有意なビットを持つ整数をデコードする際に精度の損失が発生する可能性があります。 また、CBORは、整数表現の符号ビットをメジャータイプに保持するため、同じ長さの典型的なプラットフォーム符号付き整数表現(8バイトint64_tの場合は-263..263-1)よりも、特定の長さの符号付き数値(たとえば、1 + 8バイト整数の場合は-264..264-1)に1ビット多くのビットがあります。 数値を使用するプロトコルは、デコーダーと受信アプリケーションで非自明な数値の処理に関する期待を定義する必要があります。

A CBOR-based protocol that includes floating-point numbers can restrict which of the three formats (half-precision, single-precision, and double-precision) are to be supported. For an integer-only application, a protocol may want to completely exclude the use of floating-point values.

浮動小数点数を含むCBORベースのプロトコルは、サポートするフォーマット(ハーフプレシジョン、シングルプレシジョン、ダブルプレシジョン)のうちどれを制限するかを制限することができます。整数のみのアプリケーションの場合、プロトコルは浮動小数点値の使用を完全に除外することができます。

A CBOR-based protocol designed for compactness may want to exclude specific integer encodings that are longer than necessary for the application, such as to save the need to implement 64-bit integers. There is an expectation that encoders will use the most compact integer representation that can represent a given value. However, a compact application that does not require deterministic encoding should accept values that use a longer-than-needed encoding (such as encoding "0" as 0b000_11001 followed by two bytes of 0x00) as long as the application can decode an integer of the given size. Similar considerations apply to floating-point values; decoding both preferred serializations and longer-than-needed ones is recommended.

コンパクト性を重視したCBORベースのプロトコルは、64ビット整数を実装する必要を省くために、アプリケーションに必要以上に長い特定の整数エンコーディングを除外することができます。エンコーダーは、特定の値を表現できるもっともコンパクトな整数表現を使用することが期待されています。ただし、決定論的エンコーディングを必要としないコンパクトなアプリケーションは、アプリケーションが指定されたサイズの整数をデコードできる限り、必要以上に長いエンコーディング(たとえば、「0」を0b000_11001にエンコードして、2バイトの0x00が続くようにエンコードする)を使用する値を受け入れる必要があります。 浮動小数点値にも同様の考慮事項が適用されます。推奨されるのは、最適なシリアル化と必要以上に長いシリアル化の両方をデコードすることです。

CBOR-based protocols for constrained applications that provide a choice between representing a specific number as an integer and as a decimal fraction or bigfloat (such as when the exponent is small and nonnegative) might express a quality-of-implementation expectation that the integer representation is used directly.

指数が小さく非負である場合など、特定の数を整数として表現するか、小数点以下の数値またはbigfloatとして表現することを選択できる制約されたアプリケーションのCBORベースのプロトコルは、整数表現が直接使用されることを期待する実装品質の期待値を表現する場合があります。

The encoding and decoding applications need to agree on what types of keys are going to be used in maps. In applications that need to interwork with JSON-based applications, conversion is simplified by limiting keys to text strings only; otherwise, there has to be a specified mapping from the other CBOR types to text strings, and this often leads to implementation errors. In applications where keys are numeric in nature, and numeric ordering of keys is important to the application, directly using the numbers for the keys is useful.

エンコードおよびデコードアプリケーションは、マップで使用されるキーのタイプについて合意する必要があります。JSONベースのアプリケーションと相互運用する必要があるアプリケーションでは、キーをテキスト文字列に限定することで変換が簡素化されます。それ以外の場合、他のCBORタイプからテキスト文字列への指定されたマッピングが必要であり、これにより実装エラーが発生することがよくあります。キーが数値的な性質を持ち、キーの数値的な順序がアプリケーションにとって重要な場合、キーとして直接数値を使用することが有用です。

If multiple types of keys are to be used, consideration should be given to how these types would be represented in the specific programming environments that are to be used. For example, in JavaScript Maps [ECMA262], a key of integer 1 cannot be distinguished from a key of floating-point 1.0. This means that, if integer keys are used, the protocol needs to avoid the use of floating-point keys the values of which happen to be integer numbers in the same map.

複数の種類のキーを使用する場合、これらの種類が使用される特定のプログラミング環境でどのように表現されるかを考慮する必要があります。たとえば、JavaScript Maps [ECMA262]では、整数1のキーは浮動小数点1.0のキーと区別できません。これは、整数キーが使用される場合、プロトコルが同じマップ内の整数値である浮動小数点キーの使用を避ける必要があることを意味します。

Decoders that deliver data items nested within a CBOR data item immediately on decoding them ("streaming decoders") often do not keep the state that is necessary to ascertain uniqueness of a key in a map. Similarly, an encoder that can start encoding data items before the enclosing data item is completely available ("streaming encoder") may want to reduce its overhead significantly by relying on its data source to maintain uniqueness.

CBORデータアイテム内にネストされたデータアイテムをデコードするとすぐに(「ストリーミングデコーダー」)、マップ内のキーの一意性を確認するために必要な状態を保持しないことがよくあります。同様に、データアイテムを完全に利用可能にする前にデータアイテムのエンコードを開始できるエンコーダー(「ストリーミングエンコーダー」)は、データソースが一意性を維持することに依存して、オーバーヘッドを大幅に削減できます。

A CBOR-based protocol MUST define what to do when a receiving application sees multiple identical keys in a map. The resulting rule in the protocol MUST respect the CBOR data model: it cannot prescribe a specific handling of the entries with the identical keys, except that it might have a rule that having identical keys in a map indicates a malformed map and that the decoder has to stop with an error. When processing maps that exhibit entries with duplicate keys, a generic decoder might do one of the following:

CBORベースのプロトコルは、マップ内で複数の同じキーを持つエントリが見つかった場合に受信アプリケーションが何をするかを定義しなければなりません(MUST)。プロトコルによる結果のルールは、CBORデータモデルに準拠する必要があります。つまり、同じキーを持つエントリの処理方法を指定することはできず、ただし、マップ内に同じキーがある場合は、マップが不正なものであることを示すルールがある可能性があり、デコーダーがエラーで停止する必要があります。 重複するキーを持つエントリを含むマップを処理する場合、汎用デコーダーは次のいずれかを行うことがあります。

  • Not accept maps with duplicate keys (that is, enforce validity for maps, see also Section 5.4). These generic decoders are universally useful. An application may still need to perform its own duplicate checking based on application rules (for instance, if the application equates integers and floating-point values in map key positions for specific maps).
  • Pass all map entries to the application, including ones with duplicate keys. This requires that the application handle (check against) duplicate keys, even if the application rules are identical to the generic data model rules.
  • Lose some entries with duplicate keys, e.g., deliver only the final (or first) entry out of the entries with the same key. With such a generic decoder, applications may get different results for a specific key on different runs, and with different generic decoders, which value is returned is based on generic decoder implementation and the actual order of keys in the map. In particular, applications cannot validate key uniqueness on their own as they do not necessarily see all entries; they may not be able to use such a generic decoder if they need to validate key uniqueness. These generic decoders can only be used in situations where the data source and transfer always provide valid maps; this is not possible if the data source and transfer can be attacked.
  • マップ内に重複するキーがある場合は受け入れない(つまり、マップの妥当性を強制する。詳細はSection 5.4を参照)。これらの汎用デコーダーは普遍的に有用です。アプリケーションは、特定のマップにおいて整数と浮動小数点値をマップキーの位置で同等と見なす場合など、アプリケーションルールに基づいた重複チェックを自己実行する必要がある場合があります。
  • 重複するキーを含むすべてのマップエントリをアプリケーションに渡す。これには、アプリケーションが重複するキーを処理する(チェックする)必要があるため、アプリケーションルールが汎用データモデルルールと同一である場合でも、重複するキーを処理する必要があります。
  • 重複するキーを持つエントリのうち、最後のエントリ(または最初のエントリ)のみを配信するなど、一部のエントリを失う。このような汎用デコーダーを使用する場合、アプリケーションは、異なる実行や異なる汎用デコーダーを使用する場合に、特定のキーに対して異なる結果を得る可能性があります。どの値が返されるかは、汎用デコーダーの実装とマップ内のキーの実際の順序に基づいています。特に、アプリケーションは、すべてのエントリを見るわけではないため、自分自身でキーの一意性を検証することができないため、重複チェックを自己実行する必要がある場合があります。これらの汎用デコーダーは、データソースと転送が常に有効なマップを提供する場合にのみ使用できます。データソースと転送が攻撃される可能性がある場合、これは不可能です。

Generic decoders need to document which of these three approaches they implement.

汎用デコーダーは、これら3つのアプローチのうちどれを実装するかを文書化する必要があります。

The CBOR data model for maps does not allow ascribing semantics to the order of the key/value pairs in the map representation. Thus, a CBOR-based protocol MUST NOT specify that changing the key/value pair order in a map changes the semantics, except to specify that some orders are disallowed, for example, where they would not meet the requirements of a deterministic encoding (Section 4.2). (Any secondary effects of map ordering such as on timing, cache usage, and other potential side channels are not considered part of the semantics but may be enough reason on their own for a protocol to require a deterministic encoding format.)

マップのCBORデータモデルでは、マップ表現内のキー/値ペアの順序に意味を付与することはできません。したがって、CBORベースのプロトコルは、マップ内のキー/値ペアの順序を変更することが意味を変えることを指定してはなりません(MUST NOT)(ただし、決定論的エンコーディングの要件を満たさない場合など、一部の順序が許可されないことを指定することはできます。詳細はSection 4.2を参照)。(タイミング、キャッシュ使用、その他の潜在的なサイドチャネルなど、マップの順序による二次的な影響は意味の一部ではありませんが、プロトコルが決定論的エンコーディング形式を要求する理由となる可能性があります。)

Applications for constrained devices should consider using small integers as keys if they have maps with a small number of frequently used keys; for instance, a set of 24 or fewer keys can be encoded in a single byte as unsigned integers, up to 48 if negative integers are also used. Less frequently occurring keys can then use integers with longer encodings.

制約されたデバイス向けのアプリケーションでは、頻繁に使用されるキーの数が少ないマップがある場合は、小さな整数をキーとして使用することを検討する必要があります。たとえば、24個以下のキーのセットは、符号なし整数として1バイトでエンコードでき、負の整数も使用する場合は48個までエンコードできます。出現頻度の低いキーは、より長いエンコーディングを持つ整数を使用できます。

The specific data model that applies to a CBOR data item is used to determine whether keys occurring in maps are duplicates or distinct.

CBORデータアイテムに適用される特定のデータモデルは、マップ内に出現するキーが重複しているかどうかを判断するために使用されます。

At the generic data model level, numerically equivalent integer and floating-point values are distinct from each other, as they are from the various big numbers (Tags 2 to 5). Similarly, text strings are distinct from byte strings, even if composed of the same bytes. A tagged value is distinct from an untagged value or from a value tagged with a different tag number.

汎用データモデルレベルでは、数値的に等しい整数と浮動小数点値は互いに異なり、さまざまなビッグナンバー(タグ2から5)とも異なります。同様に、同じバイトから構成されていても、テキスト文字列はバイト文字列とは異なります。タグ付きの値は、タグのない値または異なるタグ番号でタグ付きの値とも異なります。

Within each of these groups, numeric values are distinct unless they are numerically equal (specifically, -0.0 is equal to 0.0); for the purpose of map key equivalence, NaN values are equivalent if they have the same significand after zero-extending both significands at the right to 64 bits.

これらのグループ内では、数値的に等しい場合を除いて、数値値は異なります(具体的には、-0.0は0.0と等しいです)。マップキーの同等性の目的のために、NaN値は、両方の有効桁を右側に64ビットまでゼロ拡張した後、有効桁が同じ場合に等価です。

Both byte strings and text strings are compared byte by byte, arrays are compared element by element, and are equal if they have the same number of bytes/elements and the same values at the same positions. Two maps are equal if they have the same set of pairs regardless of their order; pairs are equal if both the key and value are equal.

バイト文字列とテキスト文字列は、バイトごとに比較され、配列は要素ごとに比較され、同じバイト/要素数と同じ位置に同じ値がある場合に等しいと見なされます。2つのマップは、順序に関係なく同じペアのセットを持つ場合に等しいと見なされます。ペアは、キーと値の両方が等しい場合に等しいと見なされます。

Tagged values are equal if both the tag number and the tag content are equal. (Note that a generic decoder that provides processing for a specific tag may not be able to distinguish some semantically equivalent values, e.g., if leading zeroes occur in the content of tag 2 or tag 3 (Section 3.4.3).) Simple values are equal if they simply have the same value. Nothing else is equal in the generic data model; a simple value 2 is not equivalent to an integer 2, and an array is never equivalent to a map.

タグ付きの値は、タグ番号とタグの内容が等しい場合に等しいです。 (特定のタグの処理を提供する汎用デコーダーは、タグ2またはタグ3の内容に先行するゼロが含まれる場合など、意味的に等価な値を区別できない場合があることに注意してください(Section 3.4.3)。) シンプル値は、単に同じ値を持つ場合に等しいです。 汎用データモデルでは、それ以外のものは等しくありません。シンプル値2は整数2と等価ではなく、配列はマップと等価ではありません。

As discussed in Section 2.2, specific data models can make values equivalent for the purpose of comparing map keys that are distinct in the generic data model. Note that this implies that a generic decoder may deliver a decoded map to an application that needs to be checked for duplicate map keys by that application (alternatively, the decoder may provide a programming interface to perform this service for the application). Specific data models are not able to distinguish values for map keys that are equal for this purpose at the generic data model level.

特定のデータモデルでは、汎用データモデルで異なるマップキーを比較するために等価な値を作成できます(Section 2.2で説明されています)。これは、汎用デコーダーが、重複するマップキーをチェックする必要があるアプリケーションにデコードされたマップを提供する可能性があることを意味します(代わりに、デコーダーはアプリケーションのためにこのサービスを実行するプログラミングインターフェースを提供することができます)。特定のデータモデルは、汎用データモデルレベルでこの目的のために等しいマップキーの値を区別することができません。

In some CBOR-based protocols, the simple value (Section 3.3) of undefined might be used by an encoder as a substitute for a data item with an encoding problem, in order to allow the rest of the enclosing data items to be encoded without harm.

いくつかのCBORベースのプロトコルでは、エンコーダーがエンコーディングの問題を代替するためにundefinedのシンプル値(Section 3.3)を使用する場合があります。これにより、他の囲むデータアイテムを危険にさらすことなく、残りのデータアイテムをエンコードできるようになります。

This section gives non-normative advice about converting between CBOR and JSON. Implementations of converters MAY use whichever advice here they want.

このセクションでは、CBORとJSONの変換に関する非規範的なアドバイスを提供します。変換プログラムの実装は、ここで提供されるアドバイスのうち、どちらを使用してもかまいません

It is worth noting that a JSON text is a sequence of characters, not an encoded sequence of bytes, while a CBOR data item consists of bytes, not characters.

JSONテキストは文字のシーケンスであり、エンコードされたバイトのシーケンスではないことに注意する価値があります。一方、CBORデータアイテムは文字ではなくバイトで構成されています。

Most of the types in CBOR have direct analogs in JSON. However, some do not, and someone implementing a CBOR-to-JSON converter has to consider what to do in those cases. The following non-normative advice deals with these by converting them to a single substitute value, such as a JSON null.

CBORのほとんどのタイプには、JSONに直接対応するものがあります。ただし、一部には対応するものがないものもあり、CBORからJSONへの変換プログラムを実装する場合は、これらの場合にどのように対処するかを考慮する必要があります。次の非規範的なアドバイスは、これらを単一の代替値(JSON nullなど)に変換することで対処します。

  • An integer (major type 0 or 1) becomes a JSON number.
  • A byte string (major type 2) that is not embedded in a tag that specifies a proposed encoding is encoded in base64url without padding and becomes a JSON string.
  • A UTF-8 string (major type 3) becomes a JSON string. Note that JSON requires escaping certain characters ([RFC8259], Section 7): quotation mark (U+0022), reverse solidus (U+005C), and the "C0 control characters" (U+0000 through U+001F). All other characters are copied unchanged into the JSON UTF-8 string.
  • An array (major type 4) becomes a JSON array.
  • A map (major type 5) becomes a JSON object. This is possible directly only if all keys are UTF-8 strings. A converter might also convert other keys into UTF-8 strings (such as by converting integers into strings containing their decimal representation); however, doing so introduces a danger of key collision. Note also that, if tags on UTF-8 strings are ignored as proposed below, this will cause a key collision if the tags are different but the strings are the same.
  • False (major type 7, additional information 20) becomes a JSON false.
  • True (major type 7, additional information 21) becomes a JSON true.
  • Null (major type 7, additional information 22) becomes a JSON null.
  • A floating-point value (major type 7, additional information 25 through 27) becomes a JSON number if it is finite (that is, it can be represented in a JSON number); if the value is non-finite (NaN, or positive or negative Infinity), it is represented by the substitute value.
  • Any other simple value (major type 7, any additional information value not yet discussed) is represented by the substitute value.
  • A bignum (major type 6, tag number 2 or 3) is represented by encoding its byte string in base64url without padding and becomes a JSON string. For tag number 3 (negative bignum), a "~" (ASCII tilde) is inserted before the base-encoded value. (The conversion to a binary blob instead of a number is to prevent a likely numeric overflow for the JSON decoder.)
  • A byte string with an encoding hint (major type 6, tag number 21 through 23) is encoded as described by the hint and becomes a JSON string.
  • For all other tags (major type 6, any other tag number), the tag content is represented as a JSON value; the tag number is ignored.
  • Indefinite-length items are made definite before conversion.
  • 整数(メジャータイプ0または1)はJSON数値になります。
  • 提案されたエンコーディングを指定するタグに埋め込まれていないバイト文字列(メジャータイプ2)は、パディングのないbase64urlでエンコードされ、JSON文字列になります。
  • UTF-8文字列(メジャータイプ3)はJSON文字列になります。ただし、JSONでは特定の文字([RFC8259], Section 7)をエスケープする必要があります。これらの文字は、引用符(U+0022)、逆ソリッドスラッシュ(U+005C)、および「C0制御文字」(U+0000からU+001F)です。その他の文字は、JSON UTF-8文字列にそのままコピーされます。
  • 配列(メジャータイプ4)はJSON配列になります。
  • マップ(メジャータイプ5)はJSONオブジェクトになります。これは、すべてのキーがUTF-8文字列である場合にのみ直接可能です。コンバータは、他のキーをUTF-8文字列に変換することもできます(たとえば、整数を10進表記を含む文字列に変換することによって)。ただし、これを行うと、キーの衝突の危険性が生じます。また、UTF-8文字列のタグを以下で提案されるように無視する場合、タグが異なるが文字列が同じ場合にキーの衝突が発生することに注意してください。
  • False(メジャータイプ7、追加情報20)はJSON falseになります。
  • True(メジャータイプ7、追加情報21)はJSON trueになります。
  • Null(メジャータイプ7、追加情報22)はJSON nullになります。
  • 浮動小数点値(メジャータイプ7、追加情報25から27)は、有限である場合(つまり、JSON数値で表現できる場合)、JSON数値になります。値が有限でない場合(NaN、正のまたは負のInfinity)、代替値で表されます。
  • その他のシンプル値(メジャータイプ7、まだ議論されていない任意の追加情報値)は、代替値で表されます。
  • バイト文字列をbase64urlでパディングなしでエンコードすることにより、ビッグナンバー(メジャータイプ6、タグ番号2または3)はエンコードされ、JSON文字列になります。タグ番号3(負のビッグナンバー)の場合、ベースエンコードされた値の前に"~"(ASCIIチルダ)が挿入されます(JSONデコーダーの数値オーバーフローを防ぐために、数値ではなくバイナリブロブに変換されます)。
  • エンコーディングヒントを持つバイト文字列(メジャータイプ6、タグ番号21から23)は、ヒントに記載されているようにエンコードされ、JSON文字列になります。
  • その他のタグ(メジャータイプ6、その他のタグ番号)の場合、タグの内容はJSON値として表されます。タグ番号は無視されます。
  • 変換前に、不定長アイテムは定長に変換されます。

A CBOR-to-JSON converter may want to keep to the JSON profile I-JSON [RFC7493], to maximize interoperability and increase confidence that the JSON output can be processed with predictable results. For example, this has implications on the range of integers that can be represented reliably, as well as on the top-level items that may be supported by older JSON implementations.

CBORからJSONへの変換プログラムは、相互運用性を最大化し、JSON出力が予測可能な結果で処理できることを保証するために、JSONプロファイルI-JSON[RFC7493]に従うことが望ましい場合があります。たとえば、これには、信頼性の高い整数の範囲に関する影響があります。また、古いJSON実装でサポートされる可能性のあるトップレベルアイテムにも影響があります。

All JSON values, once decoded, directly map into one or more CBOR values. As with any kind of CBOR generation, decisions have to be made with respect to number representation. In a suggested conversion:

JSON値はすべて、デコードされた後、1つ以上のCBOR値に直接マップされます。CBORの生成に関しては、数値表現に関する決定を行う必要があります。提案される変換では、次のようになります。

  • JSON numbers without fractional parts (integer numbers) are represented as integers (major types 0 and 1, possibly major type 6, tag number 2 and 3), choosing the shortest form; integers longer than an implementation-defined threshold may instead be represented as floating-point values. The default range that is represented as integer is -253+1..253-1 (fully exploiting the range for exact integers in the binary64 representation often used for decoding JSON [RFC7493]). A CBOR-based protocol, or a generic converter implementation, may choose -232..232-1 or -264..264-1 (fully using the integer ranges available in CBOR with uint32_t or uint64_t, respectively) or even -231..231-1 or -263..263-1 (using popular ranges for two's complement signed integers). (If the JSON was generated from a JavaScript implementation, its precision is already limited to 53 bits maximum.)
  • Numbers with fractional parts are represented as floating-point values, performing the decimal-to-binary conversion based on the precision provided by IEEE 754 binary64. The mathematical value of the JSON number is converted to binary64 using the roundTiesToEven procedure in Section 4.3.1 of [IEEE754]. Then, when encoding in CBOR, the preferred serialization uses the shortest floating-point representation exactly representing this conversion result; for instance, 1.5 is represented in a 16-bit floating-point value (not all implementations will be capable of efficiently finding the minimum form, though). Instead of using the default binary64 precision, there may be an implementation-defined limit to the precision of the conversion that will affect the precision of the represented values. Decimal representation should only be used on the CBOR side if that is specified in a protocol.
  • 小数部を持たないJSON数値(整数)は、整数(メジャータイプ0および1、おそらくメジャータイプ6、タグ番号2および3)として表され、最短の形式が選択されます。実装定義の閾値よりも長い整数は、代わりに浮動小数点値として表される場合があります。整数として表されるデフォルトの範囲は、-253+1..253-1であり、(JSONデコードによく使用されるbinary64表現で正確な整数の範囲を完全に活用する)。 CBORベースのプロトコルまたは汎用コンバータ実装では、uint32_tまたはuint64_tで利用可能な整数範囲を完全に使用するために、-232..232-1または-264..264-1を選択することができます。また、2の補数符号付き整数の人気のある範囲である-231..231-1または-263..263-1を使用することもできます。 (JSONがJavaScript実装から生成された場合、その精度はすでに最大53ビットに制限されています。)
  • 小数部を持つ数値は、IEEE 754 binary64によって提供される精度に基づいて、浮動小数点値として表されます。JSON数値の数学的な値は、[IEEE754]のセクション4.3.1のroundTiesToEven手順を使用して、binary64に変換されます。その後、CBORでエンコードする際に、最短の浮動小数点表現が使用され、この変換結果を正確に表します。たとえば、1.5は16ビットの浮動小数点値で表されます(すべての実装が最小形式を効率的に見つけることができるわけではありません)。デフォルトのbinary64精度を使用する代わりに、変換の精度に影響を与える実装定義の精度制限がある場合があります。10進表記は、プロトコルで指定されている場合を除き、CBOR側でのみ使用する必要があります。

CBOR has been designed to generally provide a more compact encoding than JSON. One implementation strategy that might come to mind is to perform a JSON-to-CBOR encoding in place in a single buffer. This strategy would need to carefully consider a number of pathological cases, such as that some strings represented with no or very few escapes and longer (or much longer) than 255 bytes may expand when encoded as UTF-8 strings in CBOR. Similarly, a few of the binary floating-point representations might cause expansion from some short decimal representations (1.1, 1e9) in JSON. This may be hard to get right, and any ensuing vulnerabilities may be exploited by an attacker.

CBORは、一般的にJSONよりもコンパクトなエンコーディングを提供するように設計されています。1つの実装戦略は、JSON-to-CBORエンコーディングを単一のバッファ内で実行することです。この戦略では、いくつかの病的なケースを注意深く考慮する必要があります。たとえば、255バイトよりも長く(またははるかに長く)エスケープがない文字列がいくつかあり、CBORでUTF-8文字列としてエンコードされると拡張される可能性があります。同様に、一部のバイナリ浮動小数点表現は、JSONの短い10進表記(1.1、1e9)から拡張される可能性があります。これを正しく行うことは難しい場合があり、その後の脆弱性は攻撃者によって悪用される可能性があります。

Successful protocols evolve over time. New ideas appear, implementation platforms improve, related protocols are developed and evolve, and new requirements from applications and protocols are added. Facilitating protocol evolution is therefore an important design consideration for any protocol development.

成功したプロトコルは時間とともに進化します。新しいアイデアが現れ、実装プラットフォームが改善され、関連するプロトコルが開発および進化し、アプリケーションおよびプロトコルからの新しい要件が追加されます。そのため、プロトコルの進化を促進することは、プロトコル開発において重要な設計上の考慮事項です。

For protocols that will use CBOR, CBOR provides some useful mechanisms to facilitate their evolution. Best practices for this are well known, particularly from JSON format development of JSON-based protocols. Therefore, such best practices are outside the scope of this specification.

CBORを使用するプロトコルに対して、CBORはその進化を容易にするための有用なメカニズムを提供します。このため、JSONベースのプロトコルのJSON形式開発から、そのようなベストプラクティスがよく知られています。そのため、この仕様の範囲外で、そのようなベストプラクティスについては言及しません。

However, facilitating the evolution of CBOR itself is very well within its scope. CBOR is designed to both provide a stable basis for development of CBOR-based protocols and to be able to evolve. Since a successful protocol may live for decades, CBOR needs to be designed for decades of use and evolution. This section provides some guidance for the evolution of CBOR. It is necessarily more subjective than other parts of this document. It is also necessarily incomplete, lest it turn into a textbook on protocol development.

ただし、CBOR自体の進化を容易にすることは、その範囲内で非常にうまくいきます。CBORは、CBORベースのプロトコルの開発の安定した基盤を提供すると同時に、進化できるように設計されています。成功したプロトコルは数十年間生き残る可能性があるため、CBORは数十年間の使用と進化を考慮して設計する必要があります。このセクションでは、CBORの進化に関するいくつかのガイダンスを提供します。これは、このドキュメントの他の部分よりも主観的である必要があります。また、プロトコル開発の教科書にならないように、必然的に不完全である必要があります。

In a protocol design, opportunities for evolution are often included in the form of extension points. For example, there may be a codepoint space that is not fully allocated from the outset, and the protocol is designed to tolerate and embrace implementations that start using more codepoints than initially allocated.

プロトコル設計において、進化の機会はしばしば拡張ポイントの形で含まれます。たとえば、最初から完全に割り当てられていないコードポイントスペースがある場合があり、プロトコルは、最初に割り当てられたコードポイントよりも多くのコードポイントを使用し始める実装を許容し、受け入れるように設計されています。

Sizing the codepoint space may be difficult because the range required may be hard to predict. Protocol designs should attempt to make the codepoint space large enough so that it can slowly be filled over the intended lifetime of the protocol.

コードポイントスペースのサイズを決定することは困難な場合があります。必要な範囲を予測することが難しいためです。プロトコル設計では、コードポイントスペースが十分に大きくなるように設計する必要があります。これにより、プロトコルの寿命中にゆっくりと埋められるようになります。

CBOR has three major extension points:

CBOR has three major extension points:

the "simple" space (values in major type 7):
Of the 24 efficient (and 224 slightly less efficient) values, only a small number have been allocated. Implementations receiving an unknown simple data item may easily be able to process it as such, given that the structure of the value is indeed simple. The IANA registry in Section 9.1 is the appropriate way to address the extensibility of this codepoint space.
the "tag" space (values in major type 6):
The total codepoint space is abundant; only a tiny part of it has been allocated. However, not all of these codepoints are equally efficient: the first 24 only consume a single ("1+0") byte, and half of them have already been allocated. The next 232 values only consume two ("1+1") bytes, with nearly a quarter already allocated. These subspaces need some curation to last for a few more decades. Implementations receiving an unknown tag number can choose to process just the enclosed tag content or, preferably, to process the tag as an unknown tag number wrapping the tag content. The IANA registry in Section 9.2 is the appropriate way to address the extensibility of this codepoint space.
the "additional information" space:
An implementation receiving an unknown additional information value has no way to continue decoding, so allocating codepoints in this space is a major step beyond just exercising an extension point. There are also very few codepoints left. See also Section 7.2.
「simple」スペース(メジャータイプ7の値):
24の効率的な値(および224のやや効率的である値)のうち、ごくわずかしか割り当てられていません。不明なシンプルデータアイテムを受信した実装は、値の構造が実際にシンプルである場合、それを処理することができる場合があります。IANAレジストリは、このコードポイントスペースの拡張性をアドレスするための適切な方法です。Section 9.1
「tag」スペース(メジャータイプ6の値):
総コードポイントスペースは豊富ですが、そのうちごく一部しか割り当てられていません。ただし、これらのコードポイントがすべて同じ効率であるわけではありません。最初の24個は1つの(「1 + 0」)バイトしか消費せず、そのうちの半分がすでに割り当てられています。次の232個の値は2つの(「1 + 1」)バイトしか消費せず、そのうちの約4分の1がすでに割り当てられています。これらのサブスペースは、数十年間持続するためにいくつかの手入れが必要です。不明なタグ番号を受信した実装は、包含されたタグコンテンツだけを処理するか、好ましくは、タグコンテンツを包む不明なタグ番号としてタグを処理することができます。IANAレジストリは、このコードポイントスペースの拡張性をアドレスするための適切な方法です。Section 9.2
「additional information」スペース:
不明な追加情報値を受信した実装は、デコードを続行する方法がありません。したがって、このスペースにコードポイントを割り当てることは、拡張ポイントを実行する以上の大きなステップです。残りのコードポイントも非常に少ないです。詳細については、Section 7.2も参照してください。

The human mind is sometimes drawn to filling in little perceived gaps to make something neat. We expect the remaining gaps in the codepoint space for the additional information values to be an attractor for new ideas, just because they are there.

人間の心は、何かを整然とさせるために、時には小さな認識された隙間を埋めることに引き寄せられることがあります。追加情報値のコードポイントスペースの残りの隙間が、新しいアイデアの引き寄せ子になることを期待しています。それらがあるからです。

The present specification does not manage the additional information codepoint space by an IANA registry. Instead, allocations out of this space can only be done by updating this specification.

現在の仕様では、追加情報のコードポイントスペースはIANAレジストリによって管理されていません。このスペースからの割り当ては、この仕様を更新することによってのみ行うことができます。

For an additional information value of n >= 24, the size of the additional data typically is 2n-24 bytes. Therefore, additional information values 28 and 29 should be viewed as candidates for 128-bit and 256-bit quantities, in case a need arises to add them to the protocol. Additional information value 30 is then the only additional information value available for general allocation, and there should be a very good reason for allocating it before assigning it through an update of the present specification.

追加情報値n(n≥24)の場合、追加データのサイズは通常2n-24バイトです。したがって、追加情報値28および29は、プロトコルに追加する必要がある場合に128ビットおよび256ビットの数量の候補として見なす必要があります。追加情報値30は、一般的な割り当て用に利用可能な唯一の追加情報値であり、現在の仕様の更新を介して割り当てる前に非常に良い理由がある必要があります。

CBOR is a binary interchange format. To facilitate documentation and debugging, and in particular to facilitate communication between entities cooperating in debugging, this section defines a simple human-readable diagnostic notation. All actual interchange always happens in the binary format.

CBORはバイナリ交換形式です。ドキュメント作成およびデバッグを容易にするため、特にデバッグに協力するエンティティ間の通信を容易にするために、このセクションでは単純な人間が読める診断表記を定義します。実際の交換は常にバイナリ形式で行われます。

Note that this truly is a diagnostic format; it is not meant to be parsed. Therefore, no formal definition (as in ABNF) is given in this document. (Implementers looking for a text-based format for representing CBOR data items in configuration files may also want to consider YAML [YAML].)

これは本当に診断用のフォーマットであることに注意してください。解析することを意図していません。そのため、このドキュメントでは、ABNFのような形式的な定義は与えられていません。(構成ファイルでCBORデータアイテムを表現するためのテキストベースのフォーマットを探している実装者は、YAML [YAML]を検討することもできます。)

The diagnostic notation is loosely based on JSON as it is defined in RFC 8259, extending it where needed.

診断表記は、必要に応じて拡張されたRFC 8259で定義されているJSONに緩く基づいています。

The notation borrows the JSON syntax for numbers (integer and floating-point), True (>true<), False (>false<), Null (>null<), UTF-8 strings, arrays, and maps (maps are called objects in JSON; the diagnostic notation extends JSON here by allowing any data item in the key position). Undefined is written >undefined< as in JavaScript. The non-finite floating-point numbers Infinity, -Infinity, and NaN are written exactly as in this sentence (this is also a way they can be written in JavaScript, although JSON does not allow them). A tag is written as an integer number for the tag number, followed by the tag content in parentheses; for instance, a date in the format specified by RFC 3339 (ISO 8601) could be notated as:

この表記法は、JSONの数値(整数および浮動小数点)、True(>true<)、False(>false<)、Null(>null<)、UTF-8文字列、配列、およびマップ(JSONではマップはオブジェクトと呼ばれます。診断表記法は、キーの位置に任意のデータアイテムを許可することでJSONを拡張しています)。UndefinedはJavaScriptと同様に>undefined<と書かれます。非有限浮動小数点数のInfinity、-Infinity、およびNaNは、この文で書かれているように正確に書かれます(これはJavaScriptで書かれる方法でもありますが、JSONでは許可されていません)。タグは、タグ番号の整数値で書かれ、その後にタグコンテンツが括弧で囲まれて続きます。たとえば、RFC 3339(ISO 8601)で指定された形式の日付は、次のように表記されます。

0("2013-03-21T20:04:00Z")

0("2013-03-21T20:04:00Z")

or the equivalent relative time as the following:

または、次のような相対時間として表現されます。

1(1363896240)

1(1363896240)

Byte strings are notated in one of the base encodings, without padding, enclosed in single quotes, prefixed by >h< for base16, >b32< for base32, >h32< for base32hex, >b64< for base64 or base64url (the actual encodings do not overlap, so the string remains unambiguous). For example, the byte string 0x12345678 could be written h'12345678', b32'CI2FM6A', or b64'EjRWeA'.

バイト文字列は、パディングなしで、シングルクォートで囲まれ、ベースエンコーディングの1つで表記されます。ベース16の場合は、>h<、ベース32の場合は>b32<、ベース32hexの場合は>h32<、ベース64またはベース64urlの場合は>b64<で接頭辞が付きます(実際のエンコーディングは重複しないため、文字列は曖昧ではありません)。たとえば、バイト文字列0x12345678は、h'12345678'、b32'CI2FM6A'、またはb64'EjRWeA'として書くことができます。

Unassigned simple values are given as "simple()" with the appropriate integer in the parentheses. For example, "simple(42)" indicates major type 7, value 42.

未割り当てのシンプル値は、括弧内の適切な整数を伴う"simple()"として与えられます。たとえば、"simple(42)"は、メジャータイプ7、値42を示します。

A number of useful extensions to the diagnostic notation defined here are provided in Appendix G of [RFC8610], "Extended Diagnostic Notation" (EDN). Similarly, this notation could be extended in a separate document to provide documentation for NaN payloads, which are not covered in this document.

ここで定義された診断表記法には、[RFC8610]のAppendix Gで提供される「拡張診断表記法」(EDN)による診断表記法の有用な拡張がいくつかあります。 同様に、この表記法は、この文書ではカバーされていないNaNペイロードのドキュメントを提供するために、別の文書で拡張できます。

Sometimes it is useful to indicate in the diagnostic notation which of several alternative representations were actually used; for example, a data item written >1.5< by a diagnostic decoder might have been encoded as a half-, single-, or double-precision float.

診断表記法では、実際に使用された複数の代替表現のうち、どれが使用されたかを示すことがあると便利な場合があります。たとえば、診断デコーダーによって>1.5<と書かれたデータアイテムは、ハーフ、シングル、またはダブル精度の浮動小数点数としてエンコードされている可能性があります。

The convention for encoding indicators is that anything starting with an underscore and all following characters that are alphanumeric or underscore is an encoding indicator, and can be ignored by anyone not interested in this information. For example, _ or _3. Encoding indicators are always optional.

エンコーディングインジケータの規約は、アンダースコアで始まり、その後のすべての英数字またはアンダースコアがエンコーディングインジケータであることであり、この情報に関心のない人は無視できます。たとえば、_または_3。エンコーディングインジケータは常にオプションです。

A single underscore can be written after the opening brace of a map or the opening bracket of an array to indicate that the data item was represented in indefinite-length format. For example, [_ 1, 2] contains an indicator that an indefinite-length representation was used to represent the data item [1, 2].

マップの開始括弧の後または配列の開始括弧の後に単一のアンダースコアを書くことで、データアイテムが不定長形式で表現されたことを示すことができます。たとえば、[_ 1, 2]には、データアイテム[1, 2]が不定長形式で表現されたことを示すインジケータが含まれています。

An underscore followed by a decimal digit n indicates that the preceding item (or, for arrays and maps, the item starting with the preceding bracket or brace) was encoded with an additional information value of 24+n. For example, 1.5_1 is a half-precision floating-point number, while 1.5_3 is encoded as double precision. This encoding indicator is not shown in Appendix A. (Note that the encoding indicator "_" is thus an abbreviation of the full form "_7", which is not used.)

アンダースコアの後に10進数の数字nが続く場合、前のアイテム(または配列やマップの場合は、前の括弧またはブレースで始まるアイテム)が、追加情報値24+nでエンコードされたことを示します。たとえば、1.5_1は半精度浮動小数点数であり、1.5_3は倍精度でエンコードされます。このエンコーディングインジケータはAppendix Aには表示されません。(エンコーディングインジケータ"_"は、使用されない完全な形式"_7"の略語であることに注意してください。)

The detailed chunk structure of byte and text strings of indefinite length can be notated in the form (_ h'0123', h'4567') and (_ "foo", "bar"). However, for an indefinite-length string with no chunks inside, (_ ) would be ambiguous as to whether a byte string (0x5fff) or a text string (0x7fff) is meant and is therefore not used. The basic forms ''_ and ""_ can be used instead and are reserved for the case of no chunks only -- not as short forms for the (permitted, but not really useful) encodings with only empty chunks, which need to be notated as (_ ''), (_ ""), etc., to preserve the chunk structure.

不定長のバイト文字列とテキスト文字列の詳細なチャンク構造は、(_ h'0123', h'4567')および(_ "foo", "bar")の形式で表記できます。ただし、内部にチャンクがない不定長文字列の場合、(_ )はバイト文字列(0x5fff)またはテキスト文字列(0x7fff)のどちらを意味するか不明確であり、使用されません。 基本形式''_および""_は、チャンクがない場合にのみ使用でき、空のチャンクのみを持つ(許可されていますが、実際にはあまり有用ではない)エンコーディングは(_ '')、(_ "")などと表記する必要があります。チャンク構造を保持するために。

IANA has created two registries for new CBOR values. The registries are separate, that is, not under an umbrella registry, and follow the rules in [RFC8126]. IANA has also assigned a new media type, an associated CoAP Content-Format entry, and a structured syntax suffix.

IANAは、新しいCBOR値のために2つのレジストリを作成しました。レジストリは別々であり、傘下のレジストリではありません。また、[RFC8126]の規則に従います。IANAは、新しいメディアタイプ、関連するCoAPコンテンツフォーマットエントリ、および構造化構文接尾辞も割り当てました。

IANA has created the "Concise Binary Object Representation (CBOR) Simple Values" registry at [IANA.cbor-simple-values]. The initial values are shown in Table 4.

IANAは、[Concise Binary Object Representation (CBOR) Simple Values]レジストリを作成しました。初期値はTable 4に示されています。

New entries in the range 0 to 19 are assigned by Standards Action [RFC8126]. It is suggested that IANA allocate values starting with the number 16 in order to reserve the lower numbers for contiguous blocks (if any).

0から19の範囲の新しいエントリは、標準アクションによって割り当てられます。割り当ては、[RFC8126]によって行われます。連続するブロック(ある場合)の下位番号を予約するために、IANAが16から始まる値を割り当てることが提案されています。

New entries in the range 32 to 255 are assigned by Specification Required.

32から255の範囲の新しいエントリは、Specification Requiredによって割り当てられます。

IANA has created the "Concise Binary Object Representation (CBOR) Tags" registry at [IANA.cbor-tags]. The tags that were defined in [RFC7049] are described in detail in Section 3.4, and other tags have already been defined since then.

IANAは、[IANA.cbor-tags]において、「Concise Binary Object Representation (CBOR) Tags」レジストリを作成しました。[RFC7049]で定義されたタグについては、Section 3.4で詳しく説明されており、その後も他のタグが定義されています。

New entries in the range 0 to 23 ("1+0") are assigned by Standards Action. New entries in the ranges 24 to 255 ("1+1") and 256 to 32767 (lower half of "1+2") are assigned by Specification Required. New entries in the range 32768 to 18446744073709551615 (upper half of "1+2", "1+4", and "1+8") are assigned by First Come First Served. The template for registration requests is:

0から23の範囲の新しいエントリは、標準アクションによって割り当てられます。 24から255("1+1")および256から32767("1+2"の下位半分)の範囲の新しいエントリは、Specification Requiredによって割り当てられます。32768から18446744073709551615("1+2"の上位半分、"1+4"、および"1+8")の範囲の新しいエントリは、First Come First Servedによって割り当てられます。登録リクエストのテンプレートは以下のとおりです。

  • Data item
  • Semantics (short form)
  • データアイテム
  • 意味(短い形式)

In addition, First Come First Served requests should include:

さらに、First Come First Servedリクエストには、以下が含まれる必要があります。

  • Point of contact
  • Description of semantics (URL) -- This description is optional; the URL can point to something like an Internet-Draft or a web page.
  • 連絡先
  • 意味の説明(URL)-- この説明はオプションです。URLは、インターネットドラフトやWebページのようなものを指すことができます。

Applicants exercising the First Come First Served range and making a suggestion for a tag number that is not representable in 32 bits (i.e., larger than 4294967295) should be aware that this could reduce interoperability with implementations that do not support 64-bit numbers.

First Come First Served範囲を使用し、32ビットで表現できない(つまり、4294967295より大きい)タグ番号の提案を行う申請者は、64ビットの数値をサポートしていない実装との相互運用性が低下する可能性があることに注意する必要があります。

The Internet media type [RFC6838] ("MIME type") for a single encoded CBOR data item is "application/cbor" as defined in the "Media Types" registry [IANA.media-types]:

単一のエンコードされたCBORデータアイテムのインターネットメディアタイプ[RFC6838](「MIMEタイプ」)は、「Media Types」レジストリ[IANA.media-types]で定義されている「application/cbor」です。

Type name:
application
Subtype name:
cbor
Required parameters:
n/a
Optional parameters:
n/a
Encoding considerations:
Binary
Security considerations:
See Section 10 of RFC 8949.
Interoperability considerations:
n/a
Published specification:
RFC 8949
Applications that use this media type:
Many
Additional information:


Magic number(s):
n/a
File extension(s):
.cbor
Macintosh file type code(s):
n/a
Person & email address to contact for further information:
IETF CBOR Working Group (cbor@ietf.org) or IETF Applications and Real-Time Area (art@ietf.org)
Intended usage:
COMMON
Restrictions on usage:
none
Author:
IETF CBOR Working Group (cbor@ietf.org)
Change controller:
The IESG (iesg@ietf.org)
タイプ名:
application
サブタイプ名:
cbor
必須パラメータ:
なし
オプションパラメータ:
なし
エンコードに関する考慮事項:
バイナリ
セキュリティーに関する考慮事項:
RFC 8949Section 10を参照してください。
相互運用性に関する考慮事項:
なし
公開された仕様:
RFC 8949
このメディアタイプを使用するアプリケーション:
多数
追加情報:


マジックナンバー:
なし
ファイル拡張子:
.cbor
Macintoshファイルタイプコード:
なし
詳細情報の連絡先とメールアドレス:
IETF CBOR Working Group (cbor@ietf.org) または IETF Applications and Real-Time Area (art@ietf.org)
使用目的:
共通
使用上の制限:
なし
著者:
IETF CBOR Working Group (cbor@ietf.org)
変更管理者:
The IESG (iesg@ietf.org)

The CoAP Content-Format for CBOR has been registered in the "CoAP Content-Formats" subregistry within the "Constrained RESTful Environments (CoRE) Parameters" registry [IANA.core-parameters]:

CBORのCoAPコンテンツフォーマットは、「Constrained RESTful Environments (CoRE) Parameters」レジストリ[IANA.core-parameters]内の「CoAP Content-Formats」サブレジストリに登録されています。

Media Type:
application/cbor
Encoding:
-
ID:
60
Reference:
RFC 8949
メディアタイプ:
application/cbor
エンコーディング:
-
ID:
60
参照:
RFC 8949

The structured syntax suffix [RFC6838] for media types based on a single encoded CBOR data item is +cbor, which IANA has registered in the "Structured Syntax Suffixes" registry [IANA.structured-suffix]:

単一のエンコードされたCBORデータアイテムに基づくメディアタイプの構造化構文サフィックスは、+cborであり、IANAは「Structured Syntax Suffixes」レジストリ[IANA.structured-suffix]に登録しています。[RFC6838]

Name:
Concise Binary Object Representation (CBOR)
+suffix:
+cbor
References:
RFC 8949
Encoding Considerations:
CBOR is a binary format.
Interoperability Considerations:
n/a
Fragment Identifier Considerations:

The syntax and semantics of fragment identifiers specified for +cbor SHOULD be as specified for "application/cbor". (At publication of RFC 8949, there is no fragment identification syntax defined for "application/cbor".)

The syntax and semantics for fragment identifiers for a specific "xxx/yyy+cbor" SHOULD be processed as follows:

  • For cases defined in +cbor, where the fragment identifier resolves per the +cbor rules, then process as specified in +cbor.
  • For cases defined in +cbor, where the fragment identifier does not resolve per the +cbor rules, then process as specified in "xxx/yyy+cbor".
  • For cases not defined in +cbor, then process as specified in "xxx/yyy+cbor".
Security Considerations:
See Section 10 of RFC 8949.
Contact:
IETF CBOR Working Group (cbor@ietf.org) or IETF Applications and Real-Time Area (art@ietf.org)
Author/Change Controller:
IETF
名前:
Concise Binary Object Representation (CBOR)
+suffix:
+cbor
参照:
RFC 8949
エンコードに関する考慮事項:
CBORはバイナリ形式です。
相互運用性に関する考慮事項:
なし
フラグメント識別子に関する考慮事項:

+cborのために指定されたフラグメント識別子の構文と意味は、「application/cbor」のために指定されたものと同じであるべきです。(RFC 8949の発行時点では、「application/cbor」のためにフラグメント識別子の構文が定義されていません。)

特定の「xxx/yyy+cbor」のフラグメント識別子の構文と意味は、以下のように処理する必要があります。

  • +cborで定義された場合、フラグメント識別子が+cborのルールに従って解決される場合は、+cborで指定されたように処理します。
  • +cborで定義された場合、フラグメント識別子が+cborのルールに従って解決されない場合は、「xxx/yyy+cbor」で指定されたように処理します。
  • +cborで定義されていない場合は、「xxx/yyy+cbor」で指定されたように処理します。
セキュリティーに関する考慮事項:
RFC 8949Section 10を参照してください。
連絡先:
IETF CBOR Working Group (cbor@ietf.org) または IETF Applications and Real-Time Area (art@ietf.org)
著者/変更管理者:
IETF

A network-facing application can exhibit vulnerabilities in its processing logic for incoming data. Complex parsers are well known as a likely source of such vulnerabilities, such as the ability to remotely crash a node, or even remotely execute arbitrary code on it. CBOR attempts to narrow the opportunities for introducing such vulnerabilities by reducing parser complexity, by giving the entire range of encodable values a meaning where possible.

ネットワークに面したアプリケーションは、受信データの処理ロジックに脆弱性を示すことがあります。複雑なパーサは、ノードをリモートでクラッシュさせたり、さらにはリモートで任意のコードを実行できる可能性があるとして、そのような脆弱性の発生源としてよく知られています。CBORは、可能な限りエンコード可能な値の範囲に意味を与えることにより、パーサの複雑さを減らすことで、そのような脆弱性を導入する機会を狭めることを試みています。

Because CBOR decoders are often used as a first step in processing unvalidated input, they need to be fully prepared for all types of hostile input that may be designed to corrupt, overrun, or achieve control of the system decoding the CBOR data item. A CBOR decoder needs to assume that all input may be hostile even if it has been checked by a firewall, has come over a secure channel such as TLS, is encrypted or signed, or has come from some other source that is presumed trusted.

CBORデコーダーは、検証されていない入力を処理する最初のステップとしてしばしば使用されるため、CBORデータアイテムのデコードを行うシステムを破壊、オーバーラン、または制御するために設計されたあらゆる種類の攻撃的な入力に完全に対応する必要があります。CBORデコーダーは、ファイアウォールによってチェックされた、TLSのような安全なチャネルを介して送信された、暗号化または署名された、または信頼されると想定される他のソースから来た入力であっても、すべての入力が攻撃的であると想定する必要があります。

Section 4.1 gives examples of limitations in interoperability when using a constrained CBOR decoder with input from a CBOR encoder that uses a non-preferred serialization. When a single data item is consumed both by such a constrained decoder and a full decoder, it can lead to security issues that can be exploited by an attacker who can inject or manipulate content.

Section 4.1は、制限されたCBORデコーダーを使用して、非推奨のシリアライゼーションを使用するCBORエンコーダーからの入力を処理する場合の相互運用性の制限の例を示しています。制限されたデコーダーと完全なデコーダーの両方によって単一のデータアイテムが消費される場合、攻撃者がコンテンツを注入または操作できるセキュリティー問題が発生する可能性があります。

As discussed throughout this document, there are many values that can be considered "equivalent" in some circumstances and "not equivalent" in others. As just one example, the numeric value for the number "one" might be expressed as an integer or a bignum. A system interpreting CBOR input might accept either form for the number "one", or might reject one (or both) forms. Such acceptance or rejection can have security implications in the program that is using the interpreted input.

本文書全体で議論されているように、ある状況では「同等」と見なされる値が、他の状況では「非同等」と見なされることがあります。たとえば、数字の「1」の数値値は、整数またはビッグナンバーとして表現される可能性があります。CBOR入力を解釈するシステムは、「1」の数値に対してどちらの形式でも受け入れることができるか、またはどちらか(または両方)の形式を拒否できます。そのような受け入れまたは拒否は、解釈された入力を使用しているプログラムにセキュリティー上の影響を与える可能性があります。

Hostile input may be constructed to overrun buffers, to overflow or underflow integer arithmetic, or to cause other decoding disruption. CBOR data items might have lengths or sizes that are intentionally extremely large or too short. Resource exhaustion attacks might attempt to lure a decoder into allocating very big data items (strings, arrays, maps, or even arbitrary precision numbers) or exhaust the stack depth by setting up deeply nested items. Decoders need to have appropriate resource management to mitigate these attacks. (Items for which very large sizes are given can also attempt to exploit integer overflow vulnerabilities.)

敵対的な入力は、バッファをオーバーランしたり、整数演算をオーバーフローまたはアンダーフローさせたり、または他のデコードの妨害を引き起こすために構築される可能性があります。CBORデータアイテムには、意図的に非常に大きな長さやサイズがある場合があります。 リソース枯渇攻撃は、非常に大きなデータアイテム(文字列、配列、マップ、または任意の精度の数値)を割り当てさせたり、深くネストされたアイテムを設定することでスタックの深さを枯渇させたりすることを試みる場合があります。デコーダーは、これらの攻撃を緩和するために適切なリソース管理を持つ必要があります。 (非常に大きなサイズが指定されたアイテムは、整数オーバーフローの脆弱性を悪用することも試みることができます。)

A CBOR decoder, by definition, only accepts well-formed CBOR; this is the first step to its robustness. Input that is not well-formed CBOR causes no further processing from the point where the lack of well-formedness was detected. If possible, any data decoded up to this point should have no impact on the application using the CBOR decoder.

CBORデコーダーは、定義により、ウェルフォームなCBORのみを受け入れます。これは、その堅牢性にとって最初のステップです。ウェルフォームでないCBORの入力は、ウェルフォームでない部分が検出された時点からの処理を引き起こしません。可能であれば、この時点までにデコードされたデータは、CBORデコーダーを使用するアプリケーションに影響を与えないようにする必要があります。

In addition to ascertaining well-formedness, a CBOR decoder might also perform validity checks on the CBOR data. Alternatively, it can leave those checks to the application using the decoder. This choice needs to be clearly documented in the decoder. Beyond the validity at the CBOR level, an application also needs to ascertain that the input is in alignment with the application protocol that is serialized in CBOR.

CBORデコーダーは、ウェルフォームを確認するだけでなく、CBORデータに対して妥当性チェックを実行することもできます。また、それらのチェックをデコーダーを使用するアプリケーションに任せることもできます。この選択は、デコーダーで明確に文書化する必要があります。CBORレベルでの妥当性に加えて、アプリケーションは、CBORでシリアル化されたアプリケーションプロトコルと整合していることを確認する必要があります。

The input check itself may consume resources. This is usually linear in the size of the input, which means that an attacker has to spend resources that are commensurate to the resources spent by the defender on input validation. However, an attacker might be able to craft inputs that will take longer for a target decoder to process than for the attacker to produce. Processing for arbitrary-precision numbers may exceed linear effort. Also, some hash-table implementations that are used by decoders to build in-memory representations of maps can be attacked to spend quadratic effort, unless a secret key (see Section 7 of [SIPHASH_LNCS], also [SIPHASH_OPEN]) or some other mitigation is employed. Such superlinear efforts can be exploited by an attacker to exhaust resources at or before the input validator; they therefore need to be avoided in a CBOR decoder implementation. Note that tag number definitions and their implementations can add security considerations of this kind; this should then be discussed in the security considerations of the tag number definition.

入力チェック自体がリソースを消費する可能性があります。これは通常、入力のサイズに比例して線形になるため、攻撃者は防御側が入力検証に費やすリソースに相当するリソースを費やす必要があります。 ただし、攻撃者は、ターゲットデコーダーが処理するのに攻撃者が生成するよりも長い時間がかかる入力を作成できる場合があります。 任意精度の数値の処理は、線形努力を超える場合があります。また、デコーダーがマップのインメモリ表現を構築するために使用するハッシュテーブルの実装には、秘密鍵([SIPHASH_LNCS]のセクション7も参照してください。また、[SIPHASH_OPEN])または他の緩和策が採用されていない限り、二次努力を費やす攻撃ができます。 このような超線形の努力は、入力検証前または入力検証時にリソースを枯渇させるため、攻撃者によって悪用される可能性があるため、CBORデコーダーの実装では避ける必要があります。タグ番号の定義とその実装は、このようなセキュリティー上の考慮事項を追加する可能性があります。その場合は、タグ番号の定義のセキュリティー上の考慮事項で議論する必要があります。

CBOR encoders do not receive input directly from the network and are thus not directly attackable in the same way as CBOR decoders. However, CBOR encoders often have an API that takes input from another level in the implementation and can be attacked through that API. The design and implementation of that API should assume the behavior of its caller may be based on hostile input or on coding mistakes. It should check inputs for buffer overruns, overflow and underflow of integer arithmetic, and other such errors that are aimed to disrupt the encoder.

CBORエンコーダーは、ネットワークから直接入力を受け取らず、CBORデコーダーと同じ方法で直接攻撃されることはありません。ただし、CBORエンコーダーには、実装の別のレベルから入力を受け取るAPIがしばしばあり、そのAPIを介して攻撃される可能性があります。そのAPIの設計と実装は、呼び出し元の動作が攻撃的な入力またはコーディングのミスに基づく可能性があることを前提とする必要があります。バッファオーバーラン、整数演算のオーバーフローおよびアンダーフロー、およびその他のエラーなど、エンコーダーを妨害することを目的としたエラーをチェックする必要があります。

Protocols should be defined in such a way that potential multiple interpretations are reliably reduced to a single interpretation. For example, an attacker could make use of invalid input such as duplicate keys in maps, or exploit different precision in processing numbers to make one application base its decisions on a different interpretation than the one that will be used by a second application. To facilitate consistent interpretation, encoder and decoder implementations should provide a validity-checking mode of operation (Section 5.4). Note, however, that a generic decoder cannot know about all requirements that an application poses on its input data; it is therefore not relieving the application from performing its own input checking. Also, since the set of defined tag numbers evolves, the application may employ a tag number that is not yet supported for validity checking by the generic decoder it uses. Generic decoders therefore need to document which tag numbers they support and what validity checking they provide for those tag numbers as well as for basic CBOR (UTF-8 checking, duplicate map key checking).

プロトコルは、潜在的な複数の解釈が確実に単一の解釈に減少するように定義する必要があります。たとえば、攻撃者は、マップ内の重複したキーなどの無効な入力を利用したり、数値の処理における異なる精度を悪用したりして、1つのアプリケーションが2番目のアプリケーションで使用される解釈とは異なる解釈に基づいて決定を下すようにできます。一貫した解釈を容易にするために、エンコーダーとデコーダーの実装は、動作モードでの妥当性チェックを提供する必要があります(Section 5.4)。ただし、一般的なデコーダーは、アプリケーションが入力データに対して要求するすべての要件を知ることができないため、アプリケーションが独自の入力チェックを実行することから解放されるわけではありません。また、定義されたタグ番号のセットが進化するため、アプリケーションは、使用する一般的なデコーダーでまだ妥当性チェックがサポートされていないタグ番号を使用する場合があります。一般的なデコーダーは、サポートするタグ番号と、それらのタグ番号に対して提供する妥当性チェック、および基本的なCBOR(UTF-8チェック、重複マップキーのチェック)に対して提供する妥当性チェックを文書化する必要があります。

Section 3.4.3 notes that using the non-preferred choice of a bignum representation instead of a basic integer for encoding a number is not intended to have application semantics, but it can have such semantics if an application receiving CBOR data is using a decoder in the basic generic data model. This disparity causes a security issue if the two sets of semantics differ. Thus, applications using CBOR need to specify the data model that they are using for each use of CBOR data.

Section 3.4.3は、数値をエンコードするために基本的な整数の代わりにビッグナンバー表現を使用することは、アプリケーションの意味論を持つことを意図していないことを示していますが、CBORデータを受信するアプリケーションが基本的な汎用データモデルのデコーダーを使用している場合、そのような意味論を持つことがあります。この不一致は、2つの意味論が異なる場合にセキュリティー上の問題を引き起こす可能性があります。したがって、CBORを使用するアプリケーションは、CBORデータの各使用について使用しているデータモデルを指定する必要があります。

It is common to convert CBOR data to other formats. In many cases, CBOR has more expressive types than other formats; this is particularly true for the common conversion to JSON. The loss of type information can cause security issues for the systems that are processing the less-expressive data.

CBORデータを他の形式に変換することは一般的です。多くの場合、CBORには他の形式よりも表現力の高い型があります。これは、JSONへの一般的な変換にとくに当てはまります。型情報の欠落は、表現力の低いデータを処理しているシステムにセキュリティー上の問題を引き起こす可能性があります。

Section 6.2 describes a possibly common usage scenario of converting between CBOR and JSON that could allow an attack if the attacker knows that the application is performing the conversion.

Section 6.2は、CBORとJSONの間で変換する可能性のある一般的な使用シナリオを説明しており、攻撃者がアプリケーションが変換を実行していることを知っている場合、攻撃を許可する可能性があります。

Security considerations for the use of base16 and base64 from [RFC4648], and the use of UTF-8 from [RFC3629], are relevant to CBOR as well.

CBORに関しては、[RFC4648]で定義されたbase16およびbase64の使用、および[RFC3629]で定義されたUTF-8の使用に関するセキュリティー上の考慮事項が関連しています。

References

Normative References

[C]
International Organization for Standardization, "Information technology - Programming languages - C", , ISO/IEC 9899:2018, , <https://www.iso.org/standard/74528.html>
[Cplusplus20]
International Organization for Standardization, "Programming languages - C++", , ISO/IEC DIS 14882, ISO/IEC ISO/IEC JTC1 SC22 WG21 N 4860, , <https://isocpp.org/files/papers/N4860.pdf>
[IEEE754]
IEEE, "IEEE Standard for Floating-Point Arithmetic", IEEE Std 754-2019, DOI 10.1109/IEEESTD.2019.8766229, <https://ieeexplore.ieee.org/document/8766229>
[RFC2045]
Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", RFC 2045, DOI 10.17487/RFC2045, , <https://www.rfc-editor.org/info/rfc2045>
[RFC2119]
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/info/rfc2119>
[RFC3339]
Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/info/rfc3339>
[RFC3629]
Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, , <https://www.rfc-editor.org/info/rfc3629>
[RFC3986]
Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, , <https://www.rfc-editor.org/info/rfc3986>
[RFC4287]
Nottingham, M. and R. Sayre, "The Atom Syndication Format", RFC 4287, DOI 10.17487/RFC4287, , <https://www.rfc-editor.org/info/rfc4287>
[RFC4648]
Josefsson, S., "The Base16, Base32, and Base64 Data Encodings", RFC 4648, DOI 10.17487/RFC4648, , <https://www.rfc-editor.org/info/rfc4648>
[RFC8126]
Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/info/rfc8126>
[RFC8174]
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/info/rfc8174>
[TIME_T]
The Open Group, "The Open Group Base Specifications", , , IEEE Std 1003.1, , <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16>

Informative References

[ASN.1]
International Telecommunication Union, "Information Technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)", ITU-T Recommendation X.690, , <https://www.itu.int/rec/T-REC-X.690-201508-I/en>
[BSON]
Various, "BSON - Binary JSON", <http://bsonspec.org/>
[CBOR-TAGS]
Bormann, C., "Notable CBOR Tags", , Internet-Draft draft-bormann-cbor-notable-tags-02, , <https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02>
[ECMA262]
Ecma International, "ECMAScript 2020 Language Specification", , , <https://www.ecma-international.org/publications/standards/Ecma-262.htm>
[Err3764]
RFC Errata, Erratum ID 3764, , <https://www.rfc-editor.org/errata/eid3764>
[Err3770]
RFC Errata, Erratum ID 3770, , <https://www.rfc-editor.org/errata/eid3770>
[Err4294]
RFC Errata, Erratum ID 4294, , <https://www.rfc-editor.org/errata/eid4294>
[Err4409]
RFC Errata, Erratum ID 4409, , <https://www.rfc-editor.org/errata/eid4409>
[Err4963]
RFC Errata, Erratum ID 4963, , <https://www.rfc-editor.org/errata/eid4963>
[Err4964]
RFC Errata, Erratum ID 4964, , <https://www.rfc-editor.org/errata/eid4964>
[Err5434]
RFC Errata, Erratum ID 5434, , <https://www.rfc-editor.org/errata/eid5434>
[Err5763]
RFC Errata, Erratum ID 5763, , <https://www.rfc-editor.org/errata/eid5763>
[Err5917]
RFC Errata, Erratum ID 5917, , <https://www.rfc-editor.org/errata/eid5917>
[IANA.cbor-simple-values]
IANA, "Concise Binary Object Representation (CBOR) Simple Values", <https://www.iana.org/assignments/cbor-simple-values>
[IANA.cbor-tags]
IANA, "Concise Binary Object Representation (CBOR) Tags", <https://www.iana.org/assignments/cbor-tags>
[IANA.core-parameters]
IANA, "Constrained RESTful Environments (CoRE) Parameters", <https://www.iana.org/assignments/core-parameters>
[IANA.media-types]
IANA, "Media Types", <https://www.iana.org/assignments/media-types>
[IANA.structured-suffix]
IANA, "Structured Syntax Suffixes", <https://www.iana.org/assignments/media-type-structured-suffix>
[MessagePack]
Furuhashi, S., "MessagePack", <https://msgpack.org/>
[PCRE]
Hazel, P., "PCRE - Perl Compatible Regular Expressions", <https://www.pcre.org/>
[RFC0713]
Haverty, J., "MSDTP-Message Services Data Transmission Protocol", RFC 713, DOI 10.17487/RFC0713, , <https://www.rfc-editor.org/info/rfc713>
[RFC6838]
Freed, N., Klensin, J., and T. Hansen, "Media Type Specifications and Registration Procedures", BCP 13, RFC 6838, DOI 10.17487/RFC6838, , <https://www.rfc-editor.org/info/rfc6838>
[RFC7049]
Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, , <https://www.rfc-editor.org/info/rfc7049>
[RFC7228]
Bormann, C., Ersue, M., and A. Keranen, "Terminology for Constrained-Node Networks", RFC 7228, DOI 10.17487/RFC7228, , <https://www.rfc-editor.org/info/rfc7228>
[RFC7493]
Bray, T., "The I-JSON Message Format", RFC 7493, DOI 10.17487/RFC7493, , <https://www.rfc-editor.org/info/rfc7493>
[RFC7991]
Hoffman, P., "The "xml2rfc" Version 3 Vocabulary", RFC 7991, DOI 10.17487/RFC7991, , <https://www.rfc-editor.org/info/rfc7991>
[RFC8259]
Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", STD 90, RFC 8259, DOI 10.17487/RFC8259, , <https://www.rfc-editor.org/info/rfc8259>
[RFC8610]
Birkholz, H., Vigano, C., and C. Bormann, "Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, , <https://www.rfc-editor.org/info/rfc8610>
[RFC8618]
Dickinson, J., Hague, J., Dickinson, S., Manderson, T., and J. Bond, "Compacted-DNS (C-DNS): A Format for DNS Packet Capture", RFC 8618, DOI 10.17487/RFC8618, , <https://www.rfc-editor.org/info/rfc8618>
[RFC8742]
Bormann, C., "Concise Binary Object Representation (CBOR) Sequences", RFC 8742, DOI 10.17487/RFC8742, , <https://www.rfc-editor.org/info/rfc8742>
[RFC8746]
Bormann, C., "Concise Binary Object Representation (CBOR) Tags for Typed Arrays", RFC 8746, DOI 10.17487/RFC8746, , <https://www.rfc-editor.org/info/rfc8746>
[SIPHASH_LNCS]
Aumasson, J. and D. Bernstein, "SipHash: A Fast Short-Input PRF", , DOI 10.1007/978-3-642-34931-7_28, , <https://doi.org/10.1007/978-3-642-34931-7_28>
[SIPHASH_OPEN]
Aumasson, J. and D.J. Bernstein, "SipHash: a fast short-input PRF", <https://www.aumasson.jp/siphash/siphash.pdf>
[YAML]
Ben-Kiki, O., Evans, C., and I.d. Net, "YAML Ain't Markup Language (YAML[TM]) Version 1.2", , , <https://www.yaml.org/spec/1.2/spec.html>

参考文献

引用規格

[C]
International Organization for Standardization, "Information technology - Programming languages - C", , ISO/IEC 9899:2018, , <https://www.iso.org/standard/74528.html>
[Cplusplus20]
International Organization for Standardization, "Programming languages - C++", , ISO/IEC DIS 14882, ISO/IEC ISO/IEC JTC1 SC22 WG21 N 4860, , <https://isocpp.org/files/papers/N4860.pdf>
[IEEE754]
IEEE, "IEEE Standard for Floating-Point Arithmetic", IEEE Std 754-2019, DOI 10.1109/IEEESTD.2019.8766229, <https://ieeexplore.ieee.org/document/8766229>
[RFC2045]
Freed, N. and N. Borenstein, "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies", RFC 2045, DOI 10.17487/RFC2045, , <https://www.rfc-editor.org/info/rfc2045>
[RFC2119]
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/info/rfc2119>
[RFC3339]
Klyne, G. and C. Newman, "Date and Time on the Internet: Timestamps", RFC 3339, DOI 10.17487/RFC3339, , <https://www.rfc-editor.org/info/rfc3339>
[RFC3629]
Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, , <https://www.rfc-editor.org/info/rfc3629>
[RFC3986]
Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, DOI 10.17487/RFC3986, , <https://www.rfc-editor.org/info/rfc3986>
[RFC4287]
Nottingham, M. and R. Sayre, "The Atom Syndication Format", RFC 4287, DOI 10.17487/RFC4287, , <https://www.rfc-editor.org/info/rfc4287>
[RFC4648]
Josefsson, S., "The Base16, Base32, and Base64 Data Encodings", RFC 4648, DOI 10.17487/RFC4648, , <https://www.rfc-editor.org/info/rfc4648>
[RFC8126]
Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, , <https://www.rfc-editor.org/info/rfc8126>
[RFC8174]
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/info/rfc8174>
[TIME_T]
The Open Group, "The Open Group Base Specifications", , , IEEE Std 1003.1, , <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16>

参考文献

[ASN.1]
International Telecommunication Union, "Information Technology - ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER)", ITU-T Recommendation X.690, , <https://www.itu.int/rec/T-REC-X.690-201508-I/en>
[BSON]
Various, "BSON - Binary JSON", <http://bsonspec.org/>
[CBOR-TAGS]
Bormann, C., "Notable CBOR Tags", , Internet-Draft draft-bormann-cbor-notable-tags-02, , <https://tools.ietf.org/html/draft-bormann-cbor-notable-tags-02>
[ECMA262]
Ecma International, "ECMAScript 2020 Language Specification", , , <https://www.ecma-international.org/publications/standards/Ecma-262.htm>
[Err3764]
RFC Errata, Erratum ID 3764, , <https://www.rfc-editor.org/errata/eid3764>
[Err3770]
RFC Errata, Erratum ID 3770, , <https://www.rfc-editor.org/errata/eid3770>
[Err4294]
RFC Errata, Erratum ID 4294, , <https://www.rfc-editor.org/errata/eid4294>
[Err4409]
RFC Errata, Erratum ID 4409, , <https://www.rfc-editor.org/errata/eid4409>
[Err4963]
RFC Errata, Erratum ID 4963, , <https://www.rfc-editor.org/errata/eid4963>
[Err4964]
RFC Errata, Erratum ID 4964, , <https://www.rfc-editor.org/errata/eid4964>
[Err5434]
RFC Errata, Erratum ID 5434, , <https://www.rfc-editor.org/errata/eid5434>
[Err5763]
RFC Errata, Erratum ID 5763, , <https://www.rfc-editor.org/errata/eid5763>
[Err5917]
RFC Errata, Erratum ID 5917, , <https://www.rfc-editor.org/errata/eid5917>
[IANA.cbor-simple-values]
IANA, "Concise Binary Object Representation (CBOR) Simple Values", <https://www.iana.org/assignments/cbor-simple-values>
[IANA.cbor-tags]
IANA, "Concise Binary Object Representation (CBOR) Tags", <https://www.iana.org/assignments/cbor-tags>
[IANA.core-parameters]
IANA, "Constrained RESTful Environments (CoRE) Parameters", <https://www.iana.org/assignments/core-parameters>
[IANA.media-types]
IANA, "Media Types", <https://www.iana.org/assignments/media-types>
[IANA.structured-suffix]
IANA, "Structured Syntax Suffixes", <https://www.iana.org/assignments/media-type-structured-suffix>
[MessagePack]
Furuhashi, S., "MessagePack", <https://msgpack.org/>
[PCRE]
Hazel, P., "PCRE - Perl Compatible Regular Expressions", <https://www.pcre.org/>
[RFC0713]
Haverty, J., "MSDTP-Message Services Data Transmission Protocol", RFC 713, DOI 10.17487/RFC0713, , <https://www.rfc-editor.org/info/rfc713>
[RFC6838]
Freed, N., Klensin, J., and T. Hansen, "Media Type Specifications and Registration Procedures", BCP 13, RFC 6838, DOI 10.17487/RFC6838, , <https://www.rfc-editor.org/info/rfc6838>
[RFC7049]
Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, , <https://www.rfc-editor.org/info/rfc7049>
[RFC7228]
Bormann, C., Ersue, M., and A. Keranen, "Terminology for Constrained-Node Networks", RFC 7228, DOI 10.17487/RFC7228, , <https://www.rfc-editor.org/info/rfc7228>
[RFC7493]
Bray, T., "The I-JSON Message Format", RFC 7493, DOI 10.17487/RFC7493, , <https://www.rfc-editor.org/info/rfc7493>
[RFC7991]
Hoffman, P., "The "xml2rfc" Version 3 Vocabulary", RFC 7991, DOI 10.17487/RFC7991, , <https://www.rfc-editor.org/info/rfc7991>
[RFC8259]
Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", STD 90, RFC 8259, DOI 10.17487/RFC8259, , <https://www.rfc-editor.org/info/rfc8259>
[RFC8610]
Birkholz, H., Vigano, C., and C. Bormann, "Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, , <https://www.rfc-editor.org/info/rfc8610>
[RFC8618]
Dickinson, J., Hague, J., Dickinson, S., Manderson, T., and J. Bond, "Compacted-DNS (C-DNS): A Format for DNS Packet Capture", RFC 8618, DOI 10.17487/RFC8618, , <https://www.rfc-editor.org/info/rfc8618>
[RFC8742]
Bormann, C., "Concise Binary Object Representation (CBOR) Sequences", RFC 8742, DOI 10.17487/RFC8742, , <https://www.rfc-editor.org/info/rfc8742>
[RFC8746]
Bormann, C., "Concise Binary Object Representation (CBOR) Tags for Typed Arrays", RFC 8746, DOI 10.17487/RFC8746, , <https://www.rfc-editor.org/info/rfc8746>
[SIPHASH_LNCS]
Aumasson, J. and D. Bernstein, "SipHash: A Fast Short-Input PRF", , DOI 10.1007/978-3-642-34931-7_28, , <https://doi.org/10.1007/978-3-642-34931-7_28>
[SIPHASH_OPEN]
Aumasson, J. and D.J. Bernstein, "SipHash: a fast short-input PRF", <https://www.aumasson.jp/siphash/siphash.pdf>
[YAML]
Ben-Kiki, O., Evans, C., and I.d. Net, "YAML Ain't Markup Language (YAML[TM]) Version 1.2", , , <https://www.yaml.org/spec/1.2/spec.html>

𐅑

𐅑

Table 6: Examples of Encoded CBOR Data Items
Diagnostic Encoded
0 0x00
1 0x01
10 0x0a
23 0x17
24 0x1818
25 0x1819
100 0x1864
1000 0x1903e8
1000000 0x1a000f4240
1000000000000 0x1b000000e8d4a51000
18446744073709551615 0x1bffffffffffffffff
18446744073709551616 0xc249010000000000000000
-18446744073709551616 0x3bffffffffffffffff
-18446744073709551617 0xc349010000000000000000
-1 0x20
-10 0x29
-100 0x3863
-1000 0x3903e7
0.0 0xf90000
-0.0 0xf98000
1.0 0xf93c00
1.1 0xfb3ff199999999999a
1.5 0xf93e00
65504.0 0xf97bff
100000.0 0xfa47c35000
3.4028234663852886e+38 0xfa7f7fffff
1.0e+300 0xfb7e37e43c8800759c
5.960464477539063e-8 0xf90001
0.00006103515625 0xf90400
-4.0 0xf9c400
-4.1 0xfbc010666666666666
Infinity 0xf97c00
NaN 0xf97e00
-Infinity 0xf9fc00
Infinity 0xfa7f800000
NaN 0xfa7fc00000
-Infinity 0xfaff800000
Infinity 0xfb7ff0000000000000
NaN 0xfb7ff8000000000000
-Infinity 0xfbfff0000000000000
false 0xf4
true 0xf5
null 0xf6
undefined 0xf7
simple(16) 0xf0
simple(255) 0xf8ff
0("2013-03-21T20:04:00Z") 0xc074323031332d30332d32315432303a 30343a30305a
1(1363896240) 0xc11a514b67b0
1(1363896240.5) 0xc1fb41d452d9ec200000
23(h'01020304') 0xd74401020304
24(h'6449455446') 0xd818456449455446
32("http://www.example.com") 0xd82076687474703a2f2f7777772e6578 616d706c652e636f6d
h'' 0x40
h'01020304' 0x4401020304
"" 0x60
"a" 0x6161
"IETF" 0x6449455446
"\"\\" 0x62225c
"\u00fc" 0x62c3bc
"\u6c34" 0x63e6b0b4
"\ud800\udd51" 0x64f0908591
[] 0x80
[1, 2, 3] 0x83010203
[1, [2, 3], [4, 5]] 0x8301820203820405
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] 0x98190102030405060708090a0b0c0d0e 0f101112131415161718181819
{} 0xa0
{1: 2, 3: 4} 0xa201020304
{"a": 1, "b": [2, 3]} 0xa26161016162820203
["a", {"b": "c"}] 0x826161a161626163
{"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"} 0xa5616161416162614261636143616461 4461656145
(_ h'0102', h'030405') 0x5f42010243030405ff
(_ "strea", "ming") 0x7f657374726561646d696e67ff
[_ ] 0x9fff
[_ 1, [2, 3], [_ 4, 5]] 0x9f018202039f0405ffff
[_ 1, [2, 3], [4, 5]] 0x9f01820203820405ff
[1, [2, 3], [_ 4, 5]] 0x83018202039f0405ff
[1, [_ 2, 3], [4, 5]] 0x83019f0203ff820405
[_ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] 0x9f0102030405060708090a0b0c0d0e0f 101112131415161718181819ff
{_ "a": 1, "b": [_ 2, 3]} 0xbf61610161629f0203ffff
["a", {_ "b": "c"}] 0x826161bf61626163ff
{_ "Fun": true, "Amt": -2} 0xbf6346756ef563416d7421ff
表 6: Examples of Encoded CBOR Data Items
Diagnostic Encoded
0 0x00
1 0x01
10 0x0a
23 0x17
24 0x1818
25 0x1819
100 0x1864
1000 0x1903e8
1000000 0x1a000f4240
1000000000000 0x1b000000e8d4a51000
18446744073709551615 0x1bffffffffffffffff
18446744073709551616 0xc249010000000000000000
-18446744073709551616 0x3bffffffffffffffff
-18446744073709551617 0xc349010000000000000000
-1 0x20
-10 0x29
-100 0x3863
-1000 0x3903e7
0.0 0xf90000
-0.0 0xf98000
1.0 0xf93c00
1.1 0xfb3ff199999999999a
1.5 0xf93e00
65504.0 0xf97bff
100000.0 0xfa47c35000
3.4028234663852886e+38 0xfa7f7fffff
1.0e+300 0xfb7e37e43c8800759c
5.960464477539063e-8 0xf90001
0.00006103515625 0xf90400
-4.0 0xf9c400
-4.1 0xfbc010666666666666
Infinity 0xf97c00
NaN 0xf97e00
-Infinity 0xf9fc00
Infinity 0xfa7f800000
NaN 0xfa7fc00000
-Infinity 0xfaff800000
Infinity 0xfb7ff0000000000000
NaN 0xfb7ff8000000000000
-Infinity 0xfbfff0000000000000
false 0xf4
true 0xf5
null 0xf6
undefined 0xf7
simple(16) 0xf0
simple(255) 0xf8ff
0("2013-03-21T20:04:00Z") 0xc074323031332d30332d32315432303a 30343a30305a
1(1363896240) 0xc11a514b67b0
1(1363896240.5) 0xc1fb41d452d9ec200000
23(h'01020304') 0xd74401020304
24(h'6449455446') 0xd818456449455446
32("http://www.example.com") 0xd82076687474703a2f2f7777772e6578 616d706c652e636f6d
h'' 0x40
h'01020304' 0x4401020304
"" 0x60
"a" 0x6161
"IETF" 0x6449455446
"\"\\" 0x62225c
"\u00fc" 0x62c3bc
"\u6c34" 0x63e6b0b4
"\ud800\udd51" 0x64f0908591
[] 0x80
[1, 2, 3] 0x83010203
[1, [2, 3], [4, 5]] 0x8301820203820405
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] 0x98190102030405060708090a0b0c0d0e 0f101112131415161718181819
{} 0xa0
{1: 2, 3: 4} 0xa201020304
{"a": 1, "b": [2, 3]} 0xa26161016162820203
["a", {"b": "c"}] 0x826161a161626163
{"a": "A", "b": "B", "c": "C", "d": "D", "e": "E"} 0xa5616161416162614261636143616461 4461656145
(_ h'0102', h'030405') 0x5f42010243030405ff
(_ "strea", "ming") 0x7f657374726561646d696e67ff
[_ ] 0x9fff
[_ 1, [2, 3], [_ 4, 5]] 0x9f018202039f0405ffff
[_ 1, [2, 3], [4, 5]] 0x9f01820203820405ff
[1, [2, 3], [_ 4, 5]] 0x83018202039f0405ff
[1, [_ 2, 3], [4, 5]] 0x83019f0203ff820405
[_ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] 0x9f0102030405060708090a0b0c0d0e0f 101112131415161718181819ff
{_ "a": 1, "b": [_ 2, 3]} 0xbf61610161629f0203ffff
["a", {_ "b": "c"}] 0x826161bf61626163ff
{_ "Fun": true, "Amt": -2} 0xbf6346756ef563416d7421ff

For brevity, this jump table does not show initial bytes that are reserved for future extension. It also only shows a selection of the initial bytes that can be used for optional features. (All unsigned integers are in network byte order.)

簡潔さのために、このジャンプテーブルには将来の拡張のために予約された初期バイトは表示されません。また、オプションの機能に使用できる初期バイトの選択のみを表示します。 (すべての符号なし整数はネットワークバイトオーダーで表されます。)

Table 7: Jump Table for Initial Byte
Byte Structure/Semantics
0x00..0x17 unsigned integer 0x00..0x17 (0..23)
0x18 unsigned integer (one-byte uint8_t follows)
0x19 unsigned integer (two-byte uint16_t follows)
0x1a unsigned integer (four-byte uint32_t follows)
0x1b unsigned integer (eight-byte uint64_t follows)
0x20..0x37 negative integer -1-0x00..-1-0x17 (-1..-24)
0x38 negative integer -1-n (one-byte uint8_t for n follows)
0x39 negative integer -1-n (two-byte uint16_t for n follows)
0x3a negative integer -1-n (four-byte uint32_t for n follows)
0x3b negative integer -1-n (eight-byte uint64_t for n follows)
0x40..0x57 byte string (0x00..0x17 bytes follow)
0x58 byte string (one-byte uint8_t for n, and then n bytes follow)
0x59 byte string (two-byte uint16_t for n, and then n bytes follow)
0x5a byte string (four-byte uint32_t for n, and then n bytes follow)
0x5b byte string (eight-byte uint64_t for n, and then n bytes follow)
0x5f byte string, byte strings follow, terminated by "break"
0x60..0x77 UTF-8 string (0x00..0x17 bytes follow)
0x78 UTF-8 string (one-byte uint8_t for n, and then n bytes follow)
0x79 UTF-8 string (two-byte uint16_t for n, and then n bytes follow)
0x7a UTF-8 string (four-byte uint32_t for n, and then n bytes follow)
0x7b UTF-8 string (eight-byte uint64_t for n, and then n bytes follow)
0x7f UTF-8 string, UTF-8 strings follow, terminated by "break"
0x80..0x97 array (0x00..0x17 data items follow)
0x98 array (one-byte uint8_t for n, and then n data items follow)
0x99 array (two-byte uint16_t for n, and then n data items follow)
0x9a array (four-byte uint32_t for n, and then n data items follow)
0x9b array (eight-byte uint64_t for n, and then n data items follow)
0x9f array, data items follow, terminated by "break"
0xa0..0xb7 map (0x00..0x17 pairs of data items follow)
0xb8 map (one-byte uint8_t for n, and then n pairs of data items follow)
0xb9 map (two-byte uint16_t for n, and then n pairs of data items follow)
0xba map (four-byte uint32_t for n, and then n pairs of data items follow)
0xbb map (eight-byte uint64_t for n, and then n pairs of data items follow)
0xbf map, pairs of data items follow, terminated by "break"
0xc0 text-based date/time (data item follows; see Section 3.4.1)
0xc1 epoch-based date/time (data item follows; see Section 3.4.2)
0xc2 unsigned bignum (data item "byte string" follows)
0xc3 negative bignum (data item "byte string" follows)
0xc4 decimal Fraction (data item "array" follows; see Section 3.4.4)
0xc5 bigfloat (data item "array" follows; see Section 3.4.4)
0xc6..0xd4 (tag)
0xd5..0xd7 expected conversion (data item follows; see Section 3.4.5.2)
0xd8..0xdb (more tags; 1/2/4/8 bytes of tag number and then a data item follow)
0xe0..0xf3 (simple value)
0xf4 false
0xf5 true
0xf6 null
0xf7 undefined
0xf8 (simple value, one byte follows)
0xf9 half-precision float (two-byte IEEE 754)
0xfa single-precision float (four-byte IEEE 754)
0xfb double-precision float (eight-byte IEEE 754)
0xff "break" stop code
表 7: Jump Table for Initial Byte
バイト 構造/意味
0x00..0x17 0x00..0x17(0..23)の符号なし整数
0x18 符号なし整数(1バイトのuint8_tが続く)
0x19 符号なし整数(2バイトのuint16_tが続く)
0x1a 符号なし整数(4バイトのuint32_tが続く)
0x1b 符号なし整数(8バイトのuint64_tが続く)
0x20..0x37 負の整数 -1-0x00..-1-0x17 (-1..-24)
0x38 負の整数 -1-n (1バイトのuint8_tが続く)
0x39 負の整数 -1-n (2バイトのuint16_tが続く)
0x3a 負の整数 -1-n (4バイトのuint32_tが続く)
0x3b 負の整数 -1-n (8バイトのuint64_tが続く)
0x40..0x57 バイト文字列(0x00..0x17バイトが続く)
0x58 バイト文字列(1バイトのuint8_tが続き、その後nバイトが続く)
0x59 バイト文字列(2バイトのuint16_tが続き、その後nバイトが続く)
0x5a バイト文字列(4バイトのuint32_tが続き、その後nバイトが続く)
0x5b バイト文字列(8バイトのuint64_tが続き、その後nバイトが続く)
0x5f バイト文字列、"break"で終了する
0x60..0x77 UTF-8文字列(0x00..0x17バイトが続く)
0x78 UTF-8文字列(1バイトのuint8_tが続き、その後nバイトが続く)
0x79 UTF-8文字列(2バイトのuint16_tが続き、その後nバイトが続く)
0x7a UTF-8文字列(4バイトのuint32_tが続き、その後nバイトが続く)
0x7b UTF-8文字列(8バイトのuint64_tが続き、その後nバイトが続く)
0x7f UTF-8文字列、UTF-8文字列が "break" で終了する
0x80..0x97 配列(0x00..0x17のデータ項目が続く)
0x98 配列(1バイトのuint8_tが続き、その後n個のデータ項目が続く)
0x99 配列(2バイトのuint16_tが続き、その後n個のデータ項目が続く)
0x9a 配列(4バイトのuint32_tが続き、その後n個のデータ項目が続く)
0x9b 配列(8バイトのuint64_tが続き、その後n個のデータ項目が続く)
0x9f 配列、データ項目が "break" で終了する
0xa0..0xb7 マップ(0x00..0x17ペアのデータ項目が続く)
0xb8 マップ(1バイトのuint8_tが続き、その後nペアのデータ項目が続く)
0xb9 マップ(2バイトのuint16_tが続き、その後nペアのデータ項目が続く)
0xba マップ(4バイトのuint32_tが続き、その後nペアのデータ項目が続く)
0xbb マップ(8バイトのuint64_tが続き、その後nペアのデータ項目が続く)
0xbf マップ、データ項目が "break" で終了する
0xc0 テキストベースの日付/時刻(データ項目が続く。詳細はSection 3.4.1を参照)
0xc1 エポックベースの日付/時刻(データ項目が続く。詳細はSection 3.4.2を参照)
0xc2 符号なしビッグナンバー(データ項目 "byte string" が続く)
0xc3 負のビッグナンバー(データ項目 "byte string" が続く)
0xc4 10進数の分数(データ項目 "array" が続く。詳細はSection 3.4.4を参照)
0xc5 ビッグフロート(データ項目 "array" が続く。詳細はSection 3.4.4を参照)
0xc6..0xd4 (タグ)
0xd5..0xd7 期待される変換(データ項目が続く。詳細はSection 3.4.5.2を参照)
0xd8..0xdb (タグの続き; 1/2/4/8バイトのタグ番号が続き、その後にデータ項目が続く)
0xe0..0xf3 (シンプル値)
0xf4 false
0xf5 true
0xf6 null
0xf7 undefined
0xf8 (シンプル値、1バイトが続く)
0xf9 半精度浮動小数点数(2バイトIEEE 754)
0xfa 単精度浮動小数点数(4バイトIEEE 754)
0xfb 倍精度浮動小数点数(8バイトIEEE 754)
0xff "break" ストップコード

The well-formedness of a CBOR item can be checked by the pseudocode in Figure 1. The data is well-formed if and only if:

CBORアイテムのウェルフォーム性は、Figure 1の疑似コードでチェックできます。データは、次の場合に限りウェルフォームです。

  • the pseudocode does not "fail";
  • after execution of the pseudocode, no bytes are left in the input (except in streaming applications).
  • 疑似コードは「失敗」しません。
  • 疑似コードの実行後、入力データにバイトが残っていない場合(ストリーミングアプリケーションを除く)、ウェルフォームです。

The pseudocode has the following prerequisites:

疑似コードには、以下の前提条件があります。

  • take(n) reads n bytes from the input data and returns them as a byte string. If n bytes are no longer available, take(n) fails.
  • uint() converts a byte string into an unsigned integer by interpreting the byte string in network byte order.
  • Arithmetic works as in C.
  • All variables are unsigned integers of sufficient range.
  • take(n) は、入力データから n バイトを読み取り、バイト文字列として返します。n バイトが利用できなくなった場合、take(n) は失敗します。
  • uint() は、バイト文字列をネットワークバイトオーダーで解釈して、符号なし整数に変換します。
  • 算術演算は C と同じように動作します。
  • すべての変数は、十分な範囲の符号なし整数です。

Note that well_formed returns the major type for well-formed definite-length items, but 99 for an indefinite-length item (or -1 for a "break" stop code, only if breakable is set). This is used in well_formed_indefinite to ascertain that indefinite-length strings only contain definite-length strings as chunks.

well_formedは、ウェルフォームな有限長アイテムのメジャータイプを返しますが、不定長アイテムの場合は99を返します(また、breakableが設定されている場合にのみ、「break」ストップコードの場合は-1を返します)。これは、well_formed_indefiniteで使用され、不定長文字列がチャンクとして有限長文字列のみを含むことを確認するために使用されます。

well_formed(breakable = false) {
  // process initial bytes
  ib = uint(take(1));
  mt = ib >> 5;
  val = ai = ib & 0x1f;
  switch (ai) {
    case 24: val = uint(take(1)); break;
    case 25: val = uint(take(2)); break;
    case 26: val = uint(take(4)); break;
    case 27: val = uint(take(8)); break;
    case 28: case 29: case 30: fail();
    case 31:
      return well_formed_indefinite(mt, breakable);
  }
  // process content
  switch (mt) {
    // case 0, 1, 7 do not have content; just use val
    case 2: case 3: take(val); break; // bytes/UTF-8
    case 4: for (i = 0; i < val; i++) well_formed(); break;
    case 5: for (i = 0; i < val*2; i++) well_formed(); break;
    case 6: well_formed(); break;     // 1 embedded data item
    case 7: if (ai == 24 && val < 32) fail(); // bad simple
  }
  return mt;                    // definite-length data item
}

well_formed_indefinite(mt, breakable) {
  switch (mt) {
    case 2: case 3:
      while ((it = well_formed(true)) != -1)
        if (it != mt)           // need definite-length chunk
          fail();               //    of same type
      break;
    case 4: while (well_formed(true) != -1); break;
    case 5: while (well_formed(true) != -1) well_formed(); break;
    case 7:
      if (breakable)
        return -1;              // signal break out
      else fail();              // no enclosing indefinite
    default: fail();            // wrong mt
  }
  return 99;                    // indefinite-length data item
}
Figure 1: Pseudocode for Well-Formedness Check
well_formed(breakable = false) {
  // process initial bytes
  ib = uint(take(1));
  mt = ib >> 5;
  val = ai = ib & 0x1f;
  switch (ai) {
    case 24: val = uint(take(1)); break;
    case 25: val = uint(take(2)); break;
    case 26: val = uint(take(4)); break;
    case 27: val = uint(take(8)); break;
    case 28: case 29: case 30: fail();
    case 31:
      return well_formed_indefinite(mt, breakable);
  }
  // process content
  switch (mt) {
    // case 0, 1, 7 do not have content; just use val
    case 2: case 3: take(val); break; // bytes/UTF-8
    case 4: for (i = 0; i < val; i++) well_formed(); break;
    case 5: for (i = 0; i < val*2; i++) well_formed(); break;
    case 6: well_formed(); break;     // 1 embedded data item
    case 7: if (ai == 24 && val < 32) fail(); // bad simple
  }
  return mt;                    // definite-length data item
}

well_formed_indefinite(mt, breakable) {
  switch (mt) {
    case 2: case 3:
      while ((it = well_formed(true)) != -1)
        if (it != mt)           // need definite-length chunk
          fail();               //    of same type
      break;
    case 4: while (well_formed(true) != -1); break;
    case 5: while (well_formed(true) != -1) well_formed(); break;
    case 7:
      if (breakable)
        return -1;              // signal break out
      else fail();              // no enclosing indefinite
    default: fail();            // wrong mt
  }
  return 99;                    // indefinite-length data item
}
Figure 1: ウェルフォームドネスチェックの疑似コード

Note that the remaining complexity of a complete CBOR decoder is about presenting data that has been decoded to the application in an appropriate form.

完全なCBORデコーダーの残りの複雑さは、デコードされたデータを適切な形式でアプリケーションに提示することに関するものです。

Major types 0 and 1 are designed in such a way that they can be encoded in C from a signed integer without actually doing an if-then-else for positive/negative (Figure 2). This uses the fact that (-1-n), the transformation for major type 1, is the same as ~n (bitwise complement) in C unsigned arithmetic; ~n can then be expressed as (-1)^n for the negative case, while 0^n leaves n unchanged for nonnegative. The sign of a number can be converted to -1 for negative and 0 for nonnegative (0 or positive) by arithmetic-shifting the number by one bit less than the bit length of the number (for example, by 63 for 64-bit numbers).

メジャータイプ0および1は、正負のif-then-elseを実際に行わずに、Cで符号付き整数からエンコードできるように設計されています(Figure 2)。これは、(-1-n)、メジャータイプ1の変換に使用されるものが、Cの符号なし算術では~n(ビットごとの補数)と同じであることを利用しています。~nは、負の場合は(-1)^nで表され、非負の場合は0^nでnは変わりません。数値の符号は、数値のビット長より1ビット少ないビット数で算術シフトすることにより、負の場合は-1、非負の場合は0に変換できます(たとえば、64ビット数値の場合は63で算術シフトします)。

void encode_sint(int64_t n) {
  uint64t ui = n >> 63;    // extend sign to whole length
  unsigned mt = ui & 0x20; // extract (shifted) major type
  ui ^= n;                 // complement negatives
  if (ui < 24)
    *p++ = mt + ui;
  else if (ui < 256) {
    *p++ = mt + 24;
    *p++ = ui;
  } else
       ...
Figure 2: Pseudocode for Encoding a Signed Integer
void encode_sint(int64_t n) {
  uint64t ui = n >> 63;    // extend sign to whole length
  unsigned mt = ui & 0x20; // extract (shifted) major type
  ui ^= n;                 // complement negatives
  if (ui < 24)
    *p++ = mt + ui;
  else if (ui < 256) {
    *p++ = mt + 24;
    *p++ = ui;
  } else
       ...
Figure 2: 符号付き整数のエンコードのための疑似コード

See Section 1.2 for some specific assumptions about the profile of the C language used in these pieces of code.

これらのコードの使用に関するC言語のプロファイルについてのいくつかの具体的な前提条件については、Section 1.2を参照してください。

As half-precision floating-point numbers were only added to IEEE 754 in 2008 [IEEE754], today's programming platforms often still only have limited support for them. It is very easy to include at least decoding support for them even without such support. An example of a small decoder for half-precision floating-point numbers in the C language is shown in Figure 3. A similar program for Python is in Figure 4; this code assumes that the 2-byte value has already been decoded as an (unsigned short) integer in network byte order (as would be done by the pseudocode in Appendix C).

半精度浮動小数点数は、IEEE 754に2008年に追加されたため、今日のプログラミングプラットフォームでは、まだ限定的なサポートしかない場合があります[IEEE754]。そのようなサポートがなくても、少なくともデコードサポートを含めることは非常に簡単です。C言語の半精度浮動小数点数の小さなデコーダーの例をFigure 3に示します。Pythonの類似のプログラムは、Figure 4にあります。このコードは、2バイトの値が(unsigned short)整数としてネットワークバイトオーダーですでにデコードされていることを前提としています(疑似コードAppendix Cで行われるように)。

#include <math.h>

double decode_half(unsigned char *halfp) {
  unsigned half = (halfp[0] << 8) + halfp[1];
  unsigned exp = (half >> 10) & 0x1f;
  unsigned mant = half & 0x3ff;
  double val;
  if (exp == 0) val = ldexp(mant, -24);
  else if (exp != 31) val = ldexp(mant + 1024, exp - 25);
  else val = mant == 0 ? INFINITY : NAN;
  return half & 0x8000 ? -val : val;
}
Figure 3: C Code for a Half-Precision Decoder
#include <math.h>

double decode_half(unsigned char *halfp) {
  unsigned half = (halfp[0] << 8) + halfp[1];
  unsigned exp = (half >> 10) & 0x1f;
  unsigned mant = half & 0x3ff;
  double val;
  if (exp == 0) val = ldexp(mant, -24);
  else if (exp != 31) val = ldexp(mant + 1024, exp - 25);
  else val = mant == 0 ? INFINITY : NAN;
  return half & 0x8000 ? -val : val;
}
Figure 3: C Code for a Half-Precision Decoder
import struct
from math import ldexp

def decode_single(single):
    return struct.unpack("!f", struct.pack("!I", single))[0]

def decode_half(half):
    valu = (half & 0x7fff) << 13 | (half & 0x8000) << 16
    if ((half & 0x7c00) != 0x7c00):
        return ldexp(decode_single(valu), 112)
    return decode_single(valu | 0x7f800000)
Figure 4: Python Code for a Half-Precision Decoder
import struct
from math import ldexp

def decode_single(single):
    return struct.unpack("!f", struct.pack("!I", single))[0]

def decode_half(half):
    valu = (half & 0x7fff) << 13 | (half & 0x8000) << 16
    if ((half & 0x7c00) != 0x7c00):
        return ldexp(decode_single(valu), 112)
    return decode_single(valu | 0x7f800000)
Figure 4: 半精度デコーダのPythonコード

The proposal for CBOR follows a history of binary formats that is as long as the history of computers themselves. Different formats have had different objectives. In most cases, the objectives of the format were never stated, although they can sometimes be implied by the context where the format was first used. Some formats were meant to be universally usable, although history has proven that no binary format meets the needs of all protocols and applications.

CBORの提案は、コンピュータの歴史と同じくらい長いバイナリ形式の歴史に続いています。異なる形式には異なる目的がありました。ほとんどの場合、形式の目的は明示されていませんでしたが、形式が最初に使用された文脈から推測できる場合があります。いくつかの形式は普遍的に使用できるように設計されていましたが、歴史はすべてのプロトコルやアプリケーションのニーズを満たすバイナリ形式は存在しないことを証明しています。

CBOR differs from many of these formats due to it starting with a set of objectives and attempting to meet just those. This section compares a few of the dozens of formats with CBOR's objectives in order to help the reader decide if they want to use CBOR or a different format for a particular protocol or application.

CBORは、多くの形式とは異なり、一連の目的から始まり、それらだけを満たそうとすることによって異なります。このセクションでは、CBORの目的と比較して、数十種類の形式のいくつかを比較し、特定のプロトコルやアプリケーションに対してCBORまたは別の形式を使用するかどうかを決定するのに役立ちます。

Note that the discussion here is not meant to be a criticism of any format: to the best of our knowledge, no format before CBOR was meant to cover CBOR's objectives in the priority we have assigned them. A brief recap of the objectives from Section 1.1 is:

ここでの議論は、どの形式に対しても批判的なものではありません。私たちの知る限り、CBOR以前の形式は、私たちが優先順位を付けたCBORの目的をカバーすることを意図していなかったと思われます。 Section 1.1からの目的の簡単な要約は次のとおりです。

  1. unambiguous encoding of most common data formats from Internet standards
  2. code compactness for encoder or decoder
  3. no schema description needed
  4. reasonably compact serialization
  5. applicability to constrained and unconstrained applications
  6. good JSON conversion
  7. extensibility
  1. インターネット標準のほとんどのデータ形式の明確なエンコード
  2. エンコーダーまたはデコーダーのコードのコンパクトさ
  3. スキーマの説明は必要なし
  4. 合理的にコンパクトなシリアル化
  5. 制約されたおよび非制約されたアプリケーションに適用可能
  6. JSON変換の良さ
  7. 拡張性

A discussion of CBOR and other formats with respect to a different set of design objectives is provided in Section RFC8618 and Appendix RFC8618 of [RFC8618].

CBORと他の形式に関する異なる設計目標に関する議論については、RFC8618のセクションおよび付録RFC8618で提供されています。 [RFC8618]

[ASN.1] has many serializations. In the IETF, DER and BER are the most common. The serialized output is not particularly compact for many items, and the code needed to decode numeric items can be complex on a constrained device.

[ASN.1]には多くのシリアル化形式があります。IETFでは、DERとBERがもっとも一般的です。多くのアイテムに対してシリアル化された出力はとくにコンパクトではなく、数値アイテムをデコードするために必要なコードは、制約されたデバイス上で複雑になる可能性があります。

Few (if any) IETF protocols have adopted one of the several variants of Packed Encoding Rules (PER). There could be many reasons for this, but one that is commonly stated is that PER makes use of the schema even for parsing the surface structure of the data item, requiring significant tool support. There are different versions of the ASN.1 schema language in use, which has also hampered adoption.

IETFプロトコルのほとんどは、Packed Encoding Rules(PER)のいくつかのバリアントのいずれかを採用していません。これには多くの理由が考えられますが、一般的には、PERはデータアイテムの表面構造を解析するためにスキーマを使用するため、重要なツールサポートが必要となることが挙げられます。使用されているASN.1スキーマ言語には、さまざまなバージョンがあり、これも採用を妨げています。

[MessagePack] is a concise, widely implemented counted binary serialization format, similar in many properties to CBOR, although somewhat less regular. While the data model can be used to represent JSON data, MessagePack has also been used in many remote procedure call (RPC) applications and for long-term storage of data.

[MessagePack]は、簡潔で広く実装されたバイナリシリアル化形式であり、CBORに多くの特性が似ていますが、やや規則性が低いです。データモデルはJSONデータを表すために使用できますが、MessagePackは多くのリモートプロシージャコール(RPC)アプリケーションやデータの長期保存にも使用されています。

MessagePack has been essentially stable since it was first published around 2011; it has not yet had a transition. The evolution of MessagePack is impeded by an imperative to maintain complete backwards compatibility with existing stored data, while only few bytecodes are still available for extension. Repeated requests over the years from the MessagePack user community to separate out binary and text strings in the encoding recently have led to an extension proposal that would leave MessagePack's "raw" data ambiguous between its usages for binary and text data. The extension mechanism for MessagePack remains unclear.

MessagePackは、2011年頃に最初に公開されて以来、基本的に安定しています。まだ移行していません。MessagePackの進化は、既存の格納されたデータとの完全な後方互換性を維持する必要があるという命令によって妨げられています。拡張のために使用可能なバイトコードがわずかしかないためです。エンコーディングでバイナリとテキスト文字列を分離するようにMessagePackユーザーコミュニティから何年にもわたって繰り返し要求があり、最近、バイナリとテキストデータの使用法の間でMessagePackの「生」データが曖昧になる拡張提案が行われました。MessagePackの拡張メカニズムは未解決のままです。

[BSON] is a data format that was developed for the storage of JSON-like maps (JSON objects) in the MongoDB database. Its major distinguishing feature is the capability for in-place update, which prevents a compact representation. BSON uses a counted representation except for map keys, which are null-byte terminated. While BSON can be used for the representation of JSON-like objects on the wire, its specification is dominated by the requirements of the database application and has become somewhat baroque. The status of how BSON extensions will be implemented remains unclear.

[BSON]は、MongoDBデータベース内でJSONのようなマップ(JSONオブジェクト)を格納するために開発されたデータ形式です。その主な特徴は、インプレース更新の機能であり、コンパクトな表現を妨げます。BSONは、マップキーを除いて、カウントされた表現を使用します。マップキーはヌルバイトで終了します。BSONは、ワイヤ上のJSONのようなオブジェクトの表現に使用できますが、その仕様はデータベースアプリケーションの要件に支配され、やや複雑になっています。BSON拡張の実装方法の状況は未解決のままです。

Message Services Data Transmission (MSDTP) is a very early example of a compact message format; it is described in [RFC0713], written in 1976. It is included here for its historical value, not because it was ever widely used.

メッセージサービスデータ転送(MSDTP)は、コンパクトなメッセージ形式の非常に初期の例です。1976年に書かれた[RFC0713]で説明されています。広く使用されたわけではないため、歴史的価値のためにここに含められています。

While CBOR's design objective of code compactness for encoders and decoders is a higher priority than its objective of conciseness on the wire, many people focus on the wire size. Table 8 shows some encoding examples for the simple nested array [1, [2, 3]]; where some form of indefinite-length encoding is supported by the encoding, [_ 1, [2, 3]] (indefinite length on the outer array) is also shown.

CBORのエンコーダーとデコーダーのコードのコンパクトさに関する設計目標は、ワイヤ上の簡潔さよりも優先されますが、多くの人々はワイヤサイズに焦点を当てています。 Table 8は、エンコーディングでいくつかの形式の無限長エンコーディングがサポートされている場合に、単純なネストされた配列[1、[2、3]]のエンコーディング例を示しています。[_ 1、[2、3]](外部配列の長さが不定の場合)も示されています。

Table 8: Examples for Different Levels of Conciseness
Format [1, [2, 3]] [_ 1, [2, 3]]
RFC 713 c2 05 81 c2 02 82 83
ASN.1 BER 30 0b 02 01 01 30 06 02 01 02 02 01 03 30 80 02 01 01 30 06 02 01 02 02 01 03 00 00
MessagePack 92 01 92 02 03
BSON 22 00 00 00 10 30 00 01 00 00 00 04 31 00 13 00 00 00 10 30 00 02 00 00 00 10 31 00 03 00 00 00 00 00
CBOR 82 01 82 02 03 9f 01 82 02 03 ff
表 8: Examples for Different Levels of Conciseness
Format [1, [2, 3]] [_ 1, [2, 3]]
RFC 713 c2 05 81 c2 02 82 83
ASN.1 BER 30 0b 02 01 01 30 06 02 01 02 02 01 03 30 80 02 01 01 30 06 02 01 02 02 01 03 00 00
MessagePack 92 01 92 02 03
BSON 22 00 00 00 10 30 00 01 00 00 00 04 31 00 13 00 00 00 10 30 00 02 00 00 00 10 31 00 03 00 00 00 00 00
CBOR 82 01 82 02 03 9f 01 82 02 03 ff

There are three basic kinds of well-formedness errors that can occur in decoding a CBOR data item:

CBORデータアイテムをデコードする際に発生するウェルフォームエラーには、基本的に3種類あります。

Too much data:
There are input bytes left that were not consumed. This is only an error if the application assumed that the input bytes would span exactly one data item. Where the application uses the self-delimiting nature of CBOR encoding to permit additional data after the data item, as is done in CBOR sequences [RFC8742], for example, the CBOR decoder can simply indicate which part of the input has not been consumed.
Too little data:
The input data available would need additional bytes added at their end for a complete CBOR data item. This may indicate the input is truncated; it is also a common error when trying to decode random data as CBOR. For some applications, however, this may not actually be an error, as the application may not be certain it has all the data yet and can obtain or wait for additional input bytes. Some of these applications may have an upper limit for how much additional data can appear; here the decoder may be able to indicate that the encoded CBOR data item cannot be completed within this limit.
Syntax error:
The input data are not consistent with the requirements of the CBOR encoding, and this cannot be remedied by adding (or removing) data at the end.
データが多すぎる場合:
消費されなかった入力バイトがあります。 これは、アプリケーションが入力バイトが正確に1つのデータアイテムに対応すると仮定した場合にのみエラーです。 たとえば、CBORシーケンス[RFC8742]で行われているように、アプリケーションがCBORエンコーディングの自己区切り性を使用してデータアイテムの後に追加データを許可する場合、CBORデコーダーは単にどの部分の入力が消費されていないかを示すことができます。
データが少なすぎる場合:
完全なCBORデータアイテムを得るために、入力データに追加のバイトが必要です。 これは、入力が切り捨てられていることを示す場合があります。 また、ランダムデータをCBORとしてデコードしようとした場合に一般的なエラーです。 ただし、一部のアプリケーションでは、まだすべてのデータを取得していないことが確実ではないため、これが実際にはエラーではない場合があります。 これらのアプリケーションの一部には、追加データがどの程度現れるかに上限がある場合があります。 ここでは、デコーダーがエンコードされたCBORデータアイテムがこの制限内で完了できないことを示すことができます。
構文エラー:
入力データがCBORエンコーディングの要件と一致していないため、末尾にデータを追加(または削除)しても修正できません。

In Appendix C, errors of the first kind are addressed in the first paragraph and bullet list (requiring "no bytes are left"), and errors of the second kind are addressed in the second paragraph/bullet list (failing "if n bytes are no longer available"). Errors of the third kind are identified in the pseudocode by specific instances of calling fail(), in order:

Appendix Cでは、第1種のエラーについては最初の段落と箇条書き(「バイトが残っていない」ことが必要)で説明され、第2種のエラーについては2番目の段落/箇条書き(「nバイトがもう利用できない場合」に失敗する)で説明されています。第3種のエラーは、fail()を呼び出す特定のインスタンスによって疑似コードで識別されます。

  • a reserved value is used for additional information (28, 29, 30)
  • major type 7, additional information 24, value < 32 (incorrect)
  • incorrect substructure of indefinite-length byte string or text string (may only contain definite-length strings of the same major type)
  • "break" stop code (major type 7, additional information 31) occurs in a value position of a map or except at a position directly in an indefinite-length item where also another enclosed data item could occur
  • additional information 31 used with major type 0, 1, or 6
  • 予約された値が追加情報として使用されています(28、29、30)
  • メジャータイプ7、追加情報24、値<32(不正)
  • 不正確な長さのバイト文字列またはテキスト文字列のサブ構造(同じメジャータイプの定義済み長さの文字列のみを含めることができます)
  • 「break」ストップコード(メジャータイプ7、追加情報31)が、マップの値の位置で発生するか、または別の囲まれたデータ項目が発生する可能性がある不定長項目の直接の位置以外で発生する場合は、不正です。
  • メジャータイプ0、1、または6で追加情報31が使用されています

This subsection shows a few examples for CBOR data items that are not well-formed. Each example is a sequence of bytes, each shown in hexadecimal; multiple examples in a list are separated by commas.

このサブセクションでは、ウェルフォームでないCBORデータアイテムのいくつかの例を示します。各例はバイトのシーケンスであり、それぞれ16進数で表示されます。リスト内の複数の例は、カンマで区切られます。

Examples for well-formedness error kind 1 (too much data) can easily be formed by adding data to a well-formed encoded CBOR data item.

ウェルフォームエラーの種類1(データが多すぎる)の例は、ウェルフォームエンコードされたCBORデータアイテムにデータを追加することで簡単に形成できます。

Similarly, examples for well-formedness error kind 2 (too little data) can be formed by truncating a well-formed encoded CBOR data item. In test suites, it may be beneficial to specifically test with incomplete data items that would require large amounts of addition to be completed (for instance by starting the encoding of a string of a very large size).

同様に、ウェルフォームエラーの種類2(データが少なすぎる)の例は、ウェルフォームエンコードされたCBORデータアイテムを切り捨てることで簡単に形成できます。テストスイートでは、非常に大きなサイズの文字列のエンコードを開始することによって、大量の追加が必要な不完全なデータ項目でとくにテストすることが有益である場合があります。

A premature end of the input can occur in a head or within the enclosed data, which may be bare strings or enclosed data items that are either counted or should have been ended by a "break" stop code.

入力の早期終了は、ヘッド内または囲まれたデータ内で発生する可能性があります。囲まれたデータは、カウントされたものまたは「break」ストップコードで終了する必要があるものである場合があります。

End of input in a head:
18, 19, 1a, 1b, 19 01, 1a 01 02, 1b 01 02 03 04 05 06 07, 38, 58, 78, 98, 9a 01 ff 00, b8, d8, f8, f9 00, fa 00 00, fb 00 00 00
Definite-length strings with short data:
41, 61, 5a ff ff ff ff 00, 5b ff ff ff ff ff ff ff ff 01 02 03, 7a ff ff ff ff 00, 7b 7f ff ff ff ff ff ff ff 01 02 03
Definite-length maps and arrays not closed with enough items:
81, 81 81 81 81 81 81 81 81 81, 82 00, a1, a2 01 02, a1 00, a2 00 00 00
Tag number not followed by tag content:
c0
Indefinite-length strings not closed by a "break" stop code:
5f 41 00, 7f 61 00
Indefinite-length maps and arrays not closed by a "break" stop code:
9f, 9f 01 02, bf, bf 01 02 01 02, 81 9f, 9f 80 00, 9f 9f 9f 9f 9f ff ff ff ff, 9f 81 9f 81 9f 9f ff ff ff
ヘッド内で入力が終了:
18, 19, 1a, 1b, 19 01, 1a 01 02, 1b 01 02 03 04 05 06 07, 38, 58, 78, 98, 9a 01 ff 00, b8, d8, f8, f9 00, fa 00 00, fb 00 00 00
短いデータを持つ定義済み長さの文字列:
41, 61, 5a ff ff ff ff 00, 5b ff ff ff ff ff ff ff ff 01 02 03, 7a ff ff ff ff 00, 7b 7f ff ff ff ff ff ff ff 01 02 03
十分なアイテムで閉じられていない定義済み長さのマップと配列:
81, 81 81 81 81 81 81 81 81 81, 82 00, a1, a2 01 02, a1 00, a2 00 00 00
タグ番号に続くタグコンテンツがない場合:
c0
「break」ストップコードで閉じられていない不定長文字列:
5f 41 00, 7f 61 00
「break」ストップコードで閉じられていない不定長マップと配列:
9f, 9f 01 02, bf, bf 01 02 01 02, 81 9f, 9f 80 00, 9f 9f 9f 9f 9f ff ff ff ff, 9f 81 9f 81 9f 9f ff ff ff

A few examples for the five subkinds of well-formedness error kind 3 (syntax error) are shown below.

ウェルフォームエラーの種類3(構文エラー)のいくつかの例を以下に示します。

Subkind 1:

Reserved additional information values:
1c, 1d, 1e, 3c, 3d, 3e, 5c, 5d, 5e, 7c, 7d, 7e, 9c, 9d, 9e, bc, bd, be, dc, dd, de, fc, fd, fe,
Subkind 2:

Reserved two-byte encodings of simple values:
f8 00, f8 01, f8 18, f8 1f
Subkind 3:

Indefinite-length string chunks not of the correct type:
5f 00 ff, 5f 21 ff, 5f 61 00 ff, 5f 80 ff, 5f a0 ff, 5f c0 00 ff, 5f e0 ff, 7f 41 00 ff
Indefinite-length string chunks not definite length:
5f 5f 41 00 ff ff, 7f 7f 61 00 ff ff
Subkind 4:

Break occurring on its own outside of an indefinite-length item:
ff
Break occurring in a definite-length array or map or a tag:
81 ff, 82 00 ff, a1 ff, a1 ff 00, a1 00 ff, a2 00 00 ff, 9f 81 ff, 9f 82 9f 81 9f 9f ff ff ff ff
Break in an indefinite-length map that would lead to an odd number of items (break in a value position):
bf 00 ff, bf 00 00 00 ff
Subkind 5:

Major type 0, 1, 6 with additional information 31:
1f, 3f, df
Subkind 1:

予約された追加情報値:
1c, 1d, 1e, 3c, 3d, 3e, 5c, 5d, 5e, 7c, 7d, 7e, 9c, 9d, 9e, bc, bd, be, dc, dd, de, fc, fd, fe,
Subkind 2:

単純な値の予約された2バイトエンコーディング:
f8 00, f8 01, f8 18, f8 1f
Subkind 3:

正しいタイプでない不定長文字列のチャンク:
5f 00 ff, 5f 21 ff, 5f 61 00 ff, 5f 80 ff, 5f a0 ff, 5f c0 00 ff, 5f e0 ff, 7f 41 00 ff
不定長文字列のチャンクが定義済み長さでない場合:
5f 5f 41 00 ff ff, 7f 7f 61 00 ff ff
Subkind 4:

不定長項目の外部で単独で発生する「break」:
ff
定義済み長さの配列またはマップまたはタグで発生する「break」:
81 ff, 82 00 ff, a1 ff, a1 ff 00, a1 00 ff, a2 00 00 ff, 9f 81 ff, 9f 82 9f 81 9f 9f ff ff ff ff
不定長マップ内で、アイテム数が奇数になるような「break」(値の位置での「break」):
bf 00 ff, bf 00 00 00 ff
Subkind 5:

追加情報31を持つメジャータイプ0、1、6:
1f, 3f, df

As discussed in the introduction, this document formally obsoletes RFC 7049 while keeping full compatibility with the interchange format from RFC 7049. This document provides editorial improvements, added detail, and fixed errata. This document does not create a new version of the format.

序文で説明されているように、この文書はRFC 7049を正式に廃止し、RFC 7049の交換形式と完全に互換性を維持しながら、編集上の改善、追加の詳細、および修正された勘違いを提供します。この文書は、フォーマットの新しいバージョンを作成しません。

The two verified errata on RFC 7049, [Err3764] and [Err3770], concerned two encoding examples in the text that have been corrected (Section 3.4.3: "29" -> "49", Section 5.5: "0b000_11101" -> "0b000_11001"). Also, RFC 7049 contained an example using the numeric value 24 for a simple value [Err5917], which is not well-formed; this example has been removed. Errata report 5763 [Err5763] pointed to an error in the wording of the definition of tags; this was resolved during a rewrite of Section 3.4. Errata report 5434 [Err5434] pointed out that the Universal Binary JSON (UBJSON) example in Appendix E no longer complied with the version of UBJSON current at the time of the errata report submission. It turned out that the UBJSON specification had completely changed since 2013; this example therefore was removed. Other errata reports [Err4409] [Err4963] [Err4964] complained that the map key sorting rules for canonical encoding were onerous; these led to a reconsideration of the canonical encoding suggestions and replacement by the deterministic encoding suggestions (described below). An editorial suggestion in errata report 4294 [Err4294] was also implemented (improved symmetry by adding "Second value" to a comment to the last example in Section 3.2.2).

RFC 7049の2つの確認済みの勘違い、[Err3764]および[Err3770]は、テキスト内の2つのエンコード例に関連しており、修正されました(Section 3.4.3:"29" -> "49"、Section 5.5:"0b000_11101" -> "0b000_11001")。また、RFC 7049には、単純な値に数値24を使用する例が含まれていましたが、これはウェルフォームではないため、この例は削除されました。[Err5917]。勘違いレポート5763 [Err5763]は、タグの定義の文言に誤りがあることを指摘していましたが、これはSection 3.4の書き直し中に解決されました。勘違いレポート5434 [Err5434]は、Universal Binary JSON(UBJSON)の例が、勘違いレポートの提出時点でのUBJSONのバージョンに準拠していないことを指摘していました。しかし、2013年以降、UBJSONの仕様は完全に変更されていたため、この例は削除されました。他の勘違いレポート[Err4409][Err4963][Err4964]は、正準エンコードのマップキーのソートルールが厳しいことを訴えていましたが、これにより正準エンコードの提案が再考され、決定論的エンコードの提案に置き換えられました(以下で説明)。勘違いレポート4294 [Err4294]の編集提案も実装されました(Section 3.2.2の最後の例に「Second value」をコメントに追加して対称性を改善)。

Other clerical changes include:

その他の事務的な変更には、次のものが含まれます。

  • the use of new xml2rfc functionality [RFC7991];
  • more explanation of the notation used;
  • the update of references, e.g., from RFC 4627 to [RFC8259], from CNN-TERMS to [RFC7228], and from the 5.1 edition to the 11th edition of [ECMA262]; the addition of a reference to [IEEE754] and importation of required definitions; the addition of references to [C] and [Cplusplus20]; and the addition of a reference to [RFC8618] that further illustrates the discussion in Appendix E;
  • in the discussion of diagnostic notation (Section 8), the "Extended Diagnostic Notation" (EDN) defined in [RFC8610] is now mentioned, the gap in representing NaN payloads is now highlighted, and an explanation of representing indefinite-length strings with no chunks has been added (Section 8.1);
  • the addition of this appendix.
  • 新しいxml2rfc機能の使用[RFC7991];
  • 使用される表記法の説明の追加;
  • 参照の更新。例えば、RFC 4627から[RFC8259]に、CNN-TERMSから[RFC7228]に、ECMA262の第5.1版から第11版に更新。必要な定義のインポートとして、[IEEE754]への参照の追加、[C][Cplusplus20]への参照の追加。また、Appendix Eでの議論をさらに説明する[RFC8618]への参照の追加;
  • 診断表記の議論(Section 8)で、[RFC8610]で定義された「拡張診断表記」(EDN)が言及され、NaNペイロードの表現のギャップが強調され、長さが不定の文字列を表す方法についての説明が追加された(Section 8.1);
  • この付録の追加。

The IANA considerations were generally updated (clerical changes, e.g., now pointing to the CBOR Working Group as the author of the specification). References to the respective IANA registries were added to the informative references.

IANAに関する考慮事項が一般的に更新されました(事務的な変更、例えば、仕様の筆者としてCBOR Working Groupを指定するようになりました)。情報参照に対して、それぞれのIANAレジストリへの参照が追加されました。

In the "Concise Binary Object Representation (CBOR) Tags" registry [IANA.cbor-tags], tags in the space from 256 to 32767 (lower half of "1+2") are no longer assigned by First Come First Served; this range is now Specification Required.

「Concise Binary Object Representation (CBOR) Tags」レジストリ[IANA.cbor-tags]では、256から32767のタグ(「1+2」の下位半分)は、もはやFirst Come First Servedによって割り当てられません。この範囲は、現在「Specification Required」となっています。

While revising the document, beyond the addressing of the errata reports, the working group drew upon nearly seven years of experience with CBOR in a diverse set of applications. This led to a number of editorial changes, including adding tables for illustration, but also emphasizing some aspects and de-emphasizing others.

文書を改訂する際、勘定書の報告に対処することを超えて、作業グループは、多様なアプリケーションでの約7年間のCBORの経験を活用しました。これにより、図を示すための表の追加を含む編集上の変更がいくつか行われましたが、いくつかの側面を強調し、他の側面を弱めることも行われました。

A significant addition is Section 2, which discusses the CBOR data model and its small variations involved in the processing of CBOR. The introduction of terms for those variations (basic generic, extended generic, specific) enables more concise language in other places of the document and also helps to clarify expectations of implementations and of the extensibility features of the format.

重要な追加事項は、CBORデータモデルと、CBORの処理に関連するその小さな変化について説明するSection 2です。これらの変化に対する用語の導入(基本汎用、拡張汎用、特定)は、ドキュメントの他の場所でより簡潔な言語を可能にし、また、フォーマットの拡張性機能の実装と期待についても明確にするのに役立ちます。

As a format derived from the JSON ecosystem, RFC 7049 was influenced by the JSON number system that was in turn inherited from JavaScript at the time. JSON does not provide distinct integers and floating-point values (and the latter are decimal in the format). CBOR provides binary representations of numbers, which do differ between integers and floating-point values. Experience from implementation and use suggested that the separation between these two number domains should be more clearly drawn in the document; language that suggested an integer could seamlessly stand in for a floating-point value was removed. Also, a suggestion (based on I-JSON [RFC7493]) was added for handling these types when converting JSON to CBOR, and the use of a specific rounding mechanism has been recommended.

JSONエコシステムから派生したフォーマットであるRFC 7049は、当時JavaScriptから継承されたJSON数値システムに影響を受けました。JSONは、整数と浮動小数点値(後者は10進数形式)を区別しません。CBORは、整数と浮動小数点値の間で異なるバイナリ表現を提供します。実装と使用から得られた経験から、これら2つの数値領域の区別を文書でより明確にする必要があることが示唆されました。整数が浮動小数点値の代わりにシームレスに使用できることを示唆する言語は削除されました。また、JSONからCBORに変換する際のこれらの型の処理についての提案(I-JSON [RFC7493]に基づく)が追加され、特定の丸め機構の使用が推奨されました。

For a single value in the data model, CBOR often provides multiple encoding options. A new section (Section 4) introduces the term "preferred serialization" (Section 4.1) and defines it for various kinds of data items. On the basis of this terminology, the section then discusses how a CBOR-based protocol can define "deterministic encoding" (Section 4.2), which avoids terms "canonical" and "canonicalization" from RFC 7049. The suggestion of "Core Deterministic Encoding Requirements" (Section 4.2.1) enables generic support for such protocol-defined encoding requirements. This document further eases the implementation of deterministic encoding by simplifying the map ordering suggested in RFC 7049 to a simple lexicographic ordering of encoded keys. A description of the older suggestion is kept as an alternative, now termed "length-first map key ordering" (Section 4.2.3).

データモデルの単一の値に対して、CBORはしばしば複数のエンコーディングオプションを提供します。新しいセクション(Section 4)では、「優先シリアル化」(Section 4.1)という用語を導入し、さまざまな種類のデータ項目について定義します。この用語に基づいて、セクションでは、CBORベースのプロトコルが「決定論的エンコーディング」(Section 4.2)を定義する方法について説明します。これにより、RFC 7049の「正準」および「正準化」という用語を回避します。「コア決定論的エンコーディング要件」(Section 4.2.1)の提案により、このようなプロトコル定義のエンコーディング要件を汎用的にサポートできるようになります。このドキュメントは、エンコードされたキーの単純な辞書順序へのマップ順序の提案を、RFC 7049で提案されたマップ順序の簡素化により、決定論的エンコーディングの実装をさらに容易にします。以前の提案の説明は、現在は「長さ優先マップキー順序」(Section 4.2.3)と呼ばれ、代替案として保持されています。

The terminology for well-formed and valid data was sharpened and more stringently used, avoiding less well-defined alternative terms such as "syntax error", "decoding error", and "strict mode" outside of examples. Also, a third level of requirements that an application has on its input data beyond CBOR-level validity is now explicitly called out. Well-formed (processable at all), valid (checked by a validity-checking generic decoder), and expected input (as checked by the application) are treated as a hierarchy of layers of acceptability.

ウェルフォームなデータと有効なデータの用語が明確化され、より厳密に使用されるようになりました。"構文エラー"、"デコードエラー"、"ストリクトモード"などのより定義の曖昧な代替用語は、例外を除いて使用されなくなりました。また、CBORレベルの有効性以外に、アプリケーションが入力データに対して持つ要件の第3レベルが明示的に示されるようになりました。ウェルフォームな(全体的に処理可能な)、有効な(有効性チェックを行う汎用デコーダーによってチェックされる)、および期待される入力(アプリケーションによってチェックされる)は、受け入れ可能性のレイヤーの階層として扱われます。

The handling of non-well-formed simple values was clarified in text and pseudocode. Appendix F was added to discuss well-formedness errors and provide examples for them. The pseudocode was updated to be more portable, and some portability considerations were added.

非正常な単純な値の処理について、テキストと疑似コードで明確化されました。 Appendix F は、整形エラーについて説明し、それらの例を提供するために追加されました。疑似コードはよりポータブルに更新され、いくつかのポータビリティに関する考慮事項が追加されました。

The discussion of validity has been sharpened in two areas. Map validity (handling of duplicate keys) was clarified, and the domain of applicability of certain implementation choices explained. Also, while streamlining the terminology for tags, tag numbers, and tag content, discussion was added on tag validity, and the restrictions were clarified on tag content, in general and specifically for tag 1.

有効性に関する議論は、2つの領域でより明確になりました。マップの有効性(重複するキーの処理)が明確化され、特定の実装選択の適用範囲が説明されました。また、タグ、タグ番号、およびタグコンテンツの用語を簡素化する一方で、タグの有効性についての議論が追加され、一般的におよびとくにタグ1について、タグコンテンツの制限が明確化されました。

An implementation note (and note for future tag definitions) was added to Section 3.4 about defining tags with semantics that depend on serialization order.

実装上の注意事項(および将来のタグ定義の注意事項)が、シリアル化順序に依存する意味を持つタグの定義について、Section 3.4に追加されました。

Tag 35 is not defined by this document; the registration based on the definition in RFC 7049 remains in place.

タグ35は、このドキュメントによって定義されていません。RFC 7049の定義に基づく登録は引き続き有効です。

Terminology was introduced in Section 3 for "argument" and "head", simplifying further discussion.

「引数」と「ヘッド」に関する用語が、Section 3で導入され、さらなる議論を簡素化しました。

The security considerations (Section 10) were mostly rewritten and significantly expanded; in multiple other places, the document is now more explicit that a decoder cannot simply condone well-formedness errors.

セキュリティーに関する考慮事項(Section 10)は、大部分が書き直され、大幅に拡張されました。他の多くの場所でも、ドキュメントは、デコーダーが形式上正しいエラーを単に許容できないことをより明示的にしています。

CBOR was inspired by MessagePack. MessagePack was developed and promoted by Sadayuki Furuhashi ("frsyuki"). This reference to MessagePack is solely for attribution; CBOR is not intended as a version of, or replacement for, MessagePack, as it has different design goals and requirements.

CBORはMessagePackからインスピレーションを受けました。MessagePackはSadayuki Furuhashi ("frsyuki")によって開発され、推進されました。MessagePackへの言及は、単に帰属のためであり、CBORは異なる設計目標と要件を持つため、MessagePackのバージョンまたは代替として意図されていません。

The need for functionality beyond the original MessagePack specification became obvious to many people at about the same time around the year 2012. BinaryPack is a minor derivation of MessagePack that was developed by Eric Zhang for the binaryjs project. A similar, but different, extension was made by Tim Caswell for his msgpack-js and msgpack-js-browser projects. Many people have contributed to the discussion about extending MessagePack to separate text string representation from byte string representation.

オリジナルのMessagePack仕様を超えた機能の必要性は、2012年頃に多くの人々に明らかになりました。BinaryPackは、Eric Zhangがbinaryjsプロジェクトのために開発したMessagePackの小さな派生物です。同様の拡張が、Tim Caswellによって彼のmsgpack-jsおよびmsgpack-js-browserプロジェクトのために行われましたが、異なるものでした。多くの人々が、テキスト文字列表現をバイト文字列表現から分離するためにMessagePackを拡張することについての議論に貢献しています。

The encoding of the additional information in CBOR was inspired by the encoding of length information designed by Klaus Hartke for CoAP.

CBORの追加情報のエンコードは、CoAPのためにKlaus Hartkeによって設計された長さ情報のエンコードにインスピレーションを受けました。

This document also incorporates suggestions made by many people, notably Dan Frost, James Manger, Jeffrey Yasskin, Joe Hildebrand, Keith Moore, Laurence Lundblade, Matthew Lepinski, Michael Richardson, Nico Williams, Peter Occil, Phillip Hallam-Baker, Ray Polk, Stuart Cheshire, Tim Bray, Tony Finch, Tony Hansen, and Yaron Sheffer. Benjamin Kaduk provided an extensive review during IESG processing. Éric Vyncke, Erik Kline, Robert Wilton, and Roman Danyliw provided further IESG comments, which included an IoT directorate review by Eve Schooler.

このドキュメントには、多くの人々からの提案が取り入れられています。特に、Dan FrostJames MangerJeffrey YasskinJoe HildebrandKeith MooreLaurence LundbladeMatthew LepinskiMichael RichardsonNico WilliamsPeter OccilPhillip Hallam-BakerRay PolkStuart CheshireTim BrayTony FinchTony Hansen、およびYaron Shefferが特筆されます。IESG処理中にBenjamin Kadukが広範なレビューを提供しました。Éric VynckeErik KlineRobert Wilton、およびRoman DanyliwがさらにIESGコメントを提供し、Eve SchoolerによるIoTディレクトリレビューが含まれました。