public class PacketReader extends Object
ByteBuffer
and provides methods to read rich data types
from it. Supported data types are from the com.hp.util.ip
package.Constructor and Description |
---|
PacketReader(ByteBuffer b)
Constructs a packet reader wrapping a
ByteBuffer . |
Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Returns the byte array that backs this reader.
|
int |
limit()
Returns the limit of usable bytes.
|
int |
odometer()
Number of bytes read since creation of this reader or since the last
call to reset the odometer.
|
byte |
peek(int offset)
Peek at the byte at the specified offset from current reader index.
|
int |
peekU16()
Peek at the next two bytes from the current position, interpreting them
as an unsigned 16-bit value.
|
int |
peekU16(int offset)
Peek at the next two bytes from the given offset from the current
position, interpreting them as an unsigned 16-bit value.
|
int |
peekU24()
Peek at the next three bytes from the current position, interpreting
them as an unsigned 24-bit value.
|
int |
peekU24(int offset)
Peek at the next three bytes from the given offset from the current
position, interpreting them as an unsigned 24-bit value.
|
short |
peekU8()
Peek at the next byte from the current position, interpreting it as
an unsigned 8-bit value.
|
short |
peekU8(int offset)
Peek at the byte at the given offset from the current position,
interpreting it as an unsigned 8-bit value.
|
int |
readableBytes()
Returns the count of readable bytes remaining.
|
BigPortNumber |
readBigPortNumber()
Reads a (u32) port number from the buffer.
|
byte |
readByte()
Reads and returns a single byte from the buffer.
|
byte[] |
readBytes(int n)
Reads the specified number of bytes from the buffer, returning them in
a newly allocated array.
|
EthernetType |
readEthernetType()
Reads an Ethernet type from the buffer.
|
ICMPv4Type |
readIcmpv4Type()
Reads an ICMPv4 Type from the buffer.
|
ICMPv6Type |
readIcmpv6Type()
Reads an ICMPv6 Type from the buffer.
|
int |
readInt()
Reads four bytes as an int.
|
IpProtocol |
readIpProtocol()
Reads an IP Protocol from the buffer.
|
IpAddress |
readIPv4Address()
Reads an IPv4 address from the buffer.
|
IpAddress |
readIPv6Address()
Reads an IPv6 address from the buffer.
|
long |
readLong()
Reads eight bytes as a long.
|
MacAddress |
readMacAddress()
Reads a MAC address from the buffer.
|
PortNumber |
readPortNumber()
Reads a (u16) port number from the buffer.
|
String |
readString(int n)
Reads a string from the buffer.
|
int |
readU16()
Reads two bytes, interpreting them as an unsigned 16-bit value.
|
int |
readU24()
Reads three bytes, interpreting them as an unsigned 24-bit value.
|
long |
readU32()
Reads four bytes, interpreting them as an unsigned 32-bit value.
|
short |
readU8()
Reads a byte, interpreting it as an unsigned 8-bit value.
|
VlanId |
readVlanId()
Readsa VLAN ID from the buffer.
|
void |
resetIndex()
Resets the buffer position to the reader's original starting position.
|
void |
resetOdometer()
Resets the odometer to the current buffer position.
|
int |
ri()
Returns the reader index.
|
void |
ri(int newPosition)
Sets the reader index to the given position.
|
void |
skip(int count)
Skips buffer data by increasing the current reader index by the
specified number of bytes.
|
String |
toString() |
public PacketReader(ByteBuffer b)
ByteBuffer
.b
- the byte bufferpublic int odometer()
public void resetOdometer()
public void resetIndex()
public int ri()
public void ri(int newPosition)
newPosition
- the new positionIllegalArgumentException
- if preconditions for newPosition are
not metpublic int readableBytes()
public int limit()
public byte[] array()
public IpAddress readIPv4Address()
public IpAddress readIPv6Address()
public MacAddress readMacAddress()
public VlanId readVlanId()
public EthernetType readEthernetType()
public IpProtocol readIpProtocol()
public ICMPv4Type readIcmpv4Type()
public ICMPv6Type readIcmpv6Type()
public PortNumber readPortNumber()
public BigPortNumber readBigPortNumber()
public String readString(int n)
n
- the size of the string fieldpublic byte[] readBytes(int n)
n
- the number of bytes to readpublic byte readByte()
public void skip(int count)
count
- the number of bytes to skippublic int readInt()
public long readLong()
public short readU8()
public byte peek(int offset)
offset
- from the current reader indexpublic short peekU8(int offset)
offset
- the offset from the current positionpublic short peekU8()
public int peekU16(int offset)
offset
- the offset from the current positionpublic int peekU16()
public int peekU24(int offset)
offset
- the offset from the current positionpublic int peekU24()
public int readU16()
public int readU24()
public long readU32()
Copyright © 2015. All Rights Reserved.