com.hazelcast.client.impl.protocol.util
public class UnsafeBuffer extends Object implements ClientProtocolBuffer
Constructor and Description |
---|
UnsafeBuffer(byte[] buffer)
Attach a view to a byte[] for providing direct access.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
byteArray()
Get the underlying byte[] if one exists.
|
int |
capacity()
Get the capacity of the underlying buffer.
|
byte |
getByte(int index)
Get the value at a given index.
|
void |
getBytes(int index,
byte[] dst)
Get from the underlying buffer into a supplied byte array.
|
void |
getBytes(int index,
byte[] dst,
int offset,
int length)
Get bytes from the underlying buffer into a supplied byte array.
|
int |
getInt(int index)
Get the value at a given index.
|
long |
getLong(int index)
Get the value at a given index.
|
short |
getShort(int index)
Get the value at a given index.
|
String |
getStringUtf8(int offset,
int length)
Get part of String from bytes encoded in UTF-8 format without a length prefix.
|
void |
putByte(int index,
byte value)
Put a value to a given index.
|
void |
putBytes(int index,
byte[] src)
Put an array of src into the underlying buffer.
|
void |
putBytes(int index,
byte[] src,
int offset,
int length)
Put an array into the underlying buffer.
|
void |
putInt(int index,
int value)
Put a value at a given index.
|
void |
putLong(int index,
long value)
Put a value at a given index.
|
void |
putShort(int index,
short value)
Put a value to a given index.
|
int |
putStringUtf8(int index,
String value)
Encode a String as UTF-8 bytes to the buffer with a length prefix.
|
int |
putStringUtf8(int index,
String value,
int maxEncodedSize)
Encode a String as UTF-8 bytes the buffer with a length prefix with a maximum encoded size check.
|
void |
wrap(byte[] buffer)
Attach a view to a byte[] for providing direct access.
|
public static final Charset UTF_8
public UnsafeBuffer(byte[] buffer)
buffer
- The buffer to which the view is attached.public void wrap(byte[] buffer)
ClientProtocolBuffer
wrap
in interface ClientProtocolBuffer
buffer
- to which the view is attached.public byte[] byteArray()
ClientProtocolBuffer
byteArray
in interface ClientProtocolBuffer
public int capacity()
ClientProtocolBuffer
capacity
in interface ClientProtocolBuffer
public long getLong(int index)
ClientProtocolBuffer
getLong
in interface ClientProtocolBuffer
index
- in bytes from which to get.public void putLong(int index, long value)
ClientProtocolBuffer
putLong
in interface ClientProtocolBuffer
index
- The index in bytes where the value is put.value
- The value to put at the given index.public int getInt(int index)
ClientProtocolBuffer
getInt
in interface ClientProtocolBuffer
index
- in bytes from which to get.public void putInt(int index, int value)
ClientProtocolBuffer
putInt
in interface ClientProtocolBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public short getShort(int index)
ClientProtocolBuffer
getShort
in interface ClientProtocolBuffer
index
- in bytes from which to get.public void putShort(int index, short value)
ClientProtocolBuffer
putShort
in interface ClientProtocolBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public byte getByte(int index)
ClientProtocolBuffer
getByte
in interface ClientProtocolBuffer
index
- in bytes from which to get.public void putByte(int index, byte value)
ClientProtocolBuffer
putByte
in interface ClientProtocolBuffer
index
- The index in bytes where the value is put.value
- The value put at the given index.public void getBytes(int index, byte[] dst)
ClientProtocolBuffer
getBytes
in interface ClientProtocolBuffer
index
- in the underlying buffer to start from.dst
- into which the dst will be copied.public void getBytes(int index, byte[] dst, int offset, int length)
ClientProtocolBuffer
getBytes
in interface ClientProtocolBuffer
index
- in the underlying buffer to start from.dst
- into which the bytes will be copied.offset
- in the supplied buffer to start the copylength
- of the supplied buffer to use.public void putBytes(int index, byte[] src)
ClientProtocolBuffer
putBytes
in interface ClientProtocolBuffer
index
- The index in the underlying buffer from which to start the array.src
- The array to be copied into the underlying buffer.public void putBytes(int index, byte[] src, int offset, int length)
ClientProtocolBuffer
putBytes
in interface ClientProtocolBuffer
index
- The index in the underlying buffer from which to start the array.src
- The array to be copied into the underlying buffer.offset
- The offset in the supplied buffer at which to begin the copy.length
- The length of the supplied buffer to copy.public String getStringUtf8(int offset, int length)
ClientProtocolBuffer
getStringUtf8
in interface ClientProtocolBuffer
offset
- at which the String begins.length
- of the String in bytes to decode.public int putStringUtf8(int index, String value)
ClientProtocolBuffer
putStringUtf8
in interface ClientProtocolBuffer
index
- The index at which the String should be encoded.value
- The value of the String to be encoded.public int putStringUtf8(int index, String value, int maxEncodedSize)
ClientProtocolBuffer
putStringUtf8
in interface ClientProtocolBuffer
index
- The index at which the String should be encoded.value
- The value of the String to be encoded.maxEncodedSize
- The maximum encoded size to be checked before writing to the buffer.Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.