CborSimpleCodec class
A simple codec for CBOR, using CborSimpleEncoder and CborSimpleDecoder.
To see how CBOR values are transformed from and into objects, verify the documentation of both CborValue.CborValue and CborValue.toObject.
JavaScript (dart2js) Limitations
On JavaScript (dart2js), there is no distinction between integer and floating-point numbers at the type level. All numbers are IEEE 754 doubles. This means:
0.0 is intreturnstrueon JS butfalseon native/WASM platforms- Integer-valued doubles like
1.0,-4.0,65504.0are encoded as CBOR integers instead of CBOR floats - Very large doubles (e.g.,
1.0e+300) may lose precision when treated as integers
Note: This limitation does not apply to dart2wasm, which correctly distinguishes between integers and floats.
Workaround: To ensure consistent float encoding across all platforms, use the advanced API with explicit types:
// Instead of:
cbor.encode(1.0); // Encoded as int on JS, float on native/WASM
// Use:
cborEncode(CborFloat(1.0)); // Always encoded as float
Constructors
Properties
- decoder → CborSimpleDecoder
-
Returns the decoder of
this, converting fromTtoS.no setteroverride - encoder → CborSimpleEncoder
-
Returns the encoder from
StoT.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
-
inverted
→ Codec<
List< int> , Object?> -
Inverts
this.no setterinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
decode(
List< int> encoded, {bool? parseDateTime, bool? decodeBase64, bool? parseUri}) → Object? -
Decodes
encodeddata.override -
encode(
Object? input, {bool? dateTimeEpoch, Object? toEncodable(dynamic object)?}) → List< int> -
Encodes
input.override -
fuse<
R> (Codec< List< other) → Codec<int> , R>Object?, R> -
Fuses
thiswithother.inherited -
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