Little-Endian Active Mode Tcp ?

Per Hedeland per@REDACTED
Wed May 28 21:36:52 CEST 2003

Eric Newhuis <enewhuis@REDACTED> wrote:
>The active-mode {packet, 4} socket is AMAZING.  This is what one needs.  
>Beautiful.  But...
>I'd love to get rid of the binary continuation fragments in my recursive 
>feed parsers.  I could do it if Erlang would parse the little-endian 
>header.  My messages originate from an Intel box and the 4-byte size 
>header is little-endian.  I want Erlang to handle those headers so I can 
>simplify my parser code to focus on the message content instead of 
>content + framing.

The {packet, N} format (whether on a socket or a port) is endian-
independent - always most significant byte first (or is it last?:-).  I
guess you can call that "big-endian" like the docs do, but IMHO that
term doesn't really apply to bytes on a wire. If whatever is sending the
packets doesn't obey that, it has a bug - I would certainly hope that it
isn't another Erlang node. (I.e. don't do write(fd, &integer, 4) in your
C code, which is inherently non-portable, but make sure you write the
bytes in the right order by whatever means you prefer...)

--Per Hedeland

More information about the erlang-questions mailing list