You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by oahziur <gi...@git.apache.org> on 2014/10/03 02:23:18 UTC

[GitHub] cordova-android pull request: Added basic multipart plugin result

GitHub user oahziur opened a pull request:

    https://github.com/apache/cordova-android/pull/125

    Added basic multipart plugin result

    Related to: https://github.com/apache/cordova-js/pull/83

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/oahziur/cordova-android master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-android/pull/125.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #125
    
----
commit 94ba3c4d08af3243cdc930c76b76642e48378e60
Author: Rui Zhao <oa...@gmail.com>
Date:   2014-10-02T23:09:58Z

    Added basic multipart plugin result

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: Added basic multipart plugin result

Posted by agrieve <gi...@git.apache.org>.
Github user agrieve commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/125#discussion_r18396839
  
    --- 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) {
    --- End diff --
    
    nit: make this static since pluginResult param shadows this.pluginResult


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: [CB-7707] Added basic multipart plug...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-android/pull/125


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: [CB-7707] Added basic multipart plug...

Posted by agrieve <gi...@git.apache.org>.
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: [CB-7707] Added basic multipart plug...

Posted by oahziur <gi...@git.apache.org>.
Github user oahziur commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/125#discussion_r18401241
  
    --- Diff: framework/src/org/apache/cordova/PluginResult.java ---
    @@ -80,6 +83,12 @@ public PluginResult(Status status, byte[] data, boolean binaryString) {
             this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
         }
         
    +    public PluginResult(Status status, List<PluginResult> multipartMessages) {
    --- End diff --
    
    Yes, I think only the top level status is being used.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: Added basic multipart plugin result

Posted by agrieve <gi...@git.apache.org>.
Github user agrieve commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/125#discussion_r18396901
  
    --- 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 --
    
    ditto


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: [CB-7707] Added basic multipart plug...

Posted by agrieve <gi...@git.apache.org>.
Github user agrieve commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/125#discussion_r18397007
  
    --- Diff: framework/src/org/apache/cordova/PluginResult.java ---
    @@ -80,6 +83,12 @@ public PluginResult(Status status, byte[] data, boolean binaryString) {
             this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
         }
         
    +    public PluginResult(Status status, List<PluginResult> multipartMessages) {
    --- End diff --
    
    Add a comment here saying that the keepCallback of the multipartMessages is ignored.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


[GitHub] cordova-android pull request: [CB-7707] Added basic multipart plug...

Posted by mmocny <gi...@git.apache.org>.
Github user mmocny commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/125#discussion_r18400602
  
    --- Diff: framework/src/org/apache/cordova/PluginResult.java ---
    @@ -80,6 +83,12 @@ public PluginResult(Status status, byte[] data, boolean binaryString) {
             this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
         }
         
    +    public PluginResult(Status status, List<PluginResult> multipartMessages) {
    --- End diff --
    
    You mean, of the nested PluginResults?  Also status will be ignored.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org