code: public void write_ref(OtpErlangRef ref) {
  	int[] ids = ref.ids();
          int arity = ids.length;
  
  	write1(ref.tag());
  	write2BE(arity);
  	write_atom(ref.node());
  
  	switch (ref.tag()) {
  	case OtpExternal.newRefTag:
  	    write1(ref.creation());
  	    write4BE(ids[0] & 0x3ffff); // first word gets truncated to 18 bits
  	    break;
  	case OtpExternal.newerRefTag:
  	    write4BE(ref.creation());
  	    write4BE(ids[0]); // full first word
  	    break;
  	default:
  	    throw new AssertionError("Invalid ref tag " + ref.tag());
  	}
  
  	for (int i = 1; i < arity; i++) {
  	    write4BE(ids[i]);
  	}
      }
docs: Write an Erlang ref to the stream.
  
  @param ref
  the reference