aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/decode/decode_binary.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2019-04-03 21:16:59 +0200
committerSverker Eriksson <[email protected]>2019-04-17 19:09:12 +0200
commit6465de7e3a5393a80ed0e2c63f012fd126de706f (patch)
treef85198d2afe765a8f3b7c94ed31b36830346b006 /lib/erl_interface/src/decode/decode_binary.c
parent46aa940b9d771c4806aacaf065c2f637474e9815 (diff)
downloadotp-6465de7e3a5393a80ed0e2c63f012fd126de706f.tar.gz
otp-6465de7e3a5393a80ed0e2c63f012fd126de706f.tar.bz2
otp-6465de7e3a5393a80ed0e2c63f012fd126de706f.zip
erl_interface: Add bitstring and export fun support
Diffstat (limited to 'lib/erl_interface/src/decode/decode_binary.c')
-rw-r--r--lib/erl_interface/src/decode/decode_binary.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/erl_interface/src/decode/decode_binary.c b/lib/erl_interface/src/decode/decode_binary.c
index 5b8d234984..2799438bef 100644
--- a/lib/erl_interface/src/decode/decode_binary.c
+++ b/lib/erl_interface/src/decode/decode_binary.c
@@ -40,4 +40,40 @@ int ei_decode_binary(const char *buf, int *index, void *p, long *lenp)
return 0;
}
+int ei_decode_bitstring(const char *buf, int *index, void *p, size_t plen,
+ size_t *bitsp)
+{
+ const char *s = buf + *index;
+ const char *s0 = s;
+ unsigned long len;
+ unsigned char last_bits;
+ const unsigned char tag = get8(s);
+
+ if (tag == ERL_BINARY_EXT) {
+ long bytes;
+ int ret = ei_decode_binary(buf, index, p, &bytes);
+ if (bitsp)
+ *bitsp = (size_t)bytes * 8;
+ return ret;
+ }
+
+ if (tag != ERL_BIT_BINARY_EXT)
+ return -1;
+
+ len = get32be(s);
+ last_bits = get8(s);
+
+ if (len > plen || ((last_bits==0) != (len==0)) || last_bits > 8)
+ return -1;
+
+ if (p)
+ memcpy(p, s, len);
+ s += len;
+
+ if (bitsp)
+ *bitsp = (len == 0) ? 0 : ((len-1) * 8) + last_bits;
+
+ *index += s-s0;
+ return 0;
+}