Interface MessageCodec<T extends MessageBuffer>
- Type Parameters:
T- the type ofMessageBufferused for encoding and decoding
public interface MessageCodec<T extends MessageBuffer>
A codec for encoding and decoding messages.
- Since:
- 2.9.2
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumOptions for the encoder. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newbufferinstance.createBuffer(byte[] data) Creates a newbufferinstance with the given data.static <T,C extends MessageCodec<MessageBuffer.Wrapped<T>>>
Cprovided(Class<T> type, MessageCodec.EncoderOptions... options) Gets a providedMessageCodecfor the given type.booleanreadBoolean(T buffer) Reads a boolean value from thebuffer.byteReads a byte value from thebuffer.doublereadDouble(T buffer) Reads a double value from thebuffer.floatReads a float value from thebuffer.intReads an integer value from thebuffer.longReads a long value from thebuffer.shortReads a short value from thebuffer.readString(T buffer) Reads a string from thebuffer.readString(T buffer, int maxLength) Reads a string from thebuffer.intreadUnsignedVarInt(T buffer) Reads an unsigned variable-length integer from thebuffer.longreadUnsignedVarLong(T buffer) Reads an unsigned variable-length long from thebuffer.Reads a UUID from thebuffer.intreadVarInt(T buffer) Reads a variable-length integer from thebuffer.longreadVarLong(T buffer) Reads a variable-length long from thebuffer.voidwriteBoolean(T buffer, boolean value) Writes a boolean value to thebuffer.voidWrites a byte value to thebuffer.voidwriteDouble(T buffer, double value) Writes a double value to thebuffer.voidwriteFloat(T buffer, float value) Writes a float value to thebuffer.voidWrites an integer value to thebuffer.voidWrites a long value to thebuffer.voidwriteShort(T buffer, short value) Writes a short value to thebuffer.voidwriteString(T buffer, String value) Writes a string to thebuffer.voidwriteUnsignedVarInt(T buffer, int value) Writes an unsigned variable-length integer to thebuffer.voidwriteUnsignedVarLong(T buffer, long value) Writes an unsigned variable-length long to thebuffer.voidWrites a UUID to thebuffer.voidwriteVarInt(T buffer, int value) Writes a variable-length integer to thebuffer.voidwriteVarLong(T buffer, long value) Writes a variable-length long to thebuffer.
-
Method Details
-
readBoolean
Reads a boolean value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the boolean value read
-
readByte
Reads a byte value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the byte value read
-
readShort
Reads a short value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the short value read
-
readInt
Reads an integer value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the integer value read
-
readFloat
Reads a float value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the float value read
-
readDouble
Reads a double value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the double value read
-
readLong
Reads a long value from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the long value read
-
readVarInt
Reads a variable-length integer from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the variable-length integer read
-
readUnsignedVarInt
Reads an unsigned variable-length integer from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the unsigned variable-length integer read
-
readVarLong
Reads a variable-length long from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the variable-length long read
-
readUnsignedVarLong
Reads an unsigned variable-length long from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the unsigned variable-length long read
-
readString
Reads a string from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the string read
-
readString
Reads a string from thebuffer.- Parameters:
buffer- the buffer to read frommaxLength- the maximum length of the string to read- Returns:
- the string read
-
readUuid
Reads a UUID from thebuffer.- Parameters:
buffer- the buffer to read from- Returns:
- the UUID read
-
writeBoolean
Writes a boolean value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the boolean value to write
-
writeByte
Writes a byte value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the byte value to write
-
writeShort
Writes a short value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the short value to write
-
writeInt
Writes an integer value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the integer value to write
-
writeFloat
Writes a float value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the float value to write
-
writeDouble
Writes a double value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the double value to write
-
writeLong
Writes a long value to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the long value to write
-
writeVarInt
Writes a variable-length integer to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the variable-length integer to write
-
writeUnsignedVarInt
Writes an unsigned variable-length integer to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the unsigned variable-length integer to write
-
writeVarLong
Writes a variable-length long to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the variable-length long to write
-
writeUnsignedVarLong
Writes an unsigned variable-length long to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the unsigned variable-length long to write
-
writeString
Writes a string to thebuffer.- Parameters:
buffer- the buffer to write tovalue- the string to write
-
writeUuid
Writes a UUID to thebuffer.- Parameters:
buffer- the buffer to write touuid- the UUID to write
-
createBuffer
T createBuffer()Creates a newbufferinstance.- Returns:
- a new instance of
MessageBuffer
-
createBuffer
Creates a newbufferinstance with the given data.- Parameters:
data- the byte array to initialize the buffer with- Returns:
- a new instance of
MessageBufferinitialized with the provided data
-
provided
static <T,C extends MessageCodec<MessageBuffer.Wrapped<T>>> C provided(Class<T> type, MessageCodec.EncoderOptions... options) Gets a providedMessageCodecfor the given type.- Type Parameters:
T- the type of message codec to getC- the type of message codec to get- Parameters:
type- the type of message codec to getoptions- the encoder options- Returns:
- the provided message codec
- Throws:
IllegalArgumentException- if no provider is found
-