public class PacketWriter extends Object
ByteBuffer and provides methods to write rich data types
into it. Supported data types are from the com.h3c.util.ip package.| Constructor and Description |
|---|
PacketWriter(byte[] bytes)
Constructs a packet writer backed by the byte array.
|
PacketWriter(ByteBuffer bb)
Constructs a packet writer wrapping a
ByteBuffer. |
PacketWriter(int capacity)
Constructs a packet writer creating a backing
ByteBuffer. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Returns the byte array that backs this reader.
|
void |
setU16(int idx,
int uv)
Set two bytes (unsigned 16-bit) equivalent to the given value at the
given index.
|
void |
setU32(int idx,
long uv)
Set two bytes (unsigned 32-bit) equivalent to the given value at the
given index.
|
String |
toString() |
int |
wi()
Returns the writer index.
|
int |
writableBytes()
Returns the count of writable bytes remaining.
|
void |
write(BigPortNumber pn)
Writes a (u32) port number to the buffer.
|
void |
write(EthernetType et)
Writes an Ethernet Type value (u16) to the buffer.
|
void |
write(ICMPv4Type it)
Writes an ICMPv4 Type value (u8) to the buffer.
|
void |
write(ICMPv6Type it)
Writes an ICMPv6 Type value (u8) to the buffer.
|
void |
write(IpAddress ip)
Writes an IP address to the buffer.
|
void |
write(IpProtocol ipp)
Writes an IP Protocol value (u8) to the buffer.
|
void |
write(MacAddress mac)
Writes a MAC address to the buffer.
|
void |
write(PortNumber pn)
Writes a (u16) port number to the buffer.
|
void |
writeByte(byte b)
Writes a single byte to the buffer.
|
void |
writeBytes(byte[] bytes)
Writes the specified byte array to the buffer.
|
void |
writeBytes(byte b,
int count)
Writes the given byte value the specified number of times.
|
void |
writeBytes(PacketWriter w)
Writes the bytes in the passed in writer up to it's write index to
the buffer.
|
void |
writeInt(int i)
Writes an int to the buffer as four bytes.
|
void |
writeLong(long l)
Writes a long to the buffer as eight bytes.
|
void |
writeString(String str)
Writes a string to the buffer.
|
void |
writeString(String str,
int fieldLength)
Writes a null-terminated string to the buffer, allocating a field
of the specified length.
|
void |
writeU16(int uv)
Writes two bytes (unsigned 16-bit) equivalent to the given value.
|
void |
writeU24(int uv)
Writes three bytes (unsigned 24-bit) equivalent to the given value.
|
void |
writeU32(long uv)
Writes four bytes (unsigned 32-bit) equivalent to the given value.
|
void |
writeU8(int uv)
Writes a single byte (unsigned 8-bit) equivalent to the given value.
|
void |
writeU8(short uv)
Writes a single byte (unsigned 8-bit) equivalent to the given value.
|
void |
writeZeros(int count)
Writes the specified number of NUL bytes (0x00) to the buffer.
|
public PacketWriter(ByteBuffer bb)
ByteBuffer.bb - the byte bufferpublic PacketWriter(int capacity)
ByteBuffer.capacity - the new writer's capacity, in bytespublic PacketWriter(byte[] bytes)
bytes - the new writer's backed byte arraypublic int wi()
public int writableBytes()
public byte[] array()
public void write(IpAddress ip)
ip - the IP address to writepublic void write(MacAddress mac)
mac - the MAC address to writepublic void write(EthernetType et)
et - the Ethernet Type to writepublic void write(IpProtocol ipp)
ipp - the IP Protocol to writepublic void write(ICMPv4Type it)
it - the ICMPv4 Type to writepublic void write(ICMPv6Type it)
it - the ICMPv6 Type to writepublic void write(PortNumber pn)
pn - the port number to writepublic void write(BigPortNumber pn)
pn - the port number to writepublic void writeString(String str, int fieldLength)
str - the string to writefieldLength - the length of the fieldpublic void writeString(String str)
str - the string to writepublic void writeByte(byte b)
b - the byte to writepublic void writeBytes(byte[] bytes)
bytes - the bytes to writepublic void writeBytes(PacketWriter w)
w - packet writer containing the bytes to writepublic void writeBytes(byte b,
int count)
b - the byte value to writecount - the number of times to write itpublic void writeZeros(int count)
count - the number of zeros to writepublic void writeInt(int i)
i - the int valuepublic void writeLong(long l)
l - the long valuepublic void writeU8(short uv)
uv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^8-1public void writeU8(int uv)
uv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^8-1public void writeU16(int uv)
uv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^16-1public void setU16(int idx,
int uv)
idx - the absolute index in the bufferuv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^16-1public void setU32(int idx,
long uv)
idx - the absolute index in the bufferuv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^16-1public void writeU24(int uv)
uv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^24-1public void writeU32(long uv)
uv - the unsigned value to writeIllegalArgumentException - if u is not 0..2^32-1Copyright © 2014. All Rights Reserved.