You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2014/10/03 16:13:34 UTC
[jira] [Commented] (CB-7707) Implement a multipart Plugin Result
for Android
[ https://issues.apache.org/jira/browse/CB-7707?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14158004#comment-14158004 ]
ASF GitHub Bot commented on CB-7707:
------------------------------------
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?
> Implement a multipart Plugin Result for Android
> -----------------------------------------------
>
> Key: CB-7707
> URL: https://issues.apache.org/jira/browse/CB-7707
> Project: Apache Cordova
> Issue Type: Sub-task
> Components: Android, CordovaJS, iOS
> Affects Versions: 3.7.0
> Reporter: Michal Mocny
> Assignee: Michal Mocny
> Fix For: 2.6.0
>
>
> We added multipart messages to iOS, and added support to the bridge for Android, but never actually implemented a way to send multiple messages.
> This is specifically required because ArrayBuffers are only decoded if they are a top-level argument (cannot be nested within a JSON object), and so you cannot send a reply with both an ArrayBuffer and another argument (string descriptor for example).
> We've previously hacked around this by using "keepCallback" and expecting multiple messages with different arguments, but it leads to complicated state transfers and is quite inefficient.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org