[erlang-questions] Encoding empty strings using ei

Peter Membrey peter@REDACTED
Thu Aug 1 08:52:14 CEST 2013

Hi Serge,

Thanks for taking the time to go through that, much appreciated!



----- Original Message -----
From: "Serge Aleynikov" <serge@REDACTED>
To: "Peter Membrey" <peter@REDACTED>
Cc: "Erlang Questions" <erlang-questions@REDACTED>
Sent: Thursday, 1 August, 2013 1:00:19 PM
Subject: Re: [erlang-questions] Encoding empty strings using ei

term_to_binary/1 is your friend:

1> term_to_binary({mylist, []}).

As you see at the end of that binary, the empty list gets encoded with a
special 106 ('j') tag, which is what ei_x_encode_empty_list() call does
under the hood.

$ grep ERL_NIL_EXT lib/erl_interface/include/ei.h
#define ERL_NIL_EXT           'j'

So the correct way to encode the {mylist, []} tuple in ei is to call:

      ei_x_encode_tuple_header(pbuf, 2);
      ei_x_encode_atom(pbuf, "mylist");



On 7/31/2013 11:57 AM, Peter Membrey wrote:
> Hi guys,
> I've got a C program that encodes a list of tuples to send to an Erlang
> server, something like this:
> {mylist, [{1,2,3} , {2,3,4} , {3,4,5}]}
> To do this I encode a list header with:
> ei_x_encode_list_header(ei_x_buff* x, int arity);
> and all is well.
> The question I have though, is what should I do if I encode this tuple?
> {mylist, [] }
> Should I encode the tuple, followed by an empty list
> (ei_x_encode_empty_list) or do I need to put in a list header with an
> arity of 0 and then add the empty list?
> In short, what is the correct way to encode an empty list using the ei
> interface.
> Thanks in advance!
> Cheers,
> Pete
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list