protobufTreeDecode method

  1. @override
DateTimeWithTimeZone protobufTreeDecode(
  1. Object? value, {
  2. ProtobufDecodingContext? context,
})
override

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
DateTimeWithTimeZone protobufTreeDecode(
  Object? value, {
  ProtobufDecodingContext? context,
}) {
  // TODO: How to serialize timezone in Protocol Buffers?
  context ??= ProtobufDecodingContext();
  final dateTime = context.decode(value, kind: const DateTimeKind());
  return DateTimeWithTimeZone.fromDateTime(dateTime);
}