Github user agrieve commented on a diff in the pull request: https://github.com/apache/cordova-android/pull/125#discussion_r18396932 --- Diff: framework/src/org/apache/cordova/NativeToJsMessageQueue.java --- @@ -419,53 +419,43 @@ private void initReflection() { this.pluginResult = pluginResult; } - int calculateEncodedLength() { - if (pluginResult == null) { - return jsPayloadOrCallbackId.length() + 1; - } - int statusLen = String.valueOf(pluginResult.getStatus()).length(); - int ret = 2 + statusLen + 1 + jsPayloadOrCallbackId.length() + 1; + int calculateEncodedLength(PluginResult pluginResult) { switch (pluginResult.getMessageType()) { case PluginResult.MESSAGE_TYPE_BOOLEAN: // f or t case PluginResult.MESSAGE_TYPE_NULL: // N - ret += 1; - break; + return 1; case PluginResult.MESSAGE_TYPE_NUMBER: // n - ret += 1 + pluginResult.getMessage().length(); - break; + return 1 + pluginResult.getMessage().length(); case PluginResult.MESSAGE_TYPE_STRING: // s - ret += 1 + pluginResult.getStrMessage().length(); - break; + return 1 + pluginResult.getStrMessage().length(); case PluginResult.MESSAGE_TYPE_BINARYSTRING: - ret += 1 + pluginResult.getMessage().length(); - break; + return 1 + pluginResult.getMessage().length(); case PluginResult.MESSAGE_TYPE_ARRAYBUFFER: - ret += 1 + pluginResult.getMessage().length(); - break; + return 1 + pluginResult.getMessage().length(); + case PluginResult.MESSAGE_TYPE_MULTIPART: + int ret = 1; + for (int i = 0; i < pluginResult.getMultipartMessagesSize(); i++) { + int length = calculateEncodedLength(pluginResult.getMultipartMessage(i)); + int argLength = String.valueOf(length).length(); + ret += argLength + 1 + length; + } + return ret; case PluginResult.MESSAGE_TYPE_JSON: default: - ret += pluginResult.getMessage().length(); + return pluginResult.getMessage().length(); } - return ret; } - void encodeAsMessage(StringBuilder sb) { + int calculateEncodedLength() { if (pluginResult == null) { - sb.append('J') - .append(jsPayloadOrCallbackId); - return; + return jsPayloadOrCallbackId.length() + 1; + } + int statusLen = String.valueOf(pluginResult.getStatus()).length(); + int ret = 2 + statusLen + 1 + jsPayloadOrCallbackId.length() + 1; + return ret + calculateEncodedLength(pluginResult); } - int status = pluginResult.getStatus(); - boolean noResult = status == PluginResult.Status.NO_RESULT.ordinal(); - boolean resultOk = status == PluginResult.Status.OK.ordinal(); - boolean keepCallback = pluginResult.getKeepCallback(); - sb.append((noResult || resultOk) ? 'S' : 'F') - .append(keepCallback ? '1' : '0') - .append(status) - .append(' ') - .append(jsPayloadOrCallbackId) - .append(' '); + void encodeAsMessage(StringBuilder sb, PluginResult pluginResult) { --- End diff -- Maybe call them "*Helper" as well, so that they are not overloads?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org For additional commands, e-mail: dev-h...@cordova.apache.org