org.avineas.comli.impl
public class Packet extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static byte |
ACK |
static byte |
ACKTYPE
Acknowledgment packet.
|
static int |
HEADERSIZE |
static int |
MAXSIZE |
Constructor and Description |
---|
Packet(byte[] data)
Construct a packet from a received byte array.
|
Packet(byte[] data,
int offset,
int size)
Construct a packet from a received byte array.
|
Packet(int destination,
byte stamp,
byte type,
byte[] contents)
Construct a packet from the parameters
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getBytes()
Get the bytes of this packet, array variant
|
int |
getBytes(byte[] buffer,
int offset)
Get the bytes of this packet to be transferred over the
line.
|
byte[] |
getContents()
Get the contents of this packet.
|
int |
getDestination()
Get the destination of this packet.
|
byte |
getStamp()
Get the stamp of this packet.
|
byte |
getType()
Get the packet type.
|
static boolean |
isAck(byte type)
Is the packet type an ACK?
|
static boolean |
isRequest(byte type)
Is the type passed a request type?
|
static boolean |
isTransfer(byte type)
Is the type passed a response type?
|
void |
setContents(byte[] contents)
Set the contents/payload of the packet.
|
void |
setDestination(int destination)
Set the destination of this packet.
|
void |
setStamp(byte stamp)
Set the packet stamp.
|
void |
setType(byte type)
Set the packet type.
|
public static final byte ACKTYPE
public static final byte ACK
public static final int MAXSIZE
public static final int HEADERSIZE
public Packet(byte[] data)
data
- The contents of the datapublic Packet(byte[] data, int offset, int size)
data
- The packet bufferoffset
- The offset in the buffer where the data startssize
- The size of the data receivedpublic Packet(int destination, byte stamp, byte type, byte[] contents)
destination
- The destination for the packetstamp
- The stamptype
- The message typecontents
- The contents of the messagepublic void setStamp(byte stamp)
public void setType(byte type)
public void setDestination(int destination)
public void setContents(byte[] contents)
public byte[] getContents()
public int getDestination()
public byte getStamp()
public byte getType()
public int getBytes(byte[] buffer, int offset)
buffer
- The buffer to write the data inoffset
- The start offset to start writingpublic byte[] getBytes()
public static boolean isAck(byte type)
type
- The packet type to checkpublic static boolean isRequest(byte type)
type
- The packet type to checkpublic static boolean isTransfer(byte type)
type
- The packet type to check