send method
Answers request with its ok payload (PROTOCOL.md, "Envelope"), or
with the error the engine reported.
Implementation
@override
Future<Result<Map<String, Object?>, DbError>> send(
ProtocolRequest<Object?> request,
) async {
if (_closed) {
return Err(DbError(DbErrorCode.closed, 'The database is closed'));
}
final String json;
try {
json = jsonEncode(request.toJson());
} on JsonUnsupportedObjectError catch (error) {
return Err(
DbError(
DbErrorCode.invalidRequest,
'The request is not JSON: ${error.unsupportedObject}',
),
);
}
final answer = _abiV2
? await _worker.executeV2(_handle, json)
: await _worker.execute(_handle, json);
return answer.flatMap(ProtocolEnvelope.decode);
}