请输入您要查询的百科知识:

 

词条 CBOR
释义

  1. Specification of the CBOR encoding

  2. Major type and additional type handling in each data item

      CBOR data item field encoding    Tiny Field Encoding    Short Field Encoding    Long Field Encoding    CBOR data item header    Primitives (Major type = 7)    Break control code (Additional type value = 31)    IEEE 754 Floats (Additional type value = 25 or 26 or 27)    Simple value  

  3. Semantic Tag Registration

  4. Implementations

  5. See also

  6. References

  7. External links

{{about||the enzyme CBOR|Cellobiose dehydrogenase (acceptor)}}CBOR (Concise Binary Object Representation) is a binary data serialization format loosely based on JSON. Like JSON it allows the transmission of data objects that contain name–value pairs, but in a more concise manner. This increases processing and transfer speeds at the cost of human-readability. It is defined in IETF {{IETF RFC|7049}}.[1]

Amongst other uses, it is the recommended data serialization layer for the CoAP Internet of Things protocol suite.[2]{{Failed verification|date=February 2018}} It is also used in the Client-to-Authenticator Protocol (CTAP) within the scope of the FIDO2 project.[3]

Specification of the CBOR encoding

CBOR encoded data is seen as a stream of data items. E.g.

CBOR dataData item 1Data item 2Data item X...
Byte count1 byte (CBOR data item header)VariableVariable1 byte (CBOR data item header)VariableVariableetc...
StructureMajor typeAdditional informationPayload length (optional)Data payload (optional)Major typeAdditional informationPayload length (optional)Data payload (optional)etc...
Bit count3 Bits5 Bits8 Bits × variable8 Bits × variable3 Bits5 Bits8 Bits × variable8 Bits × variableetc..

Major type and additional type handling in each data item

Each data item behaviour is defined by the major type and additional type.

The major type is used for selecting the main behaviour or type of each data item.

The additional type is additional information whose exact behaviour is dependent on the major type value.

CBOR data item field encoding

Tiny Field Encoding

Byte count1 byte (CBOR data item header)
StructureMajor typeAdditional information (Value)
Bit count3 Bits5 Bits

Short Field Encoding

Byte count1 byte (CBOR data item header)Variable
StructureMajor typeAdditional informationValue
Bit count3 Bits5 Bits8 Bits × (Value_Field_Byte_Count)

Long Field Encoding

Byte count1 byte (CBOR data item header)VariableVariable
StructureMajor typeAdditional information (Size Of Length Field)Payload length (Length Of Value Field)Value
Bit count3 Bits5 Bits8 Bits × (Length_Field_Byte_Count)8 Bits × (Value_Field_Byte_Count)

CBOR data item header

The table below illustrates how the CBOR data item header works.

Major typeMajor type valueAdditional type value (unsigned)Additional type meaningItem Size In BytesField Encoding Type
Positive/Unsigned integer00b000The 5-bit additional information is either the integer itself (for additional information values 0 through 23) or the length of additional data.
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the data value. Thus keeping a compact size.1Tiny
24Next byte is uint8_t in data value section2Short
25Next 2 bytes uint16_t in data value section3Short
26Next 4 bytes is uint32_t in data value section5Short
27Next 8 bytes is uint64_t in data value section9Short
............
31.........
Negative integer10b001The encoding follows the rules for unsigned integers (major type 0), except that the value is then -1 minus the encoded unsigned integer.
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the data value. Thus keeping a compact size.1Tiny
24Next byte is uint8_t in data value section2Short
25Next 2 bytes uint16_t in data value section3Short
26Next 4 bytes is uint32_t in data value section5Short
27Next 8 bytes is uint64_t in data value section9Short
............
31.........
Byte string20b010The string's length in bytes is represented following the rules for positive integers (major type 0).
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the data length specifier. Thus keeping a compact size.up to 1+23Short
24Next byte is uint8_t for payload lengthup to 2+2^8-1Long
25Next 2 bytes uint16_t for payload lengthup to 3+2^16-1Long
26Next 4 bytes is uint32_t for payload lengthup to 5+2^32-1Long
27Next 8 bytes is uint64_t for payload lengthup to 9+2^64-1Long
............
31Start of Indefinite String: Concatenation of definite-length strings, till next corresponding "Break" Code.1Tiny
Text string30b011A text string, specifically a string of Unicode characters that is encoded as UTF-8 [RFC3629].
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the data length specifier. Thus keeping a compact size.up to 1+23Short
24Next byte is uint8_t for payload lengthup to 2+2^8-1Long
25Next 2 bytes uint16_t for payload lengthup to 3+2^16-1Long
26Next 4 bytes is uint32_t for payload lengthup to 5+2^32-1Long
27Next 8 bytes is uint64_t for payload lengthup to 9+2^64-1Long
............
31Start of Indefinite String: Concatenation of definite-length strings, till next corresponding "Break" Code.1Tiny
Array of data items40b100Arrays are also called lists, sequences, or tuples. The length denotes the number of data items in array rather than the byte length.
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the item count specifier. Thus keeping a compact size.1Tiny
24Next byte is uint8_t for payload length2Short
25Next 2 bytes uint16_t for payload length3Short
26Next 4 bytes is uint32_t for payload length5Short
27Next 8 bytes is uint64_t for payload length9Short
............
31Start of Indefinite Array till next corresponding "Break" Code.1Tiny
Map of pairs of data items50b101A map of pairs of data items. Maps are also called tables, dictionaries, hashes, or objects (in JSON).The length denotes the number of pairs of data items rather than the byte length.Every map entry takes two data items in sequential order, a key data item and a value data item.
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the item count specifier. Thus keeping a compact size.1Tiny
24Next byte is uint8_t for payload length2Short
25Next 2 bytes uint16_t for payload length3Short
26Next 4 bytes is uint32_t for payload length5Short
27Next 8 bytes is uint64_t for payload length9Short
............
31Start of indefinite map till next corresponding "break" code.1Tiny
Semantic tag60b110Used for optional semantic tagging of other major types
Value Field represents Tag ID: Refer to https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml for the semantic meaning of each tag.
0 to 23 (0x0 to 0x17) (0b00000 to 0b10111)Used directly as the data value. Thus keeping a compact size.1Tiny
24Next byte is uint8_t in data value section2Short
25Next 2 bytes uint16_t in data value section3Short
26Next 4 bytes is uint32_t in data value section5Short
27Next 8 bytes is uint64_t in data value section9Short
............
31...1...
Primitives

e.g. break,

float,

simple values

70b111floating-point numbers and simple data types that need no content, as well as the "break" stop code[4]
0..19(Unassigned)1Tiny
20False1Tiny
21True1Tiny
22Null1Tiny
23Undefined1Tiny
24Next Byte is uint8_t as Simple value (value 24..255)2Short
25Next 2 Bytes uint16_t as IEEE 754 half-precision float3Short
26Next 4 Bytes is uint32_t as IEEE 754 single-precision float5Short
27Next 8 Bytes is uint64_t as IEEE 754 double-precision float9Short
28Unassigned
29
30
31"break" stop code for indefinite-length items1Tiny
  • Byte = 8 bits

Primitives (Major type = 7)

The primitives major type has a major type value of 7. It is used for simple data types, common complex float types, as well as control code.

Major typeAdditional valueExtra bytes (if required)
Bytes012345678
Bit size3 bits5 bits88888888
Simple value 0 to 23 (value X)7X=0...23Not used
Simple value 24 to 255 (value X)724X=24...255Not used
IEEE 754 half-precision float (16 bits follow)72516 bits IEEE 754Not used
IEEE 754 single-precision float (32 bits follow)72632 bits IEEE 754Not used
IEEE 754 double-precision float (64 bits follow)72764 bits IEEE 754
Break from indefinite array or map731Not used

Break control code (Additional type value = 31)

This is a meta value, that is used in conjunction with arrays and maps set to indefinite length mode. This indicates to the CBOR parser to close the corresponding map or array level.

IEEE 754 Floats (Additional type value = 25 or 26 or 27)

This allows for storing floats, encoded as IEEE 754 float values.

Simple value

Most simple values are either unassigned or reserved for future improvements.

However these are defined.

Simple valueSemantic
20Boolean false
21Boolean true
22Null
23Undefined

Semantic Tag Registration

IANA has created the CBOR tags registry, located in https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml . Registration must contain these template.

Semantic tag typeRangeTemplate
Data itemSemantic description (Short Form)Point of contactDescription of semantics (URL)
Standard actions0-23RequiredRequiredN/AN/A
Specification required24-255RequiredRequiredN/AN/A
First Come First Served256-18446744073709551615RequiredRequiredRequiredDescription is optional.

The URL can point to an Internet-Draft or a web page.

https://tools.ietf.org/html/rfc7049#section-7.2

Implementations

Name Primary author Language License Source Remarks
cbor-js Patrick Gansterer JavaScript MIT https://github.com/paroga/cbor-js
node-cbor Joe Hildebrand JavaScript MIT https://github.com/hildjj/node-cbor
CBOREncode Pavel Gulbin PHP PHP https://github.com/2tvenom/CBOREncode
cbor Pavel Gulbin Go WTFPL https://github.com/2tvenom/cbor
cbor_go Brian Olson Go APL 2.0 https://github.com/brianolson/cbor_go
go-codec Ugorji Nwoke Go MIT https://godoc.org/github.com/ugorji/go/codec Also handles JSON, MsgPack and BinC.
rust-cborAndrew GallantRustMIT or Unlicensehttps://github.com/BurntSushi/rust-cbor
cbor-codecToralf WittnerRustMPL 2.0https://twittner.gitlab.io/cbor-codec/cbor/
SwiftCBORgreg@unrelenting.technologySwiftUnlicensehttps://github.com/myfreeweb/SwiftCBOR
CBOR.jlSaurav SachidanandJuliaMIThttps://github.com/saurvs/CBOR.jl
Lua-CBORKim AlvefurLuaMIThttps://www.zash.se/lua-cbor.html
org.conman.cborSean ConnerLuaLGPL-3https://github.com/spc476/CBOR
cbor_pyBrian OlsonPythonAPL 2.0https://github.com/brianolson/cbor_py
flynnFritz Conrad GrimpenPythonMIThttps://github.com/fritz0705/flynn
cbor2Alex GrönholmPythonMIThttps://github.com/agronholm/cbor2
CBOR::XSMarc LehmannPerlGPL-3https://metacpan.org/pod/CBOR::XS
cbor-rubySadayuki Furuhashi

Carsten Bormann

RubyAPL 2.0https://github.com/cabo/cbor-ruby
libcbor-rubyPavel KalvodaRubyMIThttps://github.com/PJK/libcbor-rubyBinding to libcbor.
cbor-erlangJihyun YuErlangBSD-3-clausehttps://github.com/yjh0502/cbor-erlang
excborCarsten BormannElixirnot specified,

ask the author

https://github.com/cabo/excbor
CBORR. Kyle MurphyHaskellLGPL-3https://github.com/orclev/CBOR
borcJoe Hildebrand

Friedel Ziegelmayer

JavaScriptMIThttps://github.com/dignifiedquire/borcFork of node-cbor.
borc-refsJoe Hildebrand

Friedel Ziegelmayer

Sandro Hawke

JavaScriptMIThttps://github.com/sandhawke/borc-refsFork of borc.
CBORPeter OccilC#Public domain softwarehttps://github.com/peteroupc/CBORAlso handles JSON.
JacksonTatu SalorantaJavaAPL-2.0https://github.com/FasterXML/jackson-dataformats-binary/tree/master/cborAlso handles other formats.
cbor-javaConstantin RackJavaAPL-2.0https://github.com/c-rack/cbor-java
jacobJ.W. JanssenJavaAPL-2.0https://github.com/jawi/jacob
cn-cborJoe Hildebrand

Carsten Bormann

CMIThttps://github.com/cabo/cn-cbor
cbor-cppStanislav OvsyannikovC++APL-2.0https://github.com/naphaso/cbor-cpp
cppborDavid PreeceC++BSDhttps://github.com/rantydave/cppborUses C++17 variants.
libcborPavel KalvodaCMIThttps://github.com/PJK/libcbor
tinycborIntelCMIThttps://github.com/01org/tinycbor
cbor-dAndrey PenechkoDBoost 1.0https://github.com/MrSmith33/cbor-d
clj-cborGreg LookClojureUnlicensehttps://github.com/greglook/clj-cbor
JSON for Modern C++Niels LohmannC++MIThttps://github.com/nlohmann/jsonAlso handles JSON and MsgPack.
boraboraChristoph EngelbertJavaAPL-2.0https://github.com/noctarius/borabora
lua-ConciseSerializationFrançois PerradLuaMIThttps://fperrad.github.io/lua-ConciseSerialization/
flunnFritz Conrad Grimpen

Sokolov Yura

PythonMIThttps://pypi.python.org/pypi/flunn
cbor-qtAnton DutovC++Public domainhttps://github.com/anton-dutov/cbor-qt
cbor11Jakob Varmose BentzenC++Public domainhttps://github.com/jakobvarmose/cbor11
cborcppAlex NekipelovC++MIThttps://github.com/nekipelov/cborcpp
GoldFishVincent LascauxC++MIThttps://github.com/OneNoteDev/GoldFish
Library-Arduino-CborJuanjo TaraC++APL-2.0https://github.com/jjtara/Library-Arduino-Cbor
serde_cborPyfischRustApache-2.0/MIThttps://github.com/pyfisch/cbor
cborgDuncan CouttsHaskellBSD-3-clausehttps://github.com/well-typed/cborg
cborSteve HamblettDartMIThttps://github.com/shamblett/cbor

See also

  • Comparison of binary data serialization formats

References

1. ^{{Cite web | url=http://cbor.io/ | title=CBOR — Concise Binary Object Representation | Overview}}
2. ^{{Cite web | url=http://coap.technology/ | title=CoAP — Constrained Application Protocol | Overview}}
3. ^{{cite web|url=https://fidoalliance.org/fido2/|title=FIDO2 Project|publisher=FIDO Alliance|accessdate=2018-05-11}}
4. ^{{cite IETF|rfc=7049}}

External links

  • Online tool to convert from CBOR binary to textual representation and back.
{{Data Exchange}}

1 : Data serialization formats

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/21 22:34:42