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

Ulf Wiger <>
Fri Nov 11 11:15:51 CET 2011


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 <> wrote:
> 
>> Max, what are you need indeed? Your words sounds very strange.
>> 
>> On 11 November 2011 15:31, Max Bourinov <> 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
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
>> 
>> 
>> 
>> -- 
>> Maxim Treskin
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111111/9b0fe768/attachment.html>


More information about the erlang-questions mailing list