[erlang-questions] How erlang handle complicated data structure like C?

Masklinn masklinn@REDACTED
Mon Sep 19 07:39:36 CEST 2011


On 19 sept. 2011, at 07:09, Jovi Zhang <bookjovi@REDACTED> wrote:
> But how to change record format to binary correctly? because the
> binary need to transport in network.
> When I try below, the output seems wrong.
> 
> -record(semper_packet_t,
>    {tdm_leg = <<1:8, 3:8>>,
>     ip_leg = 2
>     }).
> 
> term_to_binary(#semper_packet_t.tdm_leg)
> 
> result: <<131,97,2>>
you need an encoder and a decoder, to and from your binary wire format. You don't generally put raw binary data in a record, and there is just about no way erlang's binary packing of its terms (which exists for e<->e exchanges) is going to match a struct defined by an arbitrary third party. 


More information about the erlang-questions mailing list