aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2014-03-06 15:13:34 +0100
committerSverker Eriksson <[email protected]>2014-03-06 20:10:19 +0100
commit6941af88ad016141f568279f065cb181074f1f9f (patch)
treebadef0333dd52b55a523f89d01a932a658e2f88c /lib/erl_interface/src
parent453cba0046ec8363a4c3cea97ce22a6f4ff0b75a (diff)
downloadotp-6941af88ad016141f568279f065cb181074f1f9f.tar.gz
otp-6941af88ad016141f568279f065cb181074f1f9f.tar.bz2
otp-6941af88ad016141f568279f065cb181074f1f9f.zip
erl_interface: Add ei encode/decode for maps
Diffstat (limited to 'lib/erl_interface/src')
-rw-r--r--lib/erl_interface/src/decode/decode_tuple_header.c23
-rw-r--r--lib/erl_interface/src/encode/encode_tuple_header.c19
-rw-r--r--lib/erl_interface/src/misc/ei_decode_term.c3
-rw-r--r--lib/erl_interface/src/misc/ei_x_encode.c12
4 files changed, 53 insertions, 4 deletions
diff --git a/lib/erl_interface/src/decode/decode_tuple_header.c b/lib/erl_interface/src/decode/decode_tuple_header.c
index c0ba14ea47..698be1b97a 100644
--- a/lib/erl_interface/src/decode/decode_tuple_header.c
+++ b/lib/erl_interface/src/decode/decode_tuple_header.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 1998-2009. All Rights Reserved.
+ * Copyright Ericsson AB 1998-2014. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -45,3 +45,24 @@ int ei_decode_tuple_header(const char *buf, int *index, int *arity)
return 0;
}
+
+int ei_decode_map_header(const char *buf, int *index, int *arity)
+{
+ const char *s = buf + *index;
+ const char *s0 = s;
+ int i;
+
+ switch ((i=get8(s))) {
+ case ERL_MAP_EXT:
+ if (arity) *arity = get32be(s);
+ else s += 4;
+ break;
+
+ default:
+ return -1;
+ }
+
+ *index += s-s0;
+
+ return 0;
+}
diff --git a/lib/erl_interface/src/encode/encode_tuple_header.c b/lib/erl_interface/src/encode/encode_tuple_header.c
index 97a3d1f808..5b11e60447 100644
--- a/lib/erl_interface/src/encode/encode_tuple_header.c
+++ b/lib/erl_interface/src/encode/encode_tuple_header.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 1998-2009. All Rights Reserved.
+ * Copyright Ericsson AB 1998-2014. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -47,3 +47,20 @@ int ei_encode_tuple_header(char *buf, int *index, int arity)
return 0;
}
+int ei_encode_map_header(char *buf, int *index, int arity)
+{
+ char *s = buf + *index;
+ char *s0 = s;
+
+ if (arity < 0) return -1;
+
+ if (!buf) s += 5;
+ else {
+ put8(s,ERL_MAP_EXT);
+ put32be(s,arity);
+ }
+
+ *index += s-s0;
+
+ return 0;
+}
diff --git a/lib/erl_interface/src/misc/ei_decode_term.c b/lib/erl_interface/src/misc/ei_decode_term.c
index ce5ae5b19d..2e7317f781 100644
--- a/lib/erl_interface/src/misc/ei_decode_term.c
+++ b/lib/erl_interface/src/misc/ei_decode_term.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2001-2013. All Rights Reserved.
+ * Copyright Ericsson AB 2001-2014. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -100,6 +100,7 @@ int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
term->size = get16be(s);
return 0;
case ERL_LIST_EXT:
+ case ERL_MAP_EXT:
term->arity = get32be(s);
break;
case ERL_BINARY_EXT:
diff --git a/lib/erl_interface/src/misc/ei_x_encode.c b/lib/erl_interface/src/misc/ei_x_encode.c
index 14d0b56b8f..10542c88a5 100644
--- a/lib/erl_interface/src/misc/ei_x_encode.c
+++ b/lib/erl_interface/src/misc/ei_x_encode.c
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
- * Copyright Ericsson AB 2001-2013. All Rights Reserved.
+ * Copyright Ericsson AB 2001-2014. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
@@ -206,6 +206,16 @@ int ei_x_encode_tuple_header(ei_x_buff* x, long n)
return ei_encode_tuple_header(x->buff, &x->index, n);
}
+int ei_x_encode_map_header(ei_x_buff* x, long n)
+{
+ int i = x->index;
+ if (ei_encode_map_header(NULL, &i, n) == -1)
+ return -1;
+ if (!x_fix_buff(x, i))
+ return -1;
+ return ei_encode_map_header(x->buff, &x->index, n);
+}
+
int ei_x_encode_atom(ei_x_buff* x, const char* s)
{
return ei_x_encode_atom_len_as(x, s, strlen(s), ERLANG_LATIN1, ERLANG_LATIN1);