@Override public byte[] serialize() { int length = 2 + this.chassisId.getLength() + 2 + this.portId.getLength() + 2 + this.ttl.getLength() + 2; if (this.optionalTLVList != null) { for (LLDPTLV tlv : this.optionalTLVList) { length += 2 + tlv.getLength(); } } byte[] data = new byte[length]; ByteBuffer bb = ByteBuffer.wrap(data); bb.put(this.chassisId.serialize()); bb.put(this.portId.serialize()); bb.put(this.ttl.serialize()); if (this.optionalTLVList != null) { for (LLDPTLV tlv : this.optionalTLVList) { bb.put(tlv.serialize()); } } bb.putShort((short) 0); // End of LLDPDU if (this.parent != null && this.parent instanceof Ethernet) ((Ethernet) this.parent).setEtherType(Ethernet.TYPE_LLDP); return data; }