setValueWithPriority function
Writes value at path with priority, which orders it among its
siblings and is what DbQuery.orderByPriority reads.
One operation, not two. Writing the value and then the priority lets a listener see the node in between, still in its old position.
Implementation
Future<void> setValueWithPriority(
String path,
Object? value,
Object? priority,
) {
final v = encodeVariant(value);
final pr = encodeVariant(priority);
final p = path.toNativeUtf8();
final vb = calloc<Uint8>(v.isEmpty ? 1 : v.length);
final pb = calloc<Uint8>(pr.isEmpty ? 1 : pr.length);
if (v.isNotEmpty) vb.asTypedList(v.length).setAll(0, v);
if (pr.isNotEmpty) pb.asTypedList(pr.length).setAll(0, pr);
return _awaitDbOutcome(
(port) => fdbDbSetWithPriority(p.cast(), vb, v.length, pb, pr.length, port),
'setValueWithPriority',
).whenComplete(() {
calloc
..free(p)
..free(vb)
..free(pb);
});
}