replyError function
Encodes a failed reply. Used by generated code.
Implementation
String replyError(Object? id, String code, String message) {
final s = _escapeScriptSeparators(jsonEncode({'id': id, 'ok': false, 'e': {'code': code, 'message': message}}));
if (utf8.encode(s).length <= maxMessageBytes) return s;
// A malformed request can supply an arbitrary id before the nonce check.
// Preserve only finite numeric correlation ids in the bounded fallback.
return jsonEncode({
'id': id is num && id.isFinite ? id : null,
'ok': false,
'e': {'code': BridgeErrorCode.tooLarge, 'message': 'error reply is over the $maxMessageBytes byte bridge cap'},
});
}