@Test public void testDeserializeTruncated() throws Exception { byte[] bits = pimJoinPrune.serialize(); PacketTestUtils.testDeserializeTruncated(deserializer, bits); }
@Override public byte[] serialize() { int length = 4; byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); length += payloadData.length; } final byte[] data = new byte[length]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put((byte) ((this.version & 0xf) << 4 | this.type & 0xf)); bb.put(this.reserved); bb.putShort(this.checksum); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof PIM) { ((PIM) this.parent).setPIMType(TYPE_JOIN_PRUNE_REQUEST); } if (this.checksum == 0) { bb.rewind(); int accumulation = 0; for (int i = 0; i < length / 2; ++i) { accumulation += 0xffff & bb.getShort(); } if (length % 2 > 0) { accumulation += (bb.get() & 0xff) << 8; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); this.checksum = (short) (~accumulation & 0xffff); bb.putShort(2, this.checksum); } return data; }
PIM extends BasePacket { @Override public byte[] serialize() { int length = 4; byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); length += payloadData.length; } final byte[] data = new byte[length]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put((byte) ((this.version & 0xf) << 4 | this.type & 0xf)); bb.put(this.reserved); bb.putShort(this.checksum); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof PIM) { ((PIM) this.parent).setPIMType(TYPE_JOIN_PRUNE_REQUEST); } if (this.checksum == 0) { bb.rewind(); int accumulation = 0; for (int i = 0; i < length / 2; ++i) { accumulation += 0xffff & bb.getShort(); } if (length % 2 > 0) { accumulation += (bb.get() & 0xff) << 8; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); this.checksum = (short) (~accumulation & 0xffff); bb.putShort(2, this.checksum); } return data; } }
PIM extends BasePacket { @Override public byte[] serialize() { int length = 4; byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); length += payloadData.length; } final byte[] data = new byte[length]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put((byte) ((this.version & 0xf) << 4 | this.type & 0xf)); bb.put(this.reserved); bb.putShort(this.checksum); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof PIM) { ((PIM) this.parent).setPIMType(TYPE_JOIN_PRUNE_REQUEST); } if (this.checksum == 0) { bb.rewind(); int accumulation = 0; for (int i = 0; i < length / 2; ++i) { accumulation += 0xffff & bb.getShort(); } if (length % 2 > 0) { accumulation += (bb.get() & 0xff) << 8; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); this.checksum = (short) (~accumulation & 0xffff); bb.putShort(2, this.checksum); } return data; } PIM(); }
PIM extends BasePacket { @Override public byte[] serialize() { int length = 4; byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); length += payloadData.length; } final byte[] data = new byte[length]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put((byte) ((this.version & 0xf) << 4 | this.type & 0xf)); bb.put(this.reserved); bb.putShort(this.checksum); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof PIM) { ((PIM) this.parent).setPIMType(TYPE_JOIN_PRUNE_REQUEST); } if (this.checksum == 0) { bb.rewind(); int accumulation = 0; for (int i = 0; i < length / 2; ++i) { accumulation += 0xffff & bb.getShort(); } if (length % 2 > 0) { accumulation += (bb.get() & 0xff) << 8; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); this.checksum = (short) (~accumulation & 0xffff); bb.putShort(2, this.checksum); } return data; } PIM(); byte getPimMsgType(); PIM setPIMType(final byte type); byte getVersion(); void setVersion(byte version); byte getReserved(); void setReserved(byte reserved); short getChecksum(); void setChecksum(short checksum); @Override int hashCode(); @Override boolean equals(final Object obj); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
            final int length); static Deserializer<PIM> deserializer(); @Override String toString(); }
PIM extends BasePacket { @Override public byte[] serialize() { int length = 4; byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); length += payloadData.length; } final byte[] data = new byte[length]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put((byte) ((this.version & 0xf) << 4 | this.type & 0xf)); bb.put(this.reserved); bb.putShort(this.checksum); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof PIM) { ((PIM) this.parent).setPIMType(TYPE_JOIN_PRUNE_REQUEST); } if (this.checksum == 0) { bb.rewind(); int accumulation = 0; for (int i = 0; i < length / 2; ++i) { accumulation += 0xffff & bb.getShort(); } if (length % 2 > 0) { accumulation += (bb.get() & 0xff) << 8; } accumulation = (accumulation >> 16 & 0xffff) + (accumulation & 0xffff); this.checksum = (short) (~accumulation & 0xffff); bb.putShort(2, this.checksum); } return data; } PIM(); byte getPimMsgType(); PIM setPIMType(final byte type); byte getVersion(); void setVersion(byte version); byte getReserved(); void setReserved(byte reserved); short getChecksum(); void setChecksum(short checksum); @Override int hashCode(); @Override boolean equals(final Object obj); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
            final int length); static Deserializer<PIM> deserializer(); @Override String toString(); static final IpAddress PIM_ADDRESS; static final byte TYPE_HELLO; static final byte TYPE_REGISTER; static final byte TYPE_REGISTER_STOP; static final byte TYPE_JOIN_PRUNE_REQUEST; static final byte TYPE_BOOTSTRAP; static final byte TYPE_ASSERT; static final byte TYPE_GRAFT; static final byte TYPE_GRAFT_ACK; static final byte TYPE_CANDIDATE_RP_ADV; static final int PIM_HEADER_LEN; static final byte ADDRESS_FAMILY_IP4; static final byte ADDRESS_FAMILY_IP6; static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP; }