aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/encode
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface/src/encode')
-rw-r--r--lib/erl_interface/src/encode/encode_pid.c13
-rw-r--r--lib/erl_interface/src/encode/encode_port.c12
-rw-r--r--lib/erl_interface/src/encode/encode_ref.c10
3 files changed, 24 insertions, 11 deletions
diff --git a/lib/erl_interface/src/encode/encode_pid.c b/lib/erl_interface/src/encode/encode_pid.c
index 7b01b7045f..3eabbdcc02 100644
--- a/lib/erl_interface/src/encode/encode_pid.c
+++ b/lib/erl_interface/src/encode/encode_pid.c
@@ -24,7 +24,8 @@
int ei_encode_pid(char *buf, int *index, const erlang_pid *p)
{
- char *s = buf + *index;
+ char* s = buf + *index;
+ const char tag = (p->creation > 3) ? ERL_NEW_PID_EXT : ERL_PID_EXT;
++(*index); /* skip ERL_PID_EXT */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node),
@@ -32,17 +33,21 @@ int ei_encode_pid(char *buf, int *index, const erlang_pid *p)
return -1;
if (buf) {
- put8(s,ERL_PID_EXT);
+ put8(s, tag);
s = buf + *index;
/* now the integers */
put32be(s,p->num & 0x7fff); /* 15 bits */
put32be(s,p->serial & 0x1fff); /* 13 bits */
- put8(s,(p->creation & 0x03)); /* 2 bits */
+ if (tag == ERL_PID_EXT) {
+ put8(s,(p->creation & 0x03)); /* 2 bits */
+ } else {
+ put32be(s, p->creation); /* 32 bits */
+ }
}
- *index += 4 + 4 + 1;
+ *index += 4 + 4 + (tag == ERL_PID_EXT ? 1 : 4);
return 0;
}
diff --git a/lib/erl_interface/src/encode/encode_port.c b/lib/erl_interface/src/encode/encode_port.c
index a7468e5917..a6e7d3541a 100644
--- a/lib/erl_interface/src/encode/encode_port.c
+++ b/lib/erl_interface/src/encode/encode_port.c
@@ -25,6 +25,7 @@
int ei_encode_port(char *buf, int *index, const erlang_port *p)
{
char *s = buf + *index;
+ const char tag = p->creation > 3 ? ERL_NEW_PORT_EXT : ERL_PORT_EXT;
++(*index); /* skip ERL_PORT_EXT */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8,
@@ -32,16 +33,19 @@ int ei_encode_port(char *buf, int *index, const erlang_port *p)
return -1;
}
if (buf) {
- put8(s,ERL_PORT_EXT);
+ put8(s, tag);
s = buf + *index;
/* now the integers */
put32be(s,p->id & 0x0fffffff /* 28 bits */);
- put8(s,(p->creation & 0x03));
+ if (tag == ERL_PORT_EXT) {
+ put8(s,(p->creation & 0x03));
+ } else {
+ put32be(s, p->creation);
+ }
}
-
- *index += 4 + 1;
+ *index += 4 + (tag == ERL_PORT_EXT ? 1 : 4);
return 0;
}
diff --git a/lib/erl_interface/src/encode/encode_ref.c b/lib/erl_interface/src/encode/encode_ref.c
index 0f27a086f0..956a9a7e16 100644
--- a/lib/erl_interface/src/encode/encode_ref.c
+++ b/lib/erl_interface/src/encode/encode_ref.c
@@ -24,6 +24,7 @@
int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
{
+ const char tag = (p->creation > 3) ? ERL_NEWER_REFERENCE_EXT : ERL_NEW_REFERENCE_EXT;
char *s = buf + *index;
int i;
@@ -36,7 +37,7 @@ int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
/* Always encode as an extended reference; all participating parties
are now expected to be able to decode extended references. */
if (buf) {
- put8(s,ERL_NEW_REFERENCE_EXT);
+ put8(s, tag);
/* first, number of integers */
put16be(s, p->len);
@@ -45,12 +46,15 @@ int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
s = buf + *index;
/* now the integers */
- put8(s,(p->creation & 0x03));
+ if (tag == ERL_NEW_REFERENCE_EXT)
+ put8(s,(p->creation & 0x03));
+ else
+ put32be(s, p->creation);
for (i = 0; i < p->len; i++)
put32be(s,p->n[i]);
}
- *index += p->len*4 + 1;
+ *index += p->len*4 + (tag == ERL_NEW_REFERENCE_EXT ? 1 : 4);
return 0;
}