[erlang-questions] Terms to binary and viceversa

Alessandro Sivieri alessandro.sivieri@REDACTED
Thu Jan 17 00:26:59 CET 2013


Hi all,

I have the following situation: two processes are exchanging data, and one
particular packet contains the following three contents:

   - a character (which defines the type of that specific packet, in this
   case it is a 'A')
   - a pid
   - some binary data which I encode and decode in a specific way

The question is: how can I extract the pid part using the bit syntax? I am
able to extract the character, and I know that the pid (encoded to binary
with term_to_binary) is 27 bytes, or 216 bits, so my first thought was
something like

<<$A:8, Pid:216, Data/binary>>

But this is wrong because in Pid at this point I have a very large integer
(and I see my error in that pattern), so do I have to get each single byte
of the 27 bytes composing the pid one by one or is there a pattern that
immediately matches that term giving me something that I can pass to
binary_to_term? I have experimented a little but I always obtain a no
matching clause...

Alessandro

-- 
Sivieri Alessandro
alessandro.sivieri@REDACTED
http://sivieri.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130117/3695ba97/attachment.htm>


More information about the erlang-questions mailing list