public abstract class AbstractPacket extends Object implements Packet
PropertiesBasedPacketFactory
,
this subclass must implement the following method:
public static Packet newPacket(byte[] rawData, int offset, int length)
throws IllegalRawDataException
Modifier and Type | Class and Description |
---|---|
static class |
AbstractPacket.AbstractBuilder
Abstract packet builder class.
|
static class |
AbstractPacket.AbstractHeader
Abstract immutable header class.
|
Packet.Builder, Packet.Header
Constructor and Description |
---|
AbstractPacket() |
Modifier and Type | Method and Description |
---|---|
protected String |
buildHexString()
This method builds the value
toHexString() will return
using the return value of getRawData() . |
protected byte[] |
buildRawData()
This method builds the value
getRawData() will return by
concatenating the header's raw data and the payload's raw data. |
protected String |
buildString()
This method builds the value
toString() will return by
concatenating the header's string representation and the payload's string representation. |
protected int |
calcHashCode()
This method calculates the value
hashCode() will return using
the header's hash code and the payload's hash code. |
protected int |
calcLength()
This method calculates the value
length() will return by
adding up the header length and the payload length. |
<T extends Packet> |
contains(Class<T> clazz)
Returns true if this packet is or its payload includes an object of
specified packet class; false otherwise.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
<T extends Packet> |
get(Class<T> clazz)
Traverses this packet and its payload to find an object of
the specified packet class and returns the object.
|
abstract Packet.Builder |
getBuilder()
Returns a new Builder object populated with this object's fields' values.
|
Packet.Header |
getHeader()
Returns the Header object representing this packet's header.
|
Packet |
getOuterOf(Class<? extends Packet> clazz)
Returns the outer packet object of
a packet object
get(clazz) returns. |
Packet |
getPayload()
Returns the Packet object representing this packet's payload.
|
byte[] |
getRawData()
Returns this packet's raw data.
|
int |
hashCode()
Returns a hash code value for the object.
|
Iterator<Packet> |
iterator() |
int |
length()
Returns the packet length in bytes.
|
String |
toHexString()
Returns the hex string representation of this object.
|
String |
toString()
Returns a string representation of the object.
|
public Packet.Header getHeader()
public Packet getPayload()
getPayload
in interface Packet
protected int calcLength()
length()
will return by
adding up the header length and the payload length.
If you write this subclass which represents a packet with extra parts (e.g. a trailer),
you need to override this method.public int length()
calcLength()
and caches the return value
when it is called for the first time,
and then, this method returns the cached value from the second time.protected byte[] buildRawData()
getRawData()
will return by
concatenating the header's raw data and the payload's raw data.
If you write this subclass which represents a packet with extra parts (e.g. a trailer),
you need to override this method.public byte[] getRawData()
buildRawData()
and caches the return value
when it is called for the first time,
and then, this method returns the cached value from the second time.
More correctly, this method returns a copy of the cached value,
so that the cache can't be changed.getRawData
in interface Packet
public <T extends Packet> T get(Class<T> clazz)
Packet
public Packet getOuterOf(Class<? extends Packet> clazz)
Packet
get(clazz)
returns.getOuterOf
in interface Packet
clazz
- the packet class of the object
whose outer packet object is what you want to getpublic <T extends Packet> boolean contains(Class<T> clazz)
Packet
public abstract Packet.Builder getBuilder()
Packet
getBuilder
in interface Packet
protected String buildHexString()
toHexString()
will return
using the return value of getRawData()
.
Each octet in this return value is separated by a white space.
(e.g. 00 01 02 03 aa bb cc)public String toHexString()
buildHexString()
and caches the return value
when it is called for the first time,
and then, this method returns the cached value from the second time.protected String buildString()
toString()
will return by
concatenating the header's string representation and the payload's string representation.
If you write this subclass which represents a packet with extra parts (e.g. a trailer),
you need to override this method.public String toString()
buildString()
and caches the return value
when it is called for the first time,
and then, this method returns the cached value from the second time.public boolean equals(Object obj)
protected int calcHashCode()
hashCode()
will return using
the header's hash code and the payload's hash code.
If you write this subclass which represents a packet with extra parts (e.g. a trailer),
you need to override this method.public int hashCode()
calcHashCode()
and caches the return value
when it is called for the first time,
and then, this method returns the cached value from the second time.Copyright © 2011–2016 Pcap4J.org. All rights reserved.