addUserMetadata method
Adds or overwrites custom metadata for the given key.
The provided byte buffer will be stored in the log file's metadata area.
If a value already exists for the same key it will be replaced. This
operation is asynchronous and returns true when the write succeeded.
Parameters
key: The string key to associate with the metadata.userMetadata: A Uint8List containing the data to store.
Returns
- A Future<bool> that completes with
trueon success,falseon failure.
Also see:
- getUserMetadata - Retrieve custom metadata from the log.
- Recorder.addUserMetadata - Add custom metadata during recording.
Implementation
Future<bool> addUserMetadata(
final String key,
final Uint8List userMetadata,
) async {
final dynamic dataBufferPointer = GemKitPlatform.instance.toNativePointer(
userMetadata,
);
final String? resultString = await GemKitPlatform.instance
.getChannel(mapId: -1)
.invokeMethod<String>(
'callObjectMethod',
jsonEncode(<String, Object>{
'id': pointerId,
'class': 'LogMetadata',
'method': 'addUserMetadata',
'args': <String, dynamic>{
'key': key,
'dataBuffer': dataBufferPointer.address,
'dataBufferSize': userMetadata.length,
},
}),
);
GemKitPlatform.instance.freeNativePointer(dataBufferPointer);
return jsonDecode(resultString!)['result'] as bool;
}