@Test public void testSerializeUnknownMessage() { NubitsSerializer bs = new NubitsSerializer(MainNetParams.get()); UnknownMessage a = new UnknownMessage(); ByteArrayOutputStream bos = new ByteArrayOutputStream(addrMessage.length); try { bs.serialize(a, bos); fail(); } catch (Throwable e) { } }
public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
NubitsSerializer { public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); } }
NubitsSerializer { public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); } NubitsSerializer(NetworkParameters params);  NubitsSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain); }
NubitsSerializer { public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); } NubitsSerializer(NetworkParameters params);  NubitsSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain); void serialize(String name, byte[] message, OutputStream out); void serialize(Message message, OutputStream out); Message deserialize(ByteBuffer in); NubitsPacketHeader deserializeHeader(ByteBuffer in); Message deserializePayload(NubitsPacketHeader header, ByteBuffer in); void seekPastMagicBytes(ByteBuffer in); boolean isParseLazyMode(); boolean isParseRetainMode(); }
NubitsSerializer { public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 ]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); } NubitsSerializer(NetworkParameters params);  NubitsSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain); void serialize(String name, byte[] message, OutputStream out); void serialize(Message message, OutputStream out); Message deserialize(ByteBuffer in); NubitsPacketHeader deserializeHeader(ByteBuffer in); Message deserializePayload(NubitsPacketHeader header, ByteBuffer in); void seekPastMagicBytes(ByteBuffer in); boolean isParseLazyMode(); boolean isParseRetainMode();  }