replyOk function

String replyOk(
  1. Object? id,
  2. Object? v
)

Encodes a successful reply, replacing an over-cap one with E_TOO_LARGE. Used by generated code.

An over-cap reply would overrun Binder and kill the WebView, with no reply and nothing either side can catch — and a WebView death while a trial is on screen spends a strike, so a healthy bundle can be marked bad. The id is still in hand here, so it becomes an error the page can actually see (§4.2).

Implementation

String replyOk(Object? id, Object? v) {
  // Count the exact JSON inserted into JavaScript, including separator escapes.
  final s = _escapeScriptSeparators(jsonEncode({'id': id, 'ok': true, 'v': v}));
  if (utf8.encode(s).length > maxMessageBytes) {
    return replyError(
      id,
      BridgeErrorCode.tooLarge,
      'reply is over the $maxMessageBytes byte bridge cap; page the request',
    );
  }
  return s;
}