protobufTreeDecode method
Converts the argument (a Protocol Buffers tree) into an instance of T
.
The input graph contains instances of the following types:
null
bool
int
Int64
(package:fixnum)double
String
Uint8List
GeneratedMessage
(package:protobuf)- Field values must be instances of allowed types.
List
- Items must be instances of single non-list allowed type.
The graph must be a tree (no cycles are allowed).
The method must deserialize other values with context
, which may be
constructed by the method if it's null
.
Example
StringKind().protobufTreeDecode('abc');
// --> 'abc'
// We assume `generatedMessage` is an instance of GeneratedMessage
// (package:protobuf)
SomeEntity.kind.protobufTreeDecode(generatedMessage);
// --> instance of SomeEntity
Implementation
@override
int protobufTreeDecode(Object? value, {ProtobufDecodingContext? context}) {
if (value is int) {
return value;
} else if (value is Int64) {
return value.toInt();
} else {
context ??= ProtobufDecodingContext();
throw context.newUnsupportedTypeError(value);
}
}