public void write_external_fun(final String module, final String function, final int arity) { write1(OtpExternal.externalFunTag); write_atom(module); write_atom(function); write_long(arity); }
/** * Write an array of bytes to the stream as an Erlang bitstr. * * @param bin * the array of bytes to write. * @param pad_bits * the number of zero pad bits at the low end of the last byte */ public void write_bitstr(final byte[] bin, final int pad_bits) { if (pad_bits == 0) { write_binary(bin); return; } write1(OtpExternal.bitBinTag); write4BE(bin.length); write1(8 - pad_bits); writeN(bin); }
/** * Convert this tuple to the equivalent Erlang external representation. * * @param buf * an output stream to which the encoded tuple should be written. */ @Override public void encode(final OtpOutputStream buf) { final int arity = elems.length; buf.write_tuple_head(arity); for (int i = 0; i < arity; i++) { buf.write_any(elems[i]); } }
/** * Write an Erlang list header to the stream. After calling this method, you * must write 'arity' elements to the stream followed by nil, or it will not * be possible to decode it later. * * @param arity * the number of elements in the list. */ public void write_list_head(final int arity) { if (arity == 0) { write_nil(); } else { write1(OtpExternal.listTag); write4BE(arity); } }
private void sendExit(final int tag, final OtpErlangPid from, final OtpErlangPid dest, final OtpErlangObject reason) throws IOException { if (!connected) { throw new IOException("Not connected"); } @SuppressWarnings("resource") final OtpOutputStream header = new OtpOutputStream(headerLen); // preamble: 4 byte length + "passthrough" tag header.write4BE(0); // reserve space for length header.write1(passThrough); header.write1(version); // header header.write_tuple_head(4); header.write_long(tag); header.write_any(from); header.write_any(dest); header.write_any(reason); // fix up length in preamble header.poke4BE(0, header.size() - 4); do_send(header); }
protected void sendStatus(final String status) throws IOException { @SuppressWarnings("resource") final OtpOutputStream obuf = new OtpOutputStream(); obuf.write2BE(status.length() + 1); obuf.write1(ChallengeStatus); obuf.write(status.getBytes()); obuf.writeToAndFlush(socket.getOutputStream()); if (traceLevel >= handshakeThreshold) { System.out.println("-> " + "HANDSHAKE sendStatus" + " status=" + status + " local=" + localNode); } }
public static OtpOutputStream encodeTsGetRequest(String tableName, Collection<Cell> keyValues, int timeout) { final OtpOutputStream os = new OtpOutputStream(); os.write(OtpExternal.versionTag); // NB: this is the reqired 0x83 (131) value // NB: TsGetReq is a 4-tuple: tsgetreq, tableName, [key values], timeout os.write_tuple_head(4); os.write_atom(TS_GET_REQ); os.write_binary(tableName.getBytes(StandardCharsets.UTF_8)); os.write_list_head(keyValues.size()); for (Cell cell : keyValues) { writeTsCellToStream(os, cell); } os.write_nil(); // NB: finishes the list if (timeout != 0) { os.write_long(timeout); } else { os.write_atom(UNDEFINED); } return os; }
public static OtpOutputStream encodeTsQueryRequest(String queryText, byte[] coverageContext) { final OtpOutputStream os = new OtpOutputStream(); os.write(OtpExternal.versionTag); // NB: this is the reqired 0x83 (131) value // TsQueryReq is a 4-tuple: {'tsqueryreq', TsInterpolation, boolIsStreaming, bytesCoverContext} os.write_tuple_head(4); os.write_atom(TS_QUERY_REQ); // TsInterpolation is a 3-tuple // {'tsinterpolation', query, []} empty list is interpolations os.write_tuple_head(3); os.write_atom(TS_INTERPOLATION); os.write_binary(queryText.getBytes(StandardCharsets.UTF_8)); // interpolations is an empty list os.write_nil(); // streaming is false for now os.write_boolean(false); if (coverageContext == null) { // cover_context is an undefined atom os.write_atom(UNDEFINED); } else { os.write_binary(coverageContext); } return os; }
final long index, final long uniq, final OtpErlangObject[] freeVars) { if (arity == -1) { write1(OtpExternal.funTag); write4BE(freeVars.length); pid.encode(this); write_atom(module); write_long(index); write_long(uniq); for (final OtpErlangObject fv : freeVars) { fv.encode(this); write1(OtpExternal.newFunTag); final 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); for (final OtpErlangObject fv : freeVars) { fv.encode(this); poke4BE(saveSizePos, getPos() - saveSizePos);
write_nil(); break; default: if (len <= 65535 && is8bitString(s)) { // 8-bit string try { final byte[] bytebuf = s.getBytes("ISO-8859-1"); write1(OtpExternal.stringTag); write2BE(len); writeN(bytebuf); } catch (final UnsupportedEncodingException e) { write_nil(); // it should never ever get here... write_list_head(codePoints.length); for (final int codePoint : codePoints) { write_int(codePoint); write_nil();
final OtpOutputStream oos = new OtpOutputStream(o); if (oos.size() < 5) { oos.writeToAndFlush(this); close(); } catch (final IOException e) { throw new java.lang.IllegalArgumentException( final int destCount = startCount + oos.size(); fixedSize = destCount; final Deflater def = new Deflater(level); this, def); try { write1(OtpExternal.compressedTag); write4BE(oos.size()); oos.writeTo(dos); oos.writeTo(this); close(); } catch (final IOException e2) { throw new java.lang.IllegalArgumentException(
stream.write_binary(cell.getVarcharAsUTF8String().getBytes(CharsetUtils.UTF_8)); stream.write_long(cell.getLong()); stream.write_long(cell.getTimestamp()); stream.write_boolean(cell.getBoolean()); stream.write_double(cell.getDouble()); stream.write_binary(cell.getBlob());
/** * Write an Erlang port to the stream. * * @param node * the nodename. * * @param id * an arbitrary number. Only the low order 28 bits will be used. * * @param creation * another arbitrary number. Only the low order 2 bits will be * used. * */ public void write_port(final String node, final int id, final int creation) { write1(OtpExternal.portTag); write_atom(node); write4BE(id & 0xfffffff); // 28 bits write1(creation & 0x3); // 2 bits }
protected void encode(final OtpOutputStream buf, final int start) { final int arity = arity() - start; if (arity > 0) { buf.write_list_head(arity); for (int i = start; i < arity + start; i++) { buf.write_any(elems[i]); } } if (lastTail == null) { buf.write_nil(); } else { buf.write_any(lastTail); } }
public void write_big_integer(final BigInteger v) { if (v.bitLength() < 64) { this.write_long(v.longValue(), true); return; } final int signum = v.signum(); BigInteger val = v; if (signum < 0) { val = val.negate(); } final byte[] magnitude = val.toByteArray(); final int n = magnitude.length; // Reverse the array to make it little endian. for (int i = 0, j = n; i < j--; i++) { // Swap [i] with [j] final byte b = magnitude[i]; magnitude[i] = magnitude[j]; magnitude[j] = b; } if ((n & 0xFF) == n) { write1(OtpExternal.smallBigTag); write1(n); // length } else { write1(OtpExternal.largeBigTag); write4BE(n); // length } write1(signum < 0 ? 1 : 0); // sign // Write the array writeN(magnitude); }
/** * Write a single byte to the stream as an Erlang integer. The byte is * really an IDL 'octet', that is, unsigned. * * @param b * the byte to use. */ public void write_byte(final byte b) { this.write_long(b & 0xffL, true); }
/** * Convert this number to the equivalent Erlang external representation. * * @param buf * an output stream to which the encoded number should be * written. */ @Override public void encode(final OtpOutputStream buf) { if (bigVal != null) { buf.write_big_integer(bigVal); } else { buf.write_long(val); } }
@SuppressWarnings("resource") void send(final OtpErlangPid from, final String dest, final OtpErlangObject msg) throws IOException { // encode and send the message sendBuf(from, dest, new OtpOutputStream(msg)); }