An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

github.com/fxamacker/cbor/v2

Package cbor is a modern CBOR codec (RFC 8949 & RFC 8742) with CBOR tags, Go struct tag options (toarray/keyasint/omitempty/omitzero), Core Deterministic Encoding, CTAP2, Canonical CBOR, float64->32->16, and duplicate map key detection. Encoding options allow "preferred serialization" by encoding integers and floats to their smallest forms (e.g. float16) when values fit. Struct tag options "keyasint", "toarray", "omitempty", and "omitzero" reduce encoding size and reduce programming effort. For example, "toarray" tag makes struct fields encode to CBOR array elements. And "keyasint" makes a field encode to an element of CBOR map with specified int key. Latest docs can be viewed at https://github.com/fxamacker/cbor#cbor-library-in-go The Quick Start guide is at https://github.com/fxamacker/cbor#quick-start Function signatures identical to encoding/json include: Standard interfaces include: Diagnostic functions translate CBOR data item into Diagnostic Notation: Functions that simplify using CBOR Sequences (RFC 8742) include: Custom encoding and decoding is possible by implementing standard interfaces for user-defined Go types. Codec functions are available at package-level (using defaults options) or by creating modes from options at runtime. "Mode" in this API means definite way of encoding (EncMode) or decoding (DecMode). EncMode and DecMode interfaces are created from EncOptions or DecOptions structs. Modes use immutable options to avoid side-effects and simplify concurrency. Behavior of modes won't accidentally change at runtime after they're created. Modes are intended to be reused and are safe for concurrent use. EncMode and DecMode Interfaces Using Default Encoding Mode Using Default Decoding Mode Using Default Mode of UnmarshalFirst to Decode CBOR Sequences Using Extended Diagnostic Notation (EDN) to represent CBOR data Creating and Using Encoding Modes Predefined Encoding Options: https://github.com/fxamacker/cbor#predefined-encoding-options Encoding Options: https://github.com/fxamacker/cbor#encoding-options Decoding Options: https://github.com/fxamacker/cbor#decoding-options Struct tags like `cbor:"name,omitempty"` and `json:"name,omitempty"` work as expected. If both struct tags are specified then `cbor` is used. Struct tag options like "keyasint", "toarray", "omitempty", and "omitzero" make it easy to use very compact formats like COSE and CWT (CBOR Web Tokens) with structs. The "omitzero" option omits zero values from encoding, matching [stdlib encoding/json behavior](https://pkg.go.dev/encoding/json#Marshal). When specified in the `cbor` tag, the option is always honored. When specified in the `json` tag, the option is honored when building with Go 1.24+. For example, "toarray" makes struct fields encode to array elements. And "keyasint" makes struct fields encode to elements of CBOR map with int keys. https://raw.githubusercontent.com/fxamacker/images/master/cbor/v2.0.0/cbor_easy_api.png Struct tag options are listed at https://github.com/fxamacker/cbor#struct-tags-1 Over 375 tests are included in this package. Cover-guided fuzzing is handled by a private fuzzer that replaced fxamacker/cbor-fuzz years ago.

Ecosystem
proxy.golang.org
Latest Release
v2.9.0
8 months ago
Versions
21
Dependent Packages
2,061
Dependent Repos
1,615
Links
Registry proxy.golang.org
Source Repository
Docs Documentation
JSON API View JSON
CodeMeta codemeta.json
Package Details
PURL pkg:golang/github.com/fxamacker/cbor/v2
spec
License MIT
Namespace github.com/fxamacker/cbor
First Release about 6 years ago
Last Synced about 9 hours ago
Repository
Stars 947 on GitHub
Forks 72 on GitHub
Docker Dependents 775
Docker Downloads 4,981,722,344
Rankings on proxy.golang.org
Overall Top 1.3%
Dependent packages Top 0.1%
Dependent repos Top 0.2%
Forks Top 3.5%
Docker downloads Top 0.1%