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}',
),
);
}
return (await _worker.execute(
_handle,
json,
)).flatMap(ProtocolEnvelope.decode);
}