Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Serializing a list

sapan.gcet
Posted: Tue Oct 27, 2009 6:42 am Reply with quote
User Joined: 29 Sep 2009 Posts: 10 Location: Mumbai
Hi,

Lets assume that we have a list where,
List -> integer | List;

eg L1 = [1,[[2,3]],[4]].
when I perform
binary_to_list(list_to_binary(L1))
The result is [1,2,3,4]. I loose the original structure of the list.
How do then the serialization of the list is done?

Is there any other way we can perform 'binary_to_list(list_to_binary(L))'
functionality maintaining the structure of the list??

--
Regards,
Sapan Shah


Post received from mailinglist
View user's profile Send private message
maxlapshin
Posted: Tue Oct 27, 2009 6:45 am Reply with quote
User Joined: 15 Sep 2009 Posts: 159
term_to_binary, binary_to_term

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
View user's profile Send private message Send e-mail
sapan.gcet
Posted: Tue Oct 27, 2009 6:50 am Reply with quote
User Joined: 29 Sep 2009 Posts: 10 Location: Mumbai
Thanks... missed this part...

On Tue, Oct 27, 2009 at 12:13 PM, Max Lapshin <max.lapshin@gmail.com> wrote:

> term_to_binary, binary_to_term
>



--
Regards,
Sapan Shah


Post received from mailinglist
View user's profile Send private message
Guest
Posted: Wed Oct 28, 2009 12:11 am Reply with quote
Guest
On Oct 27, 2009, at 7:40 PM, sapan shah wrote:
> eg L1 = [1,[[2,3]],[4]].
> when I perform
> binary_to_list(list_to_binary(L1))
> The result is [1,2,3,4]. I loose the original structure of the list.

That's because list_to_binary/1 is defined to take an "iolist",
which is a tree structure whose leaves are binaries and *bytes*,
flatten it, and give you a binary. Had you tried a larger integer,
such as list_to_binary([999]), you would have had even more trouble.

What you want is term_to_binary/1 to do the encoding
and binary_to_term/1 to do the decoding.

Searching the 'erlang' manual page for 'to_binary' and 'binary_to'
would have found these.


________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
wuji
Posted: Wed Aug 22, 2012 6:27 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
Thursday that the U.S. added 176,000 private jobs in June, June, jordan 6 olympic 2012 June, more than expected, following a revised 136,000 jobs added
May.The number of people seeking U.S. unemployment benefits dropped last last [h3]cheap polo shirts[/h3] last week to the lowest level in six weeks, falling
to 374,000 seasonally adjusted.Brown expected around 100,000 nonfarm payroll jobs jobs [h3]knockoff designer *beep*[/h3] jobs and 115,000 private payroll jobs, seasonally adjusted, were added
June."I think the 'softer' payroll gains we saw in April April jordan 6 olympic 2012 April and May reflected a payback from an unusually mild
which pulled forward job gains that would have normally showed showed cheap polo ralph lauren showed up in the spring," Brown said.Brown expected payroll growth
June to be "somewhat better, but not especially strong" though though cheap polo shirts though the jobs report for June often has "uncertainty" because
the end of the school year and the influx of of imitation designer *beep* of summer jobs.This morning, the Bureau of Labor Statistics reported
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum