[erlang-questions] RecordA serialization ... time ... deserialization to RecordB?

Max Bourinov bourinov@REDACTED
Fri Nov 11 11:39:34 CET 2011


Hi guys,

Thank you very much for your replies!

Actually I was looking for something like module dict. (Now I discovered it
and it is already in a heavy use :-).

I wanted to be able to easily store user profiles via term_to_binary to
persistent storage...
    Then modify some code...
        And read them back again with binary_to_term.

If I do it with records - they won't properly recover coz (we all know)
that records "disappear" in precompiling time and all I have is kind of
tuple. Joel is right I needed something like a tags and it seems that dict
does this job.



On Fri, Nov 11, 2011 at 1:15 PM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:

> This is not exactly what was asked for, but…
>
> In JOBS, I have created a jobs_info module that includes jobs.hrl and uses
> exprecs's -export_records() feature.
>
> https://github.com/esl/jobs/blob/master/src/jobs_info.erl
>
> I use this module to present metadata about the various objects in JOBS.
> The only thing needed in order to 'serialize' a new type of record is to
> define it in jobs.hrl and add it to the -export_records() directive.
>
> BR,
> Ulf W
>
> -module(jobs_info).
>
>
>
> -export([pp/1]).
>
>
>
> -include("jobs.hrl").
>
> -include_lib("parse_trans/include/exprecs.hrl").
>
>
>
> -export_records([rr, cr, grp, rate, queue, sampler]).
>
>
>
>
>
> pp(L) when is_list(L) ->
>
>     [pp(X) || X <- L];
>
> pp(X) ->
>
>     case '#is_record-'(X) of
>
> 	true ->
>
> 	    RecName = element(1,X),
>
> 	    {RecName, lists:zip(
>
> 			'#info-'(RecName,fields),
>
> 			pp(tl(tuple_to_list(X))))};
>
> 	false ->
>
> 	    if is_tuple(X) ->
>
> 		    list_to_tuple(pp(tuple_to_list(X)));
>
> 	       true ->
>
> 		    X
>
> 	    end
>
>     end.
>
>
> On 11 Nov 2011, at 10:57, Joel Reymont wrote:
>
> You need to serialize the record fields with their tags. Then you can use
> something like exprecs to set individual fields in the new record
> definition.
>
> This assumes you are just adding fields and names of old fields stay the
> same.
>
> ---
> Sent from my iPhone
>
> On Nov 11, 2011, at 10:44 AM, Maxim Treskin <zerthurd@REDACTED> wrote:
>
> Max, what are you need indeed? Your words sounds very strange.
>
> On 11 November 2011 15:31, Max Bourinov <bourinov@REDACTED> wrote:
>
>> Hello Erlangers,
>>
>> What is a best way to serialize record, modify record's code and then
>> deserialize it back?
>>
>> I seen https://github.com/esl/parse_trans. Is this what I need or there
>> are another options?
>>
>> Maybe I better use another data structure?
>>
>> p.s. Of course performance is always important.
>>
>> Best regards,
>> Max
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>
> --
> Maxim Treskin
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
>  Ulf Wiger, CTO, Erlang Solutions, Ltd.
> http://erlang-solutions.com
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111111/ac0ed44c/attachment.htm>


More information about the erlang-questions mailing list