BSN extends BasePacket { @Override public byte[] serialize() { short length = 4 + 2 + 2 ; byte[] payloadData = null; if (this.payload != null) { payload.setParent(this); payloadData = payload.serialize(); length += payloadData.length; } byte[] data = new byte[length]; ByteBuffer bb = ByteBuffer.wrap(data); bb.putInt(BSN_MAGIC); bb.putShort(this.type); bb.putShort(this.version); if (payloadData != null) bb.put(payloadData); if (this.parent != null && this.parent instanceof Ethernet) ((Ethernet)this.parent).setEtherType(Ethernet.TYPE_BSN); return data; } BSN();  BSN(short type); short getType(); BSN setType(short type); short getVersion(); BSN setVersion(short version); @Override byte[] serialize(); @Override IPacket deserialize(byte[] data, int offset, int length); @Override int hashCode(); @Override boolean equals(Object obj); String toString(); static final int BSN_MAGIC; static final short BSN_VERSION_CURRENT; static final short BSN_TYPE_PROBE; static final short BSN_TYPE_BDDP; static Map<Short, Class<? extends IPacket>> typeClassMap; }
@Test public void testSerialize() throws Exception { Ethernet pkt = getProbePacket(); byte[] serialized = pkt.serialize(); assertTrue(Arrays.equals(probePkt, serialized)); }