@Test public void testSerialize() { Fragment frag = new Fragment(); frag.setNextHeader((byte) 0x11); frag.setFragmentOffset((short) 0x1f); frag.setMoreFragment((byte) 1); frag.setIdentification(0x1357); frag.setPayload(udp); assertArrayEquals(frag.serialize(), bytePacket); }
@Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } int payloadLength = 0; if (payloadData != null) { payloadLength = payloadData.length; } final byte[] data = new byte[HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.nextHeader); bb.put((byte) 0); bb.putShort((short) ( (this.fragmentOffset & 0x1fff) << 3 | this.moreFragment & 0x1 )); bb.putInt(this.identification); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof IExtensionHeader) { ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_FRAG); } return data; }
Fragment extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } int payloadLength = 0; if (payloadData != null) { payloadLength = payloadData.length; } final byte[] data = new byte[HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.nextHeader); bb.put((byte) 0); bb.putShort((short) ( (this.fragmentOffset & 0x1fff) << 3 | this.moreFragment & 0x1 )); bb.putInt(this.identification); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof IExtensionHeader) { ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_FRAG); } return data; } }
Fragment extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } int payloadLength = 0; if (payloadData != null) { payloadLength = payloadData.length; } final byte[] data = new byte[HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.nextHeader); bb.put((byte) 0); bb.putShort((short) ( (this.fragmentOffset & 0x1fff) << 3 | this.moreFragment & 0x1 )); bb.putInt(this.identification); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof IExtensionHeader) { ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_FRAG); } return data; }  }
Fragment extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } int payloadLength = 0; if (payloadData != null) { payloadLength = payloadData.length; } final byte[] data = new byte[HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.nextHeader); bb.put((byte) 0); bb.putShort((short) ( (this.fragmentOffset & 0x1fff) << 3 | this.moreFragment & 0x1 )); bb.putInt(this.identification); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof IExtensionHeader) { ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_FRAG); } return data; }  @Override byte getNextHeader(); @Override Fragment setNextHeader(final byte nextHeader); short getFragmentOffset(); Fragment setFragmentOffset(final short fragmentOffset); byte getMoreFragment(); Fragment setMoreFragment(final byte moreFragment); int getIdentification(); Fragment setIdentification(final int identification); @Override byte[] serialize(); @Override IPacket deserialize(byte[] data, int offset, int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<Fragment> deserializer(); @Override String toString(); }
Fragment extends BasePacket implements IExtensionHeader { @Override public byte[] serialize() { byte[] payloadData = null; if (this.payload != null) { this.payload.setParent(this); payloadData = this.payload.serialize(); } int payloadLength = 0; if (payloadData != null) { payloadLength = payloadData.length; } final byte[] data = new byte[HEADER_LENGTH + payloadLength]; final ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.nextHeader); bb.put((byte) 0); bb.putShort((short) ( (this.fragmentOffset & 0x1fff) << 3 | this.moreFragment & 0x1 )); bb.putInt(this.identification); if (payloadData != null) { bb.put(payloadData); } if (this.parent != null && this.parent instanceof IExtensionHeader) { ((IExtensionHeader) this.parent).setNextHeader(IPv6.PROTOCOL_FRAG); } return data; }  @Override byte getNextHeader(); @Override Fragment setNextHeader(final byte nextHeader); short getFragmentOffset(); Fragment setFragmentOffset(final short fragmentOffset); byte getMoreFragment(); Fragment setMoreFragment(final byte moreFragment); int getIdentification(); Fragment setIdentification(final int identification); @Override byte[] serialize(); @Override IPacket deserialize(byte[] data, int offset, int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<Fragment> deserializer(); @Override String toString(); static final byte HEADER_LENGTH; }