public interface MessageBuffer<T>
int, String,
other native types, byte[] of serialized objects and so on. It
contains helper methods for writing and reading back the data. If a Netty
implementation is used, then it would be a wrapper over the
ByteBuf. For Java api, it would be probably be wrapper over a
nio ByteBuffer.| Modifier and Type | Method and Description |
|---|---|
byte[] |
array()
Returns the backing byte array of this buffer.
|
void |
clear()
Clears the contents of this buffer.
|
T |
getNativeBuffer()
Returns the actual buffer implementation that is wrapped in this
MessageBuffer instance.
|
boolean |
isReadable() |
int |
readableBytes()
Gets the number of readable bytes left in the buffer.
|
int |
readByte()
Read a single signed byte from the current
readerIndex position
of the buffer. |
void |
readBytes(byte[] dst)
Transfers this buffer's data to the specified destination starting at the
current
readerIndex and increases the readerIndex by the
number of the transferred bytes (= dst.length). |
void |
readBytes(byte[] dst,
int dstIndex,
int length)
Transfers this buffer's data to the specified destination starting at the
current
readerIndex and increases the readerIndex by the
number of the transferred bytes (= length). |
byte[] |
readBytes(int length) |
char |
readChar()
Gets a 2-byte UTF-16 character at the current
readerIndex and
increases the readerIndex by 2 in this buffer. |
double |
readDouble()
Gets a 64-bit floating point number at the current
readerIndex
and increases the readerIndex by 8 in this buffer. |
float |
readFloat()
Gets a 32-bit floating point number at the current
readerIndex
and increases the readerIndex by 4 in this buffer. |
int |
readInt()
Gets a 32-bit integer at the current
readerIndex and increases
the readerIndex by 4 in this buffer. |
long |
readLong()
Gets a 64-bit integer at the current
readerIndex and increases
the readerIndex by 8 in this buffer. |
int |
readMedium()
Gets a 24-bit medium integer at the current
readerIndex and
increases the readerIndex by 3 in this buffer. |
<V> V |
readObject(Transform<T,V> converter)
Reads an object from the underlying buffer and transform the bytes using
the supplied transformer to any desired object.
|
int |
readShort()
Gets a 16-bit short integer at the current
readerIndex and
increases the readerIndex by 2 in this buffer. |
String |
readString() |
String[] |
readStrings(int numOfStrings) |
int |
readUnsignedByte()
Gets an unsigned byte at the current
readerIndex and increases
the readerIndex by 1 in this buffer. |
long |
readUnsignedInt()
Gets an unsigned 32-bit integer at the current
readerIndex and
increases the readerIndex by 4 in this buffer. |
int |
readUnsignedMedium()
Gets an unsigned 24-bit medium integer at the current
readerIndex
and increases the readerIndex by 3 in this buffer. |
int |
readUnsignedShort()
Gets an unsigned 16-bit short integer at the current
readerIndex
and increases the readerIndex by 2 in this buffer. |
MessageBuffer<T> |
writeByte(byte b) |
MessageBuffer<T> |
writeBytes(byte[] src)
Transfers the specified source array's data to this buffer starting at
the current
writerIndex and increases the writerIndex by
the number of the transferred bytes (= src.length). |
MessageBuffer<T> |
writeChar(int value)
Sets the specified 2-byte UTF-16 character at the current
writerIndex and increases the writerIndex by 2 in
this buffer. |
MessageBuffer<T> |
writeDouble(double value)
Sets the specified 64-bit floating point number at the current
writerIndex and increases the writerIndex by 8 in
this buffer. |
MessageBuffer<T> |
writeFloat(float value)
Sets the specified 32-bit floating point number at the current
writerIndex and increases the writerIndex by 4 in
this buffer. |
MessageBuffer<T> |
writeInt(int value)
Sets the specified 32-bit integer at the current
writerIndex and
increases the writerIndex by 4 in this buffer. |
MessageBuffer<T> |
writeLong(long value)
Sets the specified 64-bit long integer at the current
writerIndex
and increases the writerIndex by 8 in this buffer. |
MessageBuffer<T> |
writeMedium(int value)
Sets the specified 24-bit medium integer at the current
writerIndex and increases the writerIndex by 3 in
this buffer. |
<V> MessageBuffer<T> |
writeObject(Transform<V,T> converter,
V object)
Most implementations will write an object to the underlying buffer after
converting the incoming object using the transformer into a byte array.
|
MessageBuffer<T> |
writeShort(int value)
Sets the specified 16-bit short integer at the current
writerIndex and increases the writerIndex by 2 in
this buffer. |
MessageBuffer<T> |
writeString(String message) |
MessageBuffer<T> |
writeStrings(String... message) |
boolean isReadable()
int readableBytes()
int readByte()
readerIndex position
of the buffer. It will increment the readerIndex after doing this
operation.IndexOutOfBoundsException - if isReadable() returns false.byte[] readBytes(int length)
void readBytes(byte[] dst)
readerIndex and increases the readerIndex by the
number of the transferred bytes (= dst.length).IndexOutOfBoundsException - if dst.length is greater than
this.readableBytesvoid readBytes(byte[] dst,
int dstIndex,
int length)
readerIndex and increases the readerIndex by the
number of the transferred bytes (= length).dstIndex - the first index of the destinationlength - the number of bytes to transferIndexOutOfBoundsException - if the specified dstIndex is less than 0, if
length is greater than this.readableBytes, or
if dstIndex + length is greater than
dst.lengthint readUnsignedByte()
readerIndex and increases
the readerIndex by 1 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 1int readShort()
readerIndex and
increases the readerIndex by 2 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 2int readUnsignedShort()
readerIndex
and increases the readerIndex by 2 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 2int readMedium()
readerIndex and
increases the readerIndex by 3 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 3int readUnsignedMedium()
readerIndex
and increases the readerIndex by 3 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 3int readInt()
readerIndex and increases
the readerIndex by 4 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 4long readUnsignedInt()
readerIndex and
increases the readerIndex by 4 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 4long readLong()
readerIndex and increases
the readerIndex by 8 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 8char readChar()
readerIndex and
increases the readerIndex by 2 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 2float readFloat()
readerIndex
and increases the readerIndex by 4 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 4double readDouble()
readerIndex
and increases the readerIndex by 8 in this buffer.IndexOutOfBoundsException - if this.readableBytes is less than 8String readString()
String[] readStrings(int numOfStrings)
<V> V readObject(Transform<T,V> converter)
converter - The converter which will transform the bytes to relevant
object.MessageBuffer<T> writeByte(byte b)
MessageBuffer<T> writeBytes(byte[] src)
writerIndex and increases the writerIndex by
the number of the transferred bytes (= src.length).IndexOutOfBoundsException - if src.length is greater than
this.writableBytesMessageBuffer<T> writeShort(int value)
writerIndex and increases the writerIndex by 2 in
this buffer. The 16 high-order bits of the specified value are ignored.IndexOutOfBoundsException - if this.writableBytes is less than 2MessageBuffer<T> writeMedium(int value)
writerIndex and increases the writerIndex by 3 in
this buffer.IndexOutOfBoundsException - if this.writableBytes is less than 3MessageBuffer<T> writeInt(int value)
writerIndex and
increases the writerIndex by 4 in this buffer.IndexOutOfBoundsException - if this.writableBytes is less than 4MessageBuffer<T> writeLong(long value)
writerIndex
and increases the writerIndex by 8 in this buffer.IndexOutOfBoundsException - if this.writableBytes is less than 8MessageBuffer<T> writeChar(int value)
writerIndex and increases the writerIndex by 2 in
this buffer. The 16 high-order bits of the specified value are ignored.IndexOutOfBoundsException - if this.writableBytes is less than 2MessageBuffer<T> writeFloat(float value)
writerIndex and increases the writerIndex by 4 in
this buffer.IndexOutOfBoundsException - if this.writableBytes is less than 4MessageBuffer<T> writeDouble(double value)
writerIndex and increases the writerIndex by 8 in
this buffer.IndexOutOfBoundsException - if this.writableBytes is less than 8MessageBuffer<T> writeString(String message)
MessageBuffer<T> writeStrings(String... message)
<V> MessageBuffer<T> writeObject(Transform<V,T> converter, V object)
V - The object to be converted, mostly to a byte array or relevant
buffer implementation.converter - For most implementations, the converter which will transform
the object to byte array.T getNativeBuffer()
ByteBuf, for a core java implementation
it could be ByteBufferbyte[] array()
UnsupportedOperationException - if there no accessible backing byte arrayvoid clear()
Copyright © 2013. All Rights Reserved.