CborValue constructor
Transform the Object into a CborValue.
Throws CborCyclicError if cyclic references exist inside object
.
The object is transformed according to the following relations.
Input | Output |
---|---|
null |
CborNull |
CborValue | CborValue (unchanged) |
double | CborFloat |
int | CborSmallInt |
BigInt | CborInt |
bool | CborBool |
Uint8List | CborBytes |
String | CborString |
DateTime | CborDateTime |
Uri | CborUri |
Iterable | CborList |
Map | CborMap |
If dateTimeEpoch
is false
, DateTime is transformed into
CborDateTimeString, and otherwise into CborDateTimeInt or
CborDateTimeFloat depending on the sub-second resolution.
The toEncodable
function is used during encoding. It is invoked for
values that are not directly encodable to a CborValue. The
function must return an object that is directly encodable. The elements of
a returned list and values of a returned map do not need to be directly
encodable, and if they aren't, toEncodable
will be used on them as well.
Please notice that it is possible to cause an infinite recursive regress
in this way, by effectively creating an infinite data structure through
repeated call to toEncodable
.
If toEncodable
is omitted, it defaults to a function that returns the
result of calling .toCbor()
on the unencodable object.
Implementation
factory CborValue(
Object? object, {
bool dateTimeEpoch = false,
Object? Function(dynamic object)? toEncodable,
}) =>
CborValue._fromObject(
object,
dateTimeEpoch: dateTimeEpoch,
toEncodable: toEncodable ?? (object) => object.toCbor(),
);