@Override
    public byte[] serialize() {
        byte[] payloadData = null;
        if (this.payload != null) {
            this.payload.setParent(this);
            payloadData = this.payload.serialize();
        }

        int headerLength = FIXED_HEADER_LENGTH + options.length;
        int payloadLength = 0;
        if (payloadData != null) {
            payloadLength = payloadData.length;
        }

        final byte[] data = new byte[headerLength + payloadLength];
        final ByteBuffer bb = ByteBuffer.wrap(data);

        bb.put(this.nextHeader);
        bb.put(this.headerExtLength);
        bb.put(this.options, 0, options.length);

        if (payloadData != null) {
            bb.put(payloadData);
        }

        if (this.parent != null && this.parent instanceof IExtensionHeader) {
            ((IExtensionHeader) this.parent).setNextHeader(this.type);
        }
        return data;
    }
@Test
    public void testSerialize() {
        BaseOptions baseopt = new BaseOptions();
        baseopt.setNextHeader((byte) 0x11);
        baseopt.setHeaderExtLength((byte) 0x00);
        baseopt.setOptions(options);
        baseopt.setPayload(udp);

        assertArrayEquals(baseopt.serialize(), bytePacket);
    }