aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/encode/encode_pid.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface/src/encode/encode_pid.c')
-rw-r--r--lib/erl_interface/src/encode/encode_pid.c13
1 files changed, 9 insertions, 4 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;
}