From 6941af88ad016141f568279f065cb181074f1f9f Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Thu, 6 Mar 2014 15:13:34 +0100 Subject: erl_interface: Add ei encode/decode for maps --- lib/erl_interface/doc/src/ei.xml | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'lib/erl_interface/doc/src') diff --git a/lib/erl_interface/doc/src/ei.xml b/lib/erl_interface/doc/src/ei.xml index ab185c9179..1756ee8a7d 100644 --- a/lib/erl_interface/doc/src/ei.xml +++ b/lib/erl_interface/doc/src/ei.xml @@ -4,7 +4,7 @@
- 20012013 + 20012014 Ericsson AB. All Rights Reserved. @@ -416,6 +416,27 @@ ei_x_encode_empty_list(&x); tail of a list.

+ + intei_encode_map_header(char *buf, int *index, int arity) + intei_x_encode_map_header(ei_x_buff* x, int arity) + Encode a map + +

This function encodes a map header, with a specified arity. The next + arity terms encoded will be the keys of the map, and the next + arity terms after that will be the corresponding values in + same order.

+

E.g. to encode the map #{a => "Apple", b => "Banana"}:

+
+ei_x_encode_map_header(&x, 2);
+ei_x_encode_atom(&x, "a");
+ei_x_encode_atom(&x, "b");
+ei_x_encode_string(&x, "Apple");
+ei_x_encode_string(&x, "Banana");
+        
+

A correctly encoded map can not have duplicate keys, but no check + for duplicate keys is done by this function.

+
+
intei_get_type(const char *buf, const int *index, int *type, int *size) Fetch the type and size of an encoded term @@ -637,6 +658,19 @@ ei_x_encode_empty_list(&x); instead.

+ + intei_decode_map_header(const char *buf, int *index, int *arity) + Decode a map + +

This function decodes a map header from the binary + format. The number of key-value pairs is returned in + arity. Keys and values follows, first all keys and then all values, + which makes a total of arity*2 terms. + Keys and values are paired according to their order, the first key + with the first value and so on. If arity is zero, it's an empty map. + A correctly encoded map does not have duplicate keys.

+
+
intei_decode_ei_term(const char* buf, int* index, ei_term* term) Decode a term, without prior knowledge of type -- cgit v1.2.3