[erlang-questions] port_command and marshalling

Per Hedeland per@REDACTED
Mon Oct 29 18:16:42 CET 2007


"Paul Oliver" <puzza007@REDACTED> wrotes:
>
>I have a port open with opts [{packet, 4}, binary] and call it using:
>
>port_command(Port, term_to_binary(Msg)),
>
>With the definition of  receive_erlang_port_msg below, for a
>particular call, I get:
>
>lengthstr[0]=0
>lengthstr[1]=0
>lengthstr[2]=5
>lengthstr[3]=-103
>LEN=-103
>
>Does anyone know where the -103 comes from?

It comes from 153 + your use of an apparently-signed type 'byte' for the
length bytes. If you switch that to 'unsigned char' it will work (at
least upto len = 2^31-1). Or cast the bytes to 'unsigned char' instead
of 'unsigned' (which isn't some "generic" thing, but just short for
'unsigned int').

--Per Hedeland



More information about the erlang-questions mailing list