decodeDocument function
Decodes a document from a snapshot buffer, or null when the payload is empty — which is how a missing document arrives.
Implementation
Map<String, Object?>? decodeDocument(Uint8List bytes) {
if (bytes.length < snapshotHeaderBytes) {
throw const FormatException('snapshot shorter than its header');
}
if (bytes.length == snapshotHeaderBytes) return null;
final decoded = decodeFirestoreValue(
cborDecode(Uint8List.sublistView(bytes, snapshotHeaderBytes)),
);
if (decoded is! Map<String, Object?>) {
throw const FormatException('document payload is not a map');
}
return decoded;
}