JInterface question

Olivier Sambourg olivier.sambourg@REDACTED
Wed Jun 15 21:29:22 CEST 2005


Thank you, I'll check this doc.

My only problem with this leading byte is that I have to manually add  
or remove it on the client side so that I can retrieve the data, even  
though the OtpInputStream and OtpOutputStream classes are supposed to  
be used to manipulate data in the Erlang external format. Am I  
missing something ?

 From the OtpOutputStream class documentation :
Provides a stream for encoding Erlang terms to external format, for  
transmission or storage.

Anyway my problem can be solved like this :

public void sendObject(OtpErlangObject O) throws XMPPException {
         OtpOutputStream stream = new OtpOutputStream();
         String data;
         stream.write((byte) 131); // add leading byte
         stream.write_any(O);
         data = Base64.encodeBytes(stream.toByteArray());

         sendMessage(data);
     }

public OtpErlangObject receiveObject(String encoded) throws  
OtpErlangDecodeException {
             byte[] decoded = Base64.decode(encoded);
             OtpInputStream stream = new OtpInputStream(decoded, 1,  
decoded.length - 1); // strip leading byte
             OtpErlangObject obj = OtpErlangObject.decode(stream);

             return obj;
     }


Regards,

--
Olivier



Le 15 juin 05 à 20:49, Vlad Dumitrescu a écrit :

> ----- Original Message ----- From: Olivier Sambourg
>
>> It seems the only difference is the leading 131 byte in erlang.
>> Can anyone confirm that it is always present ? If it is the case,
>> I guess I have my solution.
>>
>
> Hi,
>
> Yes, the 131 (*) is always there, because term_to_binary encodes  
> into Erlang external format.
>
> See also $ERL_TOP/erts/emulator/internal_doc/erl_ext_dist.txt for  
> details about the format, if you're interested.
>
> regards,
> Vlad
>
> (*) Future releases might change the actual value, I think, because  
> it's a "version magic" field.
>




More information about the erlang-questions mailing list