[erlang-questions] how: Strange issue with Jinterface and marshalling

Raimo Niskanen <>
Wed May 7 09:00:05 CEST 2008

On Tue, May 06, 2008 at 02:31:14PM -0700, Jonathan Gray wrote:
> I am having a very strange problem when marshalling an Erlang term in Java
> using Jinterface and sending it to a native erlang program.
> I am able to unmarshall from Erlang to Java, and marshall and unmarshall
> within Java.
> After spending some time looking into the raw data, it appears that when I
> marshall the same term within Erlang there is an extra byte at the front
> that is missing from the Java marshalled bytes.  It is a hex 0x83 (integer
> 131).
> If I append this to the front of my byte array in Java, and then send, my
> erlang program can demarshall it without any problem whatsoever.  The
> Jinterface library is able to demarshall either format (w/ and w/o the
> header) into the exact same erlang terms.
> Is this some type of version header?  I'm using the Jinterface library
> that came with the erlang version I am using.
> We have moved forward by simply appending this extra byte, but this is a
> very strange behavior and we'd like to figure out what it's all about.

OtpOutputStream is a raw creature with several uses. One of them can
be to encode an Erlang term in external format (aka marshal).

There is no such function in Jinterface (as far as I know) as
erlang:term_to_binary/1. Jinterface is focused on communicating
with Erlang nodes. If you use OtpMbox.send() it will add the
version tag itself.

But if you want to create a marshalled Erlang term using
OtpOutputStream you have to prepend it with the external
format version magic byte 131, though you should use
the constant OtpExternal.versionTag instead;
it is clearer.

> Thanks for any help.
> Jonathan Gray
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions


/ Raimo Niskanen, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list