An array passed by a single parameter

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

An array passed by a single parameter

Murilo Camões Perrone
In my XPCOM component, I must use an single-parameter "byte array" , because I must reproduce an existent COM interface whose methods use managed arrays (sngle-parameter arrays are present on those interfaces).
 
The XPIDL language defines that, for conventional arrays, an extra parameter indicating the array length should be used, and this is a problem for me. Exemple:
 
In XPIDL I can define:
 
    void BinaryStringToByteArray ( in string BinaryString, out unsigned long length, [array, size_is (length), retval] out octet data );
 
but I need this:
 
    byte[] BinaryStringToByteArray ( in string BinaryString );
 
I need to use a byte[] compatible with Java and JavaScript native byte arrays.
 
Currently the only solution I found is to use the wrappedJSObject property of an JavaScript defined component, but this does only work if the XPCom client is JavaScript too...
 
Any ideas ?
 
------
Murilo Perrone
CertiSign
 

_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

David Huynh
I actually have the very same problem, and also the problem of passing
in an array as a single parameter, and the problem of exposing a member
field as an array.

David


Murilo Camões Perrone wrote:

> In my XPCOM component, I must use an single-parameter "byte array" ,
> because I must reproduce an existent COM interface whose methods use
> managed arrays (sngle-parameter arrays are present on those interfaces).
>  
> The XPIDL language defines that, for conventional arrays, an extra
> parameter indicating the array length should be used, and this is a
> problem for me. Exemple:
>  
> In XPIDL I can define:
>  
>     void BinaryStringToByteArray ( in string BinaryString, _out unsigned
> long length, [array, size_is (length), retval] out octet data_ );
>  
> but I need this:
>  
>     _byte[]_ BinaryStringToByteArray ( in string BinaryString );
>  
> I need to use a byte[] compatible with Java and JavaScript native byte
> arrays.
>  
> Currently the only solution I found is to use the wrappedJSObject
> property of an JavaScript defined component, but this does only work if
> the XPCom client is JavaScript too...
>  
> Any ideas ?
>  
> ------
> Murilo Perrone
> CertiSign
>  
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

Darin Fisher
In reply to this post by Murilo Camões Perrone
ACString can be used to implement this sort of thing.  It has the
property that elements of the array can be 0, so it can be used to pass
"byte array" values.  When converting an ACString to a JS string,
XPConnect inflates each byte to a double-byte value, setting the upper
byte to zero.  When converting the other direction, the upper byte is
truncated.  If the JS consumer treats each element of the JS string as a
byte of binary data, then it can be made to work pretty well.

-Darin


Murilo Camões Perrone wrote:

> In my XPCOM component, I must use an single-parameter "byte array" ,
> because I must reproduce an existent COM interface whose methods use
> managed arrays (sngle-parameter arrays are present on those interfaces).
>  
> The XPIDL language defines that, for conventional arrays, an extra
> parameter indicating the array length should be used, and this is a
> problem for me. Exemple:
>  
> In XPIDL I can define:
>  
>     void BinaryStringToByteArray ( in string BinaryString, _out
> unsigned long length, [array, size_is (length), retval] out octet data_ );
>  
> but I need this:
>  
>     _byte[]_ BinaryStringToByteArray ( in string BinaryString );
>  
> I need to use a byte[] compatible with Java and JavaScript native byte
> arrays.
>  
> Currently the only solution I found is to use the wrappedJSObject
> property of an JavaScript defined component, but this does only work
> if the XPCom client is JavaScript too...
>  
> Any ideas ?
>  
> ------
> Murilo Perrone
> CertiSign
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> dev-tech-xpcom mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-xpcom
>  

_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

David Huynh
In reply to this post by Murilo Camões Perrone
Darin Fisher wrote:
> ACString can be used to implement this sort of thing.  It has the
> property that elements of the array can be 0, so it can be used to pass
> "byte array" values.  When converting an ACString to a JS string,
> XPConnect inflates each byte to a double-byte value, setting the upper
> byte to zero.  When converting the other direction, the upper byte is
> truncated.  If the JS consumer treats each element of the JS string as a
> byte of binary data, then it can be made to work pretty well.

Is there another hack for passing/returning an array of nsISupports
instead of bytes?

Thanks.

David
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

Christian Biesinger
David Huynh wrote:
> Is there another hack for passing/returning an array of nsISupports
> instead of bytes?

If this is JS->JS communication via XPCOM, you could use wrappedJSObject:
http://www.mozilla.org/scriptable/js-components-status.html#unwrapping
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

David Huynh
In reply to this post by David Huynh
Christian Biesinger wrote:
> David Huynh wrote:
>
>> Is there another hack for passing/returning an array of nsISupports
>> instead of bytes?
>
>
> If this is JS->JS communication via XPCOM, you could use wrappedJSObject:
> http://www.mozilla.org/scriptable/js-components-status.html#unwrapping

Thanks for the suggestion. I know of this trick before. Unfortunately,
the caller is in Javascript from Web pages and does not have permission
to go through this backdoor. The call must go through an XPCOM interface.

David
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: An array passed by a single parameter

kan-4
In reply to this post by David Huynh
David Huynh wrote:

> Is there another hack for passing/returning an array of nsISupports
> instead of bytes?
Not sure, but what is about nsISupportsArray?

--
WBR, kan.
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom