tryToJson function
Implementation
Uint8List? tryToJson(CType type, dynamic value) {
if (type is VecClass<Map<String, dynamic>> &&
value is List<Enum> &&
type.covariant(value)) {
try {
final list = value as List<dynamic>;
try {
value = list.map((e) => e.toIDLSerializable()).toList(growable: false);
} on NoSuchMethodError {
value = list.map((e) => e.toJson()).toList(growable: false);
}
return type.encodeValue(value);
} catch (e) {
return null;
}
}
if ((type is RecordClass ||
type is VariantClass ||
(type is TextClass && value is! String)) &&
// obj may be a map, must be ignore.
value is! Map) {
try {
try {
value = value.toIDLSerializable();
} on NoSuchMethodError {
value = value.toJson();
}
return type.encodeValue(value);
} catch (e) {
return null;
}
}
return null;
}