DagCborCodec class
Codec for DAG-CBOR.
The DAG-CBOR multicodec (0x71) encodes IPLD data as canonical CBOR,
following the IPLD DAG-CBOR specification
(https://ipld.io/specs/codecs/dag-cbor/spec/):
- CID links are CBOR tag 42 applied to a byte string of the CID bytes
prefixed by the multibase identity byte
0x00. - Map keys must be strings and are emitted in canonical order: first by encoded key length, then bytewise lexicographic order.
- Integers use the smallest possible representation; values outside the
major type 0/1 range (
[0, 2^64 - 1]and[-2^64, -1]) use the bignum tags 2 and 3. - Floats are always 64-bit (
0xfb); non-finite values are rejected and-0.0is normalized to0.0on encode.
When strict is true (the default), decode additionally rejects:
- CBOR tags other than 2, 3, and 42.
- Duplicate or non-string map keys, and keys out of canonical order.
- Indefinite-length strings, bytes, arrays, maps, and
breaktokens. - 16-bit and 32-bit floats,
-0.0, and non-finite floats. - Non-canonical integer/length encodings (including non-
0xd82atag 42). - Bignum tags applied to values representable as major types 0/1, and bignum byte strings with leading zero bytes.
- Reserved additional-info values,
undefined, and unassigned simple values. - Extraneous trailing bytes after the top-level item.
In lenient mode (strict = false) non-canonical integer/length
encodings, out-of-order map keys, sub-64-bit floats, and -0.0 are
accepted (with -0.0 normalized to 0.0), but unsupported tags,
indefinite-length items, non-string keys, duplicates, and invalid CID
links are still rejected.
Encode errors are reported as ArgumentError; decode errors as FormatException.
- Implemented types
Constructors
- DagCborCodec({bool strict = true})
- Creates a new DagCborCodec instance.
Properties
- code → int
-
Multicodec integer code (e.g.,
0x71for DAG-CBOR).no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Multicodec name (e.g., 'dag-cbor').
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strict → bool
-
Whether decoding enforces canonical DAG-CBOR rules.
final
Methods
-
decode(
Uint8List data) → Future -
Decodes bytes into a Dart value.
override
-
encode(
dynamic value) → Future< Uint8List> -
Encodes
valueinto bytes.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited