configValues function

Future<Map<String, Object?>> configValues()

Every key and its current value: the activated one if a fetch supplied it, otherwise the default.

Implementation

Future<Map<String, Object?>> configValues() {
  final completer = Completer<Map<String, Object?>>();
  final receive = RawReceivePort();
  receive.handler = (Object? message) {
    receive.close();
    final bytes = message! as Uint8List;
    final seq = ByteData.sublistView(bytes).getInt64(8, Endian.host);
    if (seq < 0) {
      completer.completeError(
        const RemoteConfigException(-2, 'values could not be encoded', 'get'),
      );
      return;
    }
    final decoded = decodeSnapshotValue(bytes);
    completer.complete({
      for (final e in ((decoded as Map?) ?? const {}).entries)
        '${e.key}': e.value,
    });
  };
  final rc = fdbRcGetAll(receive.sendPort.nativePort);
  if (rc != 0) {
    receive.close();
    return Future.error(StateError('configValues failed ($rc)'));
  }
  return completer.future;
}