public void write_fun(OtpErlangPid pid, String module, long old_index, int arity, byte[] md5, long index, long uniq, OtpErlangObject[] freeVars) { if (arity == -1) { write1(OtpExternal.funTag); write4BE(freeVars.Length); pid.encode(this); write_atom(module); write_long(index); write_long(uniq); foreach (OtpErlangObject fv in freeVars) { fv.encode(this); } } else { write1(OtpExternal.newFunTag); int saveSizePos = getPos(); write4BE(0); // this is where we patch in the size write1(arity); writeN(md5); write4BE(index); write4BE(freeVars.Length); write_atom(module); write_long(old_index); write_long(uniq); pid.encode(this); foreach (OtpErlangObject fv in freeVars) { fv.encode(this); } poke4BE(saveSizePos, getPos() - saveSizePos); } }