Class DirectNettyBuffer
- java.lang.Object
-
- es.bsc.dataclay.serialization.buffer.DirectNettyBuffer
-
- All Implemented Interfaces:
DataClayByteBuffer
public final class DirectNettyBuffer extends Object implements DataClayByteBuffer
Netty direct buffer used in case Java UNSAFE is not supported.
-
-
Constructor Summary
Constructors Constructor Description DirectNettyBuffer()Constructor used for codificationDirectNettyBuffer(byte[] newBuffer)Constructor used for decodificationDirectNettyBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf data)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear the buffervoiddiscardSomeReadBytes()Discard the bytes available to be read.byte[]getArray()Gets the byte array used by this bufferio.grpc.netty.shaded.io.netty.buffer.ByteBufgetBuffer()Gets the netty buffervoidincreaseBufferSize(int newBufferSize)Increase the buffer size to a new size providedbooleanisReadable()Check if the buffer has some bytes to readintmaxCapacity()Gets the maximum capacity of the bufferintreadableBytes()Get the number of bytes available to be read.booleanreadBoolean()Get a boolean from the byte bufferboolean[]readBooleans(int size)Get an array of booleans.bytereadByte()Get a byte from the byte bufferbyte[]readByteArray()Get a byte array from the byte bufferbyte[][]readByteArrays(int size)Get an array of byte arrays.voidreadBytes(byte[] values)Get an array of bytes into the variable provided.byte[]readBytes(int size)Get an array of bytes.charreadChar()Get a char from the byte bufferchar[]readChars(int size)Get an array of chars.doublereadDouble()Get a double from the byte bufferdouble[]readDoubles(int size)Get an array of doubles.intreaderIndex()Get the index in buffer of the reader pointerfloatreadFloat()Get a float from the byte bufferfloat[]readFloats(int size)Get an array of floats.intreadInt()Get an integer from the byte bufferint[]readInts(int size)Get an array of integers from the byte bufferlongreadLong()Get a long from the byte bufferlong[]readLongs(int size)Get an array of longs.shortreadShort()Get a short from the byte buffershort[]readShorts(int size)Get an array of shorts.StringreadString()Get a string from the byte bufferString[]readStrings(int size)Get an array of strings.intreadVLQInt()Get a variable length integer from the byte buffer.voidrelease()Release the buffervoidrewind()Rewind the buffer.voidsetBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)Sets the netty buffervoidsetReaderIndex(int index)Sets the reader index to the position with index providedvoidsetWriterIndex(int index)Sets the writer index to the position with index providedvoidwrapBytes(byte[] newBuffer)Wrap bytes to avoid copying them.voidwriteBoolean(boolean value)Put a boolean into the byte buffer.voidwriteBooleans(boolean[] values)Put an array of booleans into the byte buffer.voidwriteByte(byte value)Put a byte into the byte buffer.voidwriteByteArray(byte[] value)Put a byte array into the byte buffer.voidwriteByteArrays(byte[][] values)Put an array of byte arrays into the byte buffer.voidwriteBytes(byte[] values)Put an array of bytes into the byte buffer.voidwriteBytes(DataClayByteBuffer binBuffer)Copy all bytes from the buffer providedvoidwriteBytes(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)Write bytes in byte buffer.voidwriteChar(char value)Put a char into the byte buffer.voidwriteChars(char[] values)Put an array of chars into the byte buffer.voidwriteDouble(double value)Put a double into the byte buffer.voidwriteDoubles(double[] values)Put an array of doubles into the byte buffer.voidwriteFloat(float value)Put a float into the byte buffer.voidwriteFloats(float[] values)Put an array of floats into the byte buffer.voidwriteInt(int value)Put an integer into the byte buffer.voidwriteInts(int[] values)Put an array of integers into the byte buffervoidwriteLong(long value)Put a long into the byte buffer.voidwriteLongs(long[] values)Put an array of longs into the byte buffer.intwriterIndex()Get the index in buffer of the writer pointervoidwriteShort(short value)Put a short into the byte buffer.voidwriteShorts(short[] values)Put an array of shorts into the byte buffer.voidwriteString(String value)Put a string into the byte buffer.voidwriteStrings(String[] values)Put an array of strings into the byte buffer.voidwriteVLQInt(int value)Put a variable length integer into the byte buffer.
-
-
-
Constructor Detail
-
DirectNettyBuffer
public DirectNettyBuffer(byte[] newBuffer)
Constructor used for decodification- Parameters:
newBuffer- The byte array to deserialize
-
DirectNettyBuffer
public DirectNettyBuffer()
Constructor used for codification
-
DirectNettyBuffer
public DirectNettyBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf data)
Constructor- Parameters:
data- ByteBuf containing data
-
-
Method Detail
-
wrapBytes
public void wrapBytes(byte[] newBuffer)
Description copied from interface:DataClayByteBufferWrap bytes to avoid copying them.- Specified by:
wrapBytesin interfaceDataClayByteBuffer- Parameters:
newBuffer- The byte array to deserialize
-
isReadable
public boolean isReadable()
Description copied from interface:DataClayByteBufferCheck if the buffer has some bytes to read- Specified by:
isReadablein interfaceDataClayByteBuffer- Returns:
- TRUE if the buffer has some bytes to read. FALSE otherwise.
-
readableBytes
public int readableBytes()
Description copied from interface:DataClayByteBufferGet the number of bytes available to be read.- Specified by:
readableBytesin interfaceDataClayByteBuffer- Returns:
- The number of bytes available to be read.
-
readerIndex
public int readerIndex()
Description copied from interface:DataClayByteBufferGet the index in buffer of the reader pointer- Specified by:
readerIndexin interfaceDataClayByteBuffer- Returns:
- The index in buffer of the reader pointer
-
writerIndex
public int writerIndex()
Description copied from interface:DataClayByteBufferGet the index in buffer of the writer pointer- Specified by:
writerIndexin interfaceDataClayByteBuffer- Returns:
- The index in buffer of the writer pointer
-
setReaderIndex
public void setReaderIndex(int index)
Description copied from interface:DataClayByteBufferSets the reader index to the position with index provided- Specified by:
setReaderIndexin interfaceDataClayByteBuffer- Parameters:
index- the new reader position
-
setWriterIndex
public void setWriterIndex(int index)
Description copied from interface:DataClayByteBufferSets the writer index to the position with index provided- Specified by:
setWriterIndexin interfaceDataClayByteBuffer- Parameters:
index- the new writer position
-
maxCapacity
public int maxCapacity()
Description copied from interface:DataClayByteBufferGets the maximum capacity of the buffer- Specified by:
maxCapacityin interfaceDataClayByteBuffer- Returns:
- the maximum capacity of the buffer
-
clear
public void clear()
Description copied from interface:DataClayByteBufferClear the buffer- Specified by:
clearin interfaceDataClayByteBuffer
-
release
public void release()
Description copied from interface:DataClayByteBufferRelease the buffer- Specified by:
releasein interfaceDataClayByteBuffer
-
increaseBufferSize
public void increaseBufferSize(int newBufferSize)
Description copied from interface:DataClayByteBufferIncrease the buffer size to a new size provided- Specified by:
increaseBufferSizein interfaceDataClayByteBuffer- Parameters:
newBufferSize- The new buffer size
-
discardSomeReadBytes
public void discardSomeReadBytes()
Description copied from interface:DataClayByteBufferDiscard the bytes available to be read.- Specified by:
discardSomeReadBytesin interfaceDataClayByteBuffer
-
getBuffer
public io.grpc.netty.shaded.io.netty.buffer.ByteBuf getBuffer()
Description copied from interface:DataClayByteBufferGets the netty buffer- Specified by:
getBufferin interfaceDataClayByteBuffer- Returns:
- The netty buffer
-
setBuffer
public void setBuffer(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)
Description copied from interface:DataClayByteBufferSets the netty buffer- Specified by:
setBufferin interfaceDataClayByteBuffer- Parameters:
byteBuf- the netty buffer to set
-
getArray
public byte[] getArray()
Description copied from interface:DataClayByteBufferGets the byte array used by this buffer- Specified by:
getArrayin interfaceDataClayByteBuffer- Returns:
- the byte array used by this buffer
-
writeInt
public void writeInt(int value)
Description copied from interface:DataClayByteBufferPut an integer into the byte buffer.- Specified by:
writeIntin interfaceDataClayByteBuffer- Parameters:
value- Integer to add.
-
readInt
public int readInt()
Description copied from interface:DataClayByteBufferGet an integer from the byte buffer- Specified by:
readIntin interfaceDataClayByteBuffer- Returns:
- integer from the array.
-
writeVLQInt
public void writeVLQInt(int value)
Description copied from interface:DataClayByteBufferPut a variable length integer into the byte buffer.- Specified by:
writeVLQIntin interfaceDataClayByteBuffer- Parameters:
value- Integer to represent.
-
readVLQInt
public int readVLQInt()
Description copied from interface:DataClayByteBufferGet a variable length integer from the byte buffer.- Specified by:
readVLQIntin interfaceDataClayByteBuffer- Returns:
- integer represented in byte array.
-
writeInts
public void writeInts(int[] values)
Description copied from interface:DataClayByteBufferPut an array of integers into the byte buffer- Specified by:
writeIntsin interfaceDataClayByteBuffer- Parameters:
values- Array of integers to add.
-
readInts
public int[] readInts(int size)
Description copied from interface:DataClayByteBufferGet an array of integers from the byte buffer- Specified by:
readIntsin interfaceDataClayByteBuffer- Parameters:
size- Number of ints to read- Returns:
- Array of integers read
-
writeByte
public void writeByte(byte value)
Description copied from interface:DataClayByteBufferPut a byte into the byte buffer.- Specified by:
writeBytein interfaceDataClayByteBuffer- Parameters:
value- Integer to add.
-
readByte
public byte readByte()
Description copied from interface:DataClayByteBufferGet a byte from the byte buffer- Specified by:
readBytein interfaceDataClayByteBuffer- Returns:
- byte from the arrray.
-
writeBytes
public void writeBytes(byte[] values)
Description copied from interface:DataClayByteBufferPut an array of bytes into the byte buffer.- Specified by:
writeBytesin interfaceDataClayByteBuffer- Parameters:
values- Array of bytes to add.
-
writeBytes
public void writeBytes(DataClayByteBuffer binBuffer)
Description copied from interface:DataClayByteBufferCopy all bytes from the buffer provided- Specified by:
writeBytesin interfaceDataClayByteBuffer- Parameters:
binBuffer- Binary buffer from which to copy bytes
-
writeBytes
public void writeBytes(io.grpc.netty.shaded.io.netty.buffer.ByteBuf byteBuf)
Write bytes in byte buffer.- Parameters:
byteBuf- Netty byte buffer
-
readBytes
public void readBytes(byte[] values)
Description copied from interface:DataClayByteBufferGet an array of bytes into the variable provided.- Specified by:
readBytesin interfaceDataClayByteBuffer- Parameters:
values- destination byte array.
-
writeLong
public void writeLong(long value)
Description copied from interface:DataClayByteBufferPut a long into the byte buffer.- Specified by:
writeLongin interfaceDataClayByteBuffer- Parameters:
value- Long to add.
-
readLong
public long readLong()
Description copied from interface:DataClayByteBufferGet a long from the byte buffer- Specified by:
readLongin interfaceDataClayByteBuffer- Returns:
- long from the array.
-
writeLongs
public void writeLongs(long[] values)
Description copied from interface:DataClayByteBufferPut an array of longs into the byte buffer.- Specified by:
writeLongsin interfaceDataClayByteBuffer- Parameters:
values- Array of longs to add.
-
readLongs
public long[] readLongs(int size)
Description copied from interface:DataClayByteBufferGet an array of longs.- Specified by:
readLongsin interfaceDataClayByteBuffer- Parameters:
size- number of longs to read- Returns:
- An array of longs.
-
readBytes
public byte[] readBytes(int size)
Description copied from interface:DataClayByteBufferGet an array of bytes.- Specified by:
readBytesin interfaceDataClayByteBuffer- Parameters:
size- number of bytes to read- Returns:
- An array of bytes.
-
writeFloat
public void writeFloat(float value)
Description copied from interface:DataClayByteBufferPut a float into the byte buffer.- Specified by:
writeFloatin interfaceDataClayByteBuffer- Parameters:
value- float to add.
-
readFloat
public float readFloat()
Description copied from interface:DataClayByteBufferGet a float from the byte buffer- Specified by:
readFloatin interfaceDataClayByteBuffer- Returns:
- float from the array.
-
writeFloats
public void writeFloats(float[] values)
Description copied from interface:DataClayByteBufferPut an array of floats into the byte buffer.- Specified by:
writeFloatsin interfaceDataClayByteBuffer- Parameters:
values- Array of floats to add.
-
readFloats
public float[] readFloats(int size)
Description copied from interface:DataClayByteBufferGet an array of floats.- Specified by:
readFloatsin interfaceDataClayByteBuffer- Parameters:
size- number of floats to read- Returns:
- An array of floats.
-
writeDouble
public void writeDouble(double value)
Description copied from interface:DataClayByteBufferPut a double into the byte buffer.- Specified by:
writeDoublein interfaceDataClayByteBuffer- Parameters:
value- double to add.
-
readDouble
public double readDouble()
Description copied from interface:DataClayByteBufferGet a double from the byte buffer- Specified by:
readDoublein interfaceDataClayByteBuffer- Returns:
- double from the array.
-
writeDoubles
public void writeDoubles(double[] values)
Description copied from interface:DataClayByteBufferPut an array of doubles into the byte buffer.- Specified by:
writeDoublesin interfaceDataClayByteBuffer- Parameters:
values- Array of doubles to add.
-
readDoubles
public double[] readDoubles(int size)
Description copied from interface:DataClayByteBufferGet an array of doubles.- Specified by:
readDoublesin interfaceDataClayByteBuffer- Parameters:
size- number of doubles to read- Returns:
- An array of doubles.
-
writeBoolean
public void writeBoolean(boolean value)
Description copied from interface:DataClayByteBufferPut a boolean into the byte buffer.- Specified by:
writeBooleanin interfaceDataClayByteBuffer- Parameters:
value- boolean to add.
-
readBoolean
public boolean readBoolean()
Description copied from interface:DataClayByteBufferGet a boolean from the byte buffer- Specified by:
readBooleanin interfaceDataClayByteBuffer- Returns:
- boolean from the array.
-
writeBooleans
public void writeBooleans(boolean[] values)
Description copied from interface:DataClayByteBufferPut an array of booleans into the byte buffer.- Specified by:
writeBooleansin interfaceDataClayByteBuffer- Parameters:
values- Array of booleans to add.
-
readBooleans
public boolean[] readBooleans(int size)
Description copied from interface:DataClayByteBufferGet an array of booleans.- Specified by:
readBooleansin interfaceDataClayByteBuffer- Parameters:
size- number of booleans to read- Returns:
- An array of booleans.
-
writeChar
public void writeChar(char value)
Description copied from interface:DataClayByteBufferPut a char into the byte buffer.- Specified by:
writeCharin interfaceDataClayByteBuffer- Parameters:
value- char to add.
-
readChar
public char readChar()
Description copied from interface:DataClayByteBufferGet a char from the byte buffer- Specified by:
readCharin interfaceDataClayByteBuffer- Returns:
- char from the array.
-
writeChars
public void writeChars(char[] values)
Description copied from interface:DataClayByteBufferPut an array of chars into the byte buffer.- Specified by:
writeCharsin interfaceDataClayByteBuffer- Parameters:
values- Array of chars to add.
-
readChars
public char[] readChars(int size)
Description copied from interface:DataClayByteBufferGet an array of chars.- Specified by:
readCharsin interfaceDataClayByteBuffer- Parameters:
size- number of chars to read- Returns:
- An array of chars.
-
writeShort
public void writeShort(short value)
Description copied from interface:DataClayByteBufferPut a short into the byte buffer.- Specified by:
writeShortin interfaceDataClayByteBuffer- Parameters:
value- short to add.
-
readShort
public short readShort()
Description copied from interface:DataClayByteBufferGet a short from the byte buffer- Specified by:
readShortin interfaceDataClayByteBuffer- Returns:
- short from the array.
-
writeShorts
public void writeShorts(short[] values)
Description copied from interface:DataClayByteBufferPut an array of shorts into the byte buffer.- Specified by:
writeShortsin interfaceDataClayByteBuffer- Parameters:
values- Array of shorts to add.
-
readShorts
public short[] readShorts(int size)
Description copied from interface:DataClayByteBufferGet an array of shorts.- Specified by:
readShortsin interfaceDataClayByteBuffer- Parameters:
size- number of shorts to read- Returns:
- An array of shorts.
-
writeString
public void writeString(String value)
Description copied from interface:DataClayByteBufferPut a string into the byte buffer.- Specified by:
writeStringin interfaceDataClayByteBuffer- Parameters:
value- string to add.
-
readString
public String readString()
Description copied from interface:DataClayByteBufferGet a string from the byte buffer- Specified by:
readStringin interfaceDataClayByteBuffer- Returns:
- string from the array.
-
writeStrings
public void writeStrings(String[] values)
Description copied from interface:DataClayByteBufferPut an array of strings into the byte buffer.- Specified by:
writeStringsin interfaceDataClayByteBuffer- Parameters:
values- Array of strings to add.
-
readStrings
public String[] readStrings(int size)
Description copied from interface:DataClayByteBufferGet an array of strings.- Specified by:
readStringsin interfaceDataClayByteBuffer- Parameters:
size- number of strings to read- Returns:
- An array of strings.
-
writeByteArray
public void writeByteArray(byte[] value)
Description copied from interface:DataClayByteBufferPut a byte array into the byte buffer.- Specified by:
writeByteArrayin interfaceDataClayByteBuffer- Parameters:
value- byte array to add.
-
readByteArray
public byte[] readByteArray()
Description copied from interface:DataClayByteBufferGet a byte array from the byte buffer- Specified by:
readByteArrayin interfaceDataClayByteBuffer- Returns:
- byte array from the array.
-
writeByteArrays
public void writeByteArrays(byte[][] values)
Description copied from interface:DataClayByteBufferPut an array of byte arrays into the byte buffer.- Specified by:
writeByteArraysin interfaceDataClayByteBuffer- Parameters:
values- Array of byte arrays to add.
-
readByteArrays
public byte[][] readByteArrays(int size)
Description copied from interface:DataClayByteBufferGet an array of byte arrays.- Specified by:
readByteArraysin interfaceDataClayByteBuffer- Parameters:
size- number of byte arrays to read- Returns:
- An array of byte arrays.
-
rewind
public void rewind()
Description copied from interface:DataClayByteBufferRewind the buffer.- Specified by:
rewindin interfaceDataClayByteBuffer
-
-