well_known library

Helpers for working with protobuf well-known types as plain Dart maps.

Each well-known type (Struct, Value, Timestamp, Duration, Any) is represented as Map<String, Object?> matching the proto3 JSON mapping. These functions convert between that representation and idiomatic Dart types, following the canonical JSON encoding rules from:

Functions

durationToString(Map<String, Object?> duration) String
Converts a google.protobuf.Duration to its canonical string form.
mapToStruct(Map<String, Object?> map) Map<String, Object?>
Converts a plain Dart map to a google.protobuf.Struct JSON map.
nativeToValue(Object? value) Map<String, Object?>
Converts a native Dart value to a google.protobuf.Value JSON map.
packAny(String typeUrl, Map<String, Object?> message) Map<String, Object?>
Packs a message into a google.protobuf.Any JSON representation.
rfc3339ToTimestamp(String rfc3339) Map<String, Object?>
Parses an RFC 3339 string into a google.protobuf.Timestamp.
stringToDuration(String durationStr) Map<String, Object?>
Parses a duration string ("Xs", "X.Ns") into a google.protobuf.Duration.
structToMap(Map<String, Object?> struct) Map<String, Object?>
Converts a google.protobuf.Struct JSON map to a plain Dart map.
timestampToRfc3339(Map<String, Object?> timestamp) String
Converts a google.protobuf.Timestamp to an RFC 3339 string.
unpackAny(Map<String, Object?> any) Map<String, Object?>
Unpacks a google.protobuf.Any JSON representation.
valueToNative(Map<String, Object?> value) Object?
Converts a google.protobuf.Value JSON map to its native Dart equivalent.