@Test public void testSeekPastMagicBytes() { byte[] brokenMessage = HEX.decode("000000"); try { new NubitsSerializer(MainNetParams.get()).seekPastMagicBytes(ByteBuffer.wrap(brokenMessage)); fail(); } catch (BufferUnderflowException e) { } }
public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } }
NubitsSerializer { public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } }
NubitsSerializer { public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } NubitsSerializer(NetworkParameters params);  NubitsSerializer(NetworkParameters params, boolean parseLazy, boolean parseRetain); }
NubitsSerializer { public void seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } 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 seekPastMagicBytes(ByteBuffer in) throws BufferUnderflowException { int magicCursor = 3; while (true) { byte b = in.get(); byte expectedByte = (byte)(0xFF & params.getPacketMagic() >>> (magicCursor * 8)); if (b == expectedByte) { magicCursor--; if (magicCursor < 0) { return; } else { } } else { magicCursor = 3; } } } 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();  }