protobufTreeEncode method
Object
protobufTreeEncode(
- DateTimeWithTimeZone value, {
- ProtobufEncodingContext? context,
override
Converts the argument into a Protocol Buffers tree.
The output graph can contain 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 output graph must be a tree (no cycles are allowed).
The method must serialize other values with context
, which may be
constructed by the method if it's null
.
Example
StringKind().protobufTreeEncode('abc');
// --> 'abc'
SomeEntity.kind.protobufTreeEncode(instanceOfSomeEntity);
// --> GeneratedMessage (package:protobuf)
Implementation
@override
Object protobufTreeEncode(DateTimeWithTimeZone value,
{ProtobufEncodingContext? context}) {
// TODO: How to serialize timezone in Protocol Buffers?
final dateTime = value.toDateTime(utc: true);
context ??= ProtobufEncodingContext();
return context.encode(dateTime, kind: const DateTimeKind());
}