@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;
    }
@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);
    }