public OtpErlangRef read_ref()
{
String node;
int id;
int creation;
int tag;
tag = read1skip_version();
switch (tag)
{
case OtpExternal.refTag:
node = read_atom();
id = read4BE() & 0x3ffff; // 18 bits
creation = read1() & 0x03; // 2 bits
return new OtpErlangRef(node, id, creation);
case OtpExternal.newRefTag:
int arity = read2BE();
node = read_atom();
creation = read1() & 0x03; // 2 bits
int[] ids = new int[arity];
for (int i = 0; i < arity; i++)
{
ids[i] = read4BE();
}
ids[0] &= 0x3ffff; // first id gets truncated to 18 bits
return new OtpErlangRef(node, ids, creation);
default:
throw new OtpErlangDecodeException("Wrong tag encountered, expected ref, got " + tag);
}
}