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.
Amongst other uses, it is the recommended data serialization layer for the CoAP Internet of Things protocol suite and the data format on which COSE messages are based. It is also used in the Client-to-Authenticator Protocol within the scope of the FIDO2 project.

Specification of the CBOR encoding

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

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

Short Field Encoding

Long Field Encoding

CBOR data item header

The table below illustrates how the CBOR data item header works.
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.

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.
https://tools.ietf.org/html/rfc7049#section-7.2

Implementations

NamePrimary authorLanguageLicenseSourceRemarks
cbor-jsPatrick GanstererJavaScriptMIThttps://github.com/paroga/cbor-js
node-cborJoe HildebrandJavaScriptMIThttps://github.com/hildjj/node-cbor
CBOREncodePavel GulbinPHPPHPhttps://github.com/2tvenom/CBOREncode
cborFaye AmackerGoMIThttps://github.com/fxamacker/cborSafe & fast, CBOR tags, float64/32/16, duplicate map key detection, API is encoding/json + toarray & keyasint struct tags, Canonical CBOR, CTAP2, fuzz tested.
cborPavel GulbinGoWTFPLhttps://github.com/2tvenom/cbor
cbor_goBrian OlsonGoAPL 2.0https://github.com/brianolson/cbor_go
go-codecUgorji NwokeGoMIThttps://godoc.org/github.com/ugorji/go/codecAlso handles JSON, MsgPack and BinC.
serde_cborPyfischRustMIT or APL 2.0https://github.com/pyfisch/cbor
cbor-codecToralf WittnerRustMPL 2.0https://twittner.gitlab.io/cbor-codec/cbor/
SwiftCBOR[email protected]SwiftUnlicensehttps://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::FreeFelipe GasperPerlArtistic & GPLhttps://metacpan.org/pod/CBOR::Free-
CBOR::PPFelipe GasperPerlArtistic & GPLhttps://metacpan.org/pod/CBOR::PP
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.
Dahomey.CborMichaël CatanzaritiC#MIT Licensehttps://github.com/dahomey-technologies/Dahomey.Cbor
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
kotlinx.serializationJetBrainsKotlinAPL-2.0https://github.com/Kotlin/kotlinx.serializationSupports cross-platform
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://web.archive.org/web/20170322112326/https://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-
QCborValueQt ProjectC++LGPLhttps://doc.qt.io/qt-5/qcborvalue.htmlPart of the Qt framework since version 5.12
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
cborgDuncan CouttsHaskellBSD-3-clausehttps://github.com/well-typed/cborg
cborSteve HamblettDartMIThttps://github.com/shamblett/cbor
borerMathias DoenitzScalaMPL 2.0https://github.com/sirthias/borerAlso handles JSON.