@Test public void testDeserialize() throws Exception { Ethernet pkt = (Ethernet) new Ethernet().deserialize(probePkt, 0, probePkt.length); assertTrue(Arrays.equals(probePkt, pkt.serialize())); Ethernet expected = getProbePacket(); assertEquals(expected, pkt); }
@Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); int magic = bb.getInt(); if (magic != BSN_MAGIC) { throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } IPacket payload; if (typeClassMap.containsKey(this.type)) { Class<? extends IPacket> clazz = typeClassMap.get(this.type); try { payload = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("Error parsing payload for BSN packet" + e); } } else { payload = new Data(); } this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); return this; }
BSN extends BasePacket { @Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); int magic = bb.getInt(); if (magic != BSN_MAGIC) { throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } IPacket payload; if (typeClassMap.containsKey(this.type)) { Class<? extends IPacket> clazz = typeClassMap.get(this.type); try { payload = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("Error parsing payload for BSN packet" + e); } } else { payload = new Data(); } this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); return this; } }
BSN extends BasePacket { @Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); int magic = bb.getInt(); if (magic != BSN_MAGIC) { throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } IPacket payload; if (typeClassMap.containsKey(this.type)) { Class<? extends IPacket> clazz = typeClassMap.get(this.type); try { payload = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("Error parsing payload for BSN packet" + e); } } else { payload = new Data(); } this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); return this; } BSN();  BSN(short type); }
BSN extends BasePacket { @Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); int magic = bb.getInt(); if (magic != BSN_MAGIC) { throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } IPacket payload; if (typeClassMap.containsKey(this.type)) { Class<? extends IPacket> clazz = typeClassMap.get(this.type); try { payload = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("Error parsing payload for BSN packet" + e); } } else { payload = new Data(); } this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); return this; } 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(); }
BSN extends BasePacket { @Override public IPacket deserialize(byte[] data, int offset, int length) throws PacketParsingException { ByteBuffer bb = ByteBuffer.wrap(data, offset, length); int magic = bb.getInt(); if (magic != BSN_MAGIC) { throw new PacketParsingException("Invalid BSN magic " + magic); } this.type = bb.getShort(); this.version = bb.getShort(); if (this.version != BSN_VERSION_CURRENT) { throw new PacketParsingException( "Invalid BSN packet version " + this.version + ", should be " + BSN_VERSION_CURRENT); } IPacket payload; if (typeClassMap.containsKey(this.type)) { Class<? extends IPacket> clazz = typeClassMap.get(this.type); try { payload = clazz.newInstance(); } catch (Exception e) { throw new RuntimeException("Error parsing payload for BSN packet" + e); } } else { payload = new Data(); } this.payload = payload.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); return this; } 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; }