ProtoGoogleAny.fromJson constructor
ProtoGoogleAny.fromJson(
- Map<
String, dynamic> json, { - ProtoJsonConfig config = DefaultProtoJsonConfig.defaultConfig,
Implementation
factory ProtoGoogleAny.fromJson(
Map<String, dynamic> json, {
ProtoJsonConfig config = DefaultProtoJsonConfig.defaultConfig,
}) {
String key = json.hasValue("type_url") ? "type_url" : "@type";
final String typeUrl = json.valueAsString<String>(key);
final value = Map<String, dynamic>.from(json)
..removeWhere((k, v) => k == key);
List<int>? decode;
if (value.length == 1 && value.hasValue("value")) {
try {
decode = value.valueAsBytes("value", encoding: config.binaryEncoding);
} catch (_) {}
}
bool isBinary = decode != null;
return ProtoGoogleAny._(
typeUrl: typeUrl,
value: decode ?? value,
isBinary: isBinary,
);
}