+1<br><br><div class="gmail_quote">2013/1/17 Fred Hebert <span dir="ltr"><<a href="mailto:mononcqc@ferd.ca" target="_blank">mononcqc@ferd.ca</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I went with whatever structure was mentionned in the parent post.<br>
<br>
If the pid expected is 27 bytes then it should work, if for example it<br>
equals some hardcoded node name (which is a big no-no to begin with.)<br>
Personally I'd use the Erlang External Term Format<br>
(<a href="http://erlang.org/doc/apps/erts/erl_ext_dist.html" target="_blank">http://erlang.org/doc/apps/erts/erl_ext_dist.html</a>) (or BERT) and<br>
serialize everything with it, or go with a prefix indicating the length<br>
of the term to follow to make it simpler.<br>
<div class="HOEnZb"><div class="h5"><br>
On 01/17, Bj�rn-Egil Dahlberg wrote:<br>
> Pids are not always 27 bytes. Names are atoms.<br>
><br>
> Example:<br>
><br>
> -module(t).<br>
><br>
> -compile([export_all]).<br>
><br>
> start() -><br>
>     Pid = self(),<br>
>     PidBin = term_to_binary(Pid),<br>
>     SomeData = <<"some other data">>,<br>
>     Bin = <<$A, PidBin/binary, SomeData/binary>>,<br>
>     <<$A, 131, 103, 100, Len:16, Name:Len/binary, Id:4/binary,<br>
> Serial:4/binary, Creation, Rest/binary>> = Bin,<br>
>     DecPid = binary_to_term(<<131, 103, 100, Len:16, Name/binary,<br>
> Id/binary, Serial/binary, Creation>>),<br>
>     {Pid, DecPid, Rest}.<br>
><br>
> Output:<br>
><br>
> egil@destiny ~ $ erl -sname some-node-name-used<br>
> Erlang R15B (erts-5.9) [source] [smp:4:4] [async-threads:0] [hipe]<br>
> [kernel-poll:false]<br>
><br>
> Eshell V5.9  (abort with ^G)<br>
> (some-node-name-used@destiny)1> t:start().<br>
> {<0.37.0>,<0.37.0>,<<"some other data">>}<br>
><br>
><br>
> // Björn-Egil<br>
><br>
><br>
> 2013/1/17 Fred Hebert <<a href="mailto:mononcqc@ferd.ca">mononcqc@ferd.ca</a>><br>
><br>
> > The pattern:<br>
> ><br>
> >     <<$A, BinPid:27/binary, Data/binary>><br>
> ><br>
> > Should do it. Then you can get `Pid` by calling `binary_to_term/1` on<br>
> > `BinPid`. By default, the size of the `binary` type of matching is in<br>
> > bytes, so you should be extracting it fine. To get it in bits, you'd<br>
> > need to specify `BinPid:216/binary-unit:1`, for example.<br>
> ><br>
> > In your case, what you were doing is returning `Pid` as a 216 bits<br>
> > integer (the default type), not something you can use in any useful way.<br>
> ><br>
> > Regards,<br>
> > Fred.<br>
> ><br>
> > On 01/17, Alessandro Sivieri wrote:<br>
> > > Hi all,<br>
> > ><br>
> > > I have the following situation: two processes are exchanging data, and<br>
> > one<br>
> > > particular packet contains the following three contents:<br>
> > ><br>
> > >    - a character (which defines the type of that specific packet, in this<br>
> > >    case it is a 'A')<br>
> > >    - a pid<br>
> > >    - some binary data which I encode and decode in a specific way<br>
> > ><br>
> > > The question is: how can I extract the pid part using the bit syntax? I<br>
> > am<br>
> > > able to extract the character, and I know that the pid (encoded to binary<br>
> > > with term_to_binary) is 27 bytes, or 216 bits, so my first thought was<br>
> > > something like<br>
> > ><br>
> > > <<$A:8, Pid:216, Data/binary>><br>
> > ><br>
> > > But this is wrong because in Pid at this point I have a very large<br>
> > integer<br>
> > > (and I see my error in that pattern), so do I have to get each single<br>
> > byte<br>
> > > of the 27 bytes composing the pid one by one or is there a pattern that<br>
> > > immediately matches that term giving me something that I can pass to<br>
> > > binary_to_term? I have experimented a little but I always obtain a no<br>
> > > matching clause...<br>
> > ><br>
> > > Alessandro<br>
> > ><br>
> > > --<br>
> > > Sivieri Alessandro<br>
> > > <a href="mailto:alessandro.sivieri@gmail.com">alessandro.sivieri@gmail.com</a><br>
> > > <a href="http://sivieri.wordpress.com/" target="_blank">http://sivieri.wordpress.com/</a><br>
> ><br>
> > > _______________________________________________<br>
> > > erlang-questions mailing list<br>
> > > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> ><br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> > <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
> ><br>
</div></div></blockquote></div><br>