JdwpPacket
public
final
class
JdwpPacket
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.device.server.jdwp.chunkhandler.JdwpPacket |
A JDWP packet, sitting at the start of a ByteBuffer somewhere.
This allows us to wrap a "pointer" to the data with the results of decoding the packet.
None of the operations here are synchronized. If multiple threads will be accessing the same ByteBuffers, external sync will be required.
Use the constructor to create an empty packet, or "findPacket()" to wrap a JdwpPacket around existing data.
Summary
Constants | |
|---|---|
int |
JDWP_HEADER_LEN
|
Public constructors | |
|---|---|
JdwpPacket(ByteBuffer buf)
Create a new, empty packet, in "buf". |
|
Public methods | |
|---|---|
void
|
consume()
Consume the JDWP packet. |
void
|
copy(ByteBuffer into)
Helper function to copy the packet into a new buffer. |
static
JdwpPacket
|
findPacket(ByteBuffer buf)
|
static
JdwpPacket
|
findPacketHeader(ByteBuffer buf)
|
void
|
finishPacket(int cmdSet, int cmd, int payloadLength)
Finish a packet created with newPacket(). |
int
|
getId()
Return the packet's ID. |
int
|
getLength()
Return the length of a packet. |
static
int
|
getPacketLength(ByteBuffer buf)
When the "buf" contains JdwpPackets the first 4 bytes are the length of the packet. |
ByteBuffer
|
getPayload()
Return a slice of the byte buffer, positioned past the JDWP header to the start of the chunk header. |
boolean
|
is(int cmdSet, int cmd)
|
boolean
|
isEmpty()
Returns "true" if this JDWP packet has no data. |
boolean
|
isError()
Returns "true" if this JDWP packet is a reply with a nonzero error code. |
boolean
|
isReply()
Returns "true" if this JDWP packet is tagged as a reply. |
void
|
log(String action)
|
void
|
move(ByteBuffer buf)
"Move" the packet data out of the buffer we're sitting on and into buf at the current position. |
void
|
setPayload(ByteBuffer buf)
Replace the payload of the package with a buffer. |
String
|
toString()
|
void
|
write(SocketChannel chan)
Write our packet to "chan". |
Constants
JDWP_HEADER_LEN
public static final int JDWP_HEADER_LEN
Constant Value: 11 (0x0000000b)
Public constructors
JdwpPacket
public JdwpPacket (ByteBuffer buf)
Create a new, empty packet, in "buf".
| Parameters | |
|---|---|
buf |
ByteBuffer |
Public methods
consume
public void consume ()
Consume the JDWP packet.
On entry and exit, "position" is at the end of data in buffer.
copy
public void copy (ByteBuffer into)
Helper function to copy the packet into a new buffer.
| Parameters | |
|---|---|
into |
ByteBuffer |
findPacket
public static JdwpPacket findPacket (ByteBuffer buf)
| Parameters | |
|---|---|
buf |
ByteBuffer |
| Returns | |
|---|---|
JdwpPacket |
|
findPacketHeader
public static JdwpPacket findPacketHeader (ByteBuffer buf)
| Parameters | |
|---|---|
buf |
ByteBuffer |
| Returns | |
|---|---|
JdwpPacket |
|
finishPacket
public void finishPacket (int cmdSet,
int cmd,
int payloadLength)Finish a packet created with newPacket().
This always creates a command packet, with the next serial number in sequence.
We have to take "payloadLength" as an argument because we can't see the position in the "slice" returned by getPayload(). We could fish it out of the chunk header, but it's legal for there to be more than one chunk in a JDWP packet.
On exit, "position" points to the end of the data.
| Parameters | |
|---|---|
cmdSet |
int |
cmd |
int |
payloadLength |
int |
getId
public int getId ()
Return the packet's ID. For a reply packet, this allows us to match the reply with the original request.
| Returns | |
|---|---|
int |
|
getLength
public int getLength ()
Return the length of a packet. This includes the header, so an empty packet is 11 bytes long.
| Returns | |
|---|---|
int |
|
getPacketLength
public static int getPacketLength (ByteBuffer buf)
When the "buf" contains JdwpPackets the first 4 bytes are the length of the packet. This helper function reads the first 4 bytes and validates that the length is at least the size of the JDWP header.
| Parameters | |
|---|---|
buf |
ByteBuffer: a buffer assumed to contain a jdwp packet. |
| Returns | |
|---|---|
int |
-1 if the length is invalid, otherwise the length of the packet. |
getPayload
public ByteBuffer getPayload ()
Return a slice of the byte buffer, positioned past the JDWP header to the start of the chunk header. The buffer's limit will be set to the size of the payload if the size is known; if this is a packet under construction the limit will be set to the end of the buffer.
Doesn't examine the packet at all -- works on empty buffers.
| Returns | |
|---|---|
ByteBuffer |
|
is
public boolean is (int cmdSet,
int cmd)| Parameters | |
|---|---|
cmdSet |
int |
cmd |
int |
| Returns | |
|---|---|
boolean |
|
isEmpty
public boolean isEmpty ()
Returns "true" if this JDWP packet has no data.
| Returns | |
|---|---|
boolean |
|
isError
public boolean isError ()
Returns "true" if this JDWP packet is a reply with a nonzero error code.
| Returns | |
|---|---|
boolean |
|
isReply
public boolean isReply ()
Returns "true" if this JDWP packet is tagged as a reply.
| Returns | |
|---|---|
boolean |
|
log
public void log (String action)
| Parameters | |
|---|---|
action |
String |
move
public void move (ByteBuffer buf)
"Move" the packet data out of the buffer we're sitting on and into buf at the current position.
| Parameters | |
|---|---|
buf |
ByteBuffer |
setPayload
public void setPayload (ByteBuffer buf)
Replace the payload of the package with a buffer. The current position is unchanged.
| Parameters | |
|---|---|
buf |
ByteBuffer |
toString
public String toString ()
| Returns | |
|---|---|
String |
|
write
public void write (SocketChannel chan)
Write our packet to "chan".
The JDWP packet starts at offset 0 and ends at mBuffer.position().
| Parameters | |
|---|---|
chan |
SocketChannel |