cbor v2.0.0 Release NotesRelease Date: 2020-02-03 // over 1 year ago
🔄 Changes in v2.0:
- 👌 Improved API.
- 🐎 Faster performance.
- ⬇️ Reduced memory usage.
- 👌 Improved code quality using around 20 linters.
- Replaced EncOptions.TimeRFC3339 bool with TimeMode (5 settings).
- Decode NaN and Infinity time values to Go's "zero time" value.
- ✂ Removed deprecated v1 options and Valid() function.
- Many improvements to README.md.
v2.0 was needed to simplify adding new features planned for v2.1 and v2.2.
- 👍 v2.1 (Feb. 9, 2020) support for CBOR tags (major type 6) and some decoder optimizations.
- v2.2 (Feb. 2020) options for handling duplicate map keys.
🚚 CBOR Tags (major type 6) was moved to milestone v2.1. and is over 50% done.
🚀 v2.0 passed 1+ billion execs in coverage-guided fuzzing before release. This is the most well-tested and most reliable release of this library. Upgrading is highly recommended.
👌 Improved API
In v2, more function signatures match encoding/json. These are the most widely used:
"Mode" in this API means definite way of encoding or decoding.
EncMode and DecMode are interfaces created from EncOptions or DecOptions structs.
EncMode and DecMode use immutable options so their behavior won't accidentally change at runtime. Modes are intended to be reused and are safe for concurrent use.
// Create EncOptions, using either struct literal or a function. opts := cbor.CanonicalEncOptions() // If needed, modify options -- e.g. how time values should be encoded. opts.Time = cbor.TimeUnix // Create reusable EncMode interface with immutable options, safe for concurrent use. em, err := opts.EncMode() // Use EncMode like encoding/json, with same function signatures. b, err := em.Marshal(v) // or encoder := em.NewEncoder(w) err := encoder.Encode(v)
📦 Package Level Functions
📦 These package level functions use default options without CBOR tags. Their API matches encoding/json. EncMode and DecMode also provide these functions with same signatures.
b, err := cbor.Marshal(v) err := cbor.Unmarshal(b, &v) encoder := cbor.NewEncoder(w) decoder := cbor.NewDecoder(r)
Replaced EncOptions.TimeRFC3339 bool with TimeMode:
- TimeUnix // secs, encodes to CBOR integer using fewest bytes
- TimeUnixMicro // μs, encodes to CBOR float with subsecs in fractional part
- TimeUnixDynamic // secs or μs, encodes to either int or float depending on empty subsecs
- TimeRFC3339 // secs, encodes to string
- 🚚 TimeRFC3339Nano // ns, encodes to string with trailing zeros removed