@Test public void testDeserialize() throws Exception { UDP udp = deserializer.deserialize(bytePacketUDP4, 0, bytePacketUDP4.length); assertThat(udp.getSourcePort(), is(0x50)); assertThat(udp.getDestinationPort(), is(0x60)); assertThat(udp.getLength(), is((short) 8)); assertThat(udp.getChecksum(), is((short) 0x7bda)); }
@Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.sourcePort = (bb.getShort() & 0xffff); this.destinationPort = (bb.getShort() & 0xffff); this.length = bb.getShort(); this.checksum = bb.getShort(); Deserializer<? extends IPacket> deserializer; if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.destinationPort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.destinationPort); } else if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.sourcePort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.sourcePort); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; }
UDP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.sourcePort = (bb.getShort() & 0xffff); this.destinationPort = (bb.getShort() & 0xffff); this.length = bb.getShort(); this.checksum = bb.getShort(); Deserializer<? extends IPacket> deserializer; if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.destinationPort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.destinationPort); } else if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.sourcePort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.sourcePort); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; } }
UDP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.sourcePort = (bb.getShort() & 0xffff); this.destinationPort = (bb.getShort() & 0xffff); this.length = bb.getShort(); this.checksum = bb.getShort(); Deserializer<? extends IPacket> deserializer; if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.destinationPort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.destinationPort); } else if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.sourcePort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.sourcePort); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; }  }
UDP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.sourcePort = (bb.getShort() & 0xffff); this.destinationPort = (bb.getShort() & 0xffff); this.length = bb.getShort(); this.checksum = bb.getShort(); Deserializer<? extends IPacket> deserializer; if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.destinationPort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.destinationPort); } else if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.sourcePort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.sourcePort); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; }  int getSourcePort(); UDP setSourcePort(final int sourcePort); int getDestinationPort(); UDP setDestinationPort(final int destinationPort); short getLength(); short getChecksum(); UDP setChecksum(final short checksum); @Override void resetChecksum(); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<UDP> deserializer(); @Override String toString(); }
UDP extends BasePacket { @Override public IPacket deserialize(final byte[] data, final int offset, final int length) { final ByteBuffer bb = ByteBuffer.wrap(data, offset, length); this.sourcePort = (bb.getShort() & 0xffff); this.destinationPort = (bb.getShort() & 0xffff); this.length = bb.getShort(); this.checksum = bb.getShort(); Deserializer<? extends IPacket> deserializer; if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.destinationPort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.destinationPort); } else if (UDP.PORT_DESERIALIZER_MAP.containsKey(this.sourcePort)) { deserializer = UDP.PORT_DESERIALIZER_MAP.get(this.sourcePort); } else { deserializer = Data.deserializer(); } try { this.payload = deserializer.deserialize(data, bb.position(), bb.limit() - bb.position()); this.payload.setParent(this); } catch (DeserializationException e) { return this; } return this; }  int getSourcePort(); UDP setSourcePort(final int sourcePort); int getDestinationPort(); UDP setDestinationPort(final int destinationPort); short getLength(); short getChecksum(); UDP setChecksum(final short checksum); @Override void resetChecksum(); @Override byte[] serialize(); @Override IPacket deserialize(final byte[] data, final int offset,
                               final int length); @Override int hashCode(); @Override boolean equals(final Object obj); static Deserializer<UDP> deserializer(); @Override String toString(); static final Map<Integer, Deserializer<? extends IPacket>> PORT_DESERIALIZER_MAP; static final int DHCP_SERVER_PORT; static final int DHCP_CLIENT_PORT; }