Class ByteBuffer¶
Defined in File byteBuffer.h
Class Documentation¶
-
class ByteBuffer¶
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
A
BitSet
is not safe for multithreaded use without external synchronization.Based on Java implementation.
Public Functions
-
inline ByteBuffer(std::size_t size, int byteOrder = EPICS_BYTE_ORDER)¶
Constructor.
- Parameters
size – The number of bytes.
byteOrder – The byte order. Must be one of EPICS_BYTE_ORDER,EPICS_ENDIAN_LITTLE,EPICS_ENDIAN_BIG.
-
inline ByteBuffer(char *buffer, std::size_t size, int byteOrder = EPICS_BYTE_ORDER)¶
Constructor for wrapping an existing buffer. Given buffer will not be released by the ByteBuffer instance.
- Parameters
buffer – Existing buffer. May not be NULL.
size – The number of bytes.
byteOrder – The byte order. Must be one of EPICS_BYTE_ORDER,EPICS_ENDIAN_LITTLE,EPICS_ENDIAN_BIG.
-
inline ~ByteBuffer()¶
Destructor
-
inline void setEndianess(int byteOrder)¶
Set the byte order.
- Parameters
byteOrder – The byte order. Must be one of EPICS_BYTE_ORDER,EPICS_ENDIAN_LITTLE,EPICS_ENDIAN_BIG,
-
inline const char *getBuffer() const¶
Get the raw buffer data.
- Returns
the raw buffer data.
-
inline void clear()¶
Makes a buffer ready for a new sequence of channel-read or relative put operations: It sets the limit to the capacity and the position to zero.
-
inline void flip()¶
Makes a buffer ready to read out previously written values.
Typically _limit==_buffer+_size is the initial state, but this is not required.
V _buffer V _position V _limit V _buffer+_size |_______written_______|____uninitialized___|____allocated___|
becomes
V _buffer/_position V _limit V _buffer+size |_______written_______|________________allocated____________|
-
inline void rewind()¶
Makes a buffer ready for re-reading the data that it already contains: It leaves the limit unchanged and sets the position to zero.
Note that this may allow reading of uninitialized values. flip() should be considered
V _buffer V _position V _limit V _buffer+_size |_______written_______|____uninitialized___|____allocated___|
becomes
V _buffer/_position V _limit V _buffer+size |_______written_______|____uninitialized___|____allocated___|
-
inline std::size_t getPosition() const¶
Returns the current position.
- Returns
The current position in the raw data.
-
inline void setPosition(std::size_t pos)¶
Sets the buffer position. If the mark is defined and larger than the new position then it is discarded.
- Parameters
pos – The offset into the raw buffer. The new position value; must be no larger than the current limit
-
inline std::size_t getLimit() const¶
Returns this buffer’s limit.
- Returns
The offset into the raw buffer.
-
inline void setLimit(std::size_t limit)¶
Sets this buffer’s limit. If the position is larger than the new limit then it is set to the new limit.s If the mark is defined and larger than the new limit then it is discarded.
- Parameters
limit – The new position value; must be no larger than the current limit
-
inline std::size_t getRemaining() const¶
Returns the number of elements between the current position and the limit.
- Returns
The number of elements remaining in this buffer.
-
inline std::size_t getSize() const¶
Returns The size, i.e. capacity of the raw data buffer in bytes.
- Returns
The size of the raw data buffer.
-
template<typename T>
inline void put(T value)¶ Put the value into the raw buffer as a byte stream in the current byte order.
- Parameters
value – The value to be put into the byte buffer.
-
template<typename T>
inline void put(std::size_t index, T value) const¶ Put the value into the raw buffer at the specified index as a byte stream in the current byte order.
- Parameters
index – Offset in the byte buffer.
value – The value to be put into the byte buffer.
-
template<typename T>
inline T get()¶ Get the new object from the byte buffer. The item MUST have type
T
. The position is adjusted based on the type.- Returns
The object.
-
template<typename T>
inline T get(std::size_t index) const¶ Get the new object from the byte buffer at the specified index. The item MUST have type
T
. The position is adjusted based on the type.- Parameters
index – The location in the byte buffer.
- Returns
The object.
-
inline void put(const char *src, std::size_t src_offset, std::size_t count)¶
Put a sub-array of bytes into the byte buffer. The position is increased by the count.
- Parameters
src – The source array.
src_offset – The starting position within src.
count – The number of bytes to put into the byte buffer. Must be less than getRemaining()
-
inline void get(char *dest, std::size_t dest_offset, std::size_t count)¶
Get a sub-array of bytes from the byte buffer. The position is increased by the count.
- Parameters
dest – The destination array.
dest_offset – The starting position within src.
count – The number of bytes to put into the byte buffer. Must be less than getRemaining()
-
template<typename T>
inline void putArray(const T *values, std::size_t count)¶ Put an array of type
T
into the byte buffer. The position is adjusted.- Parameters
values – The input array.
count – The number of elements.
-
template<typename T>
inline void getArray(T *values, std::size_t count)¶ Get an array of type
T
from the byte buffer. The position is adjusted.- Parameters
values – The destination array.
count – The number of elements.
-
template<typename T>
inline bool reverse() const¶ Is the byte order the EPICS_BYTE_ORDER
- Returns
(false,true) if (is, is not) the EPICS_BYTE_ORDER
-
inline void putBoolean(bool value)¶
Put a boolean value into the byte buffer.
- Parameters
value – The value.
-
inline void putByte(int8 value)¶
Put a byte value into the byte buffer.
- Parameters
value – The value.
-
inline void putShort(int16 value)¶
Put a short value into the byte buffer.
- Parameters
value – The value.
-
inline void putInt(int32 value)¶
Put an int value into the byte buffer.
- Parameters
value – The value.
-
inline void putLong(int64 value)¶
Put a long value into the byte buffer.
- Parameters
value – The value.
-
inline void putFloat(float value)¶
Put a float value into the byte buffer.
- Parameters
value – The value.
-
inline void putDouble(double value)¶
Put a double value into the byte buffer.
- Parameters
value – The value.
-
inline void putBoolean(std::size_t index, bool value)¶
Put a boolean value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putByte(std::size_t index, int8 value)¶
Put a byte value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putShort(std::size_t index, int16 value)¶
Put a short value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putInt(std::size_t index, int32 value)¶
Put an int value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putLong(std::size_t index, int64 value)¶
Put a long value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putFloat(std::size_t index, float value)¶
Put a float value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline void putDouble(std::size_t index, double value)¶
Put a double value into the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer,
value – The value.
-
inline bool getBoolean()¶
Get a boolean value from the byte buffer.
- Returns
The value.
-
inline float getFloat()¶
Get a float value from the byte buffer.
- Returns
The value.
-
inline double getDouble()¶
Get a double value from the byte buffer.
- Returns
The value.
-
inline bool getBoolean(std::size_t index)¶
Get a boolean value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline int8 getByte(std::size_t index)¶
Get a byte value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline int16 getShort(std::size_t index)¶
Get a short value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline int32 getInt(std::size_t index)¶
Get an int value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline int64 getLong(std::size_t index)¶
Get a long value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline float getFloat(std::size_t index)¶
Get a float value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
-
inline double getDouble(std::size_t index)¶
Get a boolean value from the byte buffer at the specified index.
- Parameters
index – The offset in the byte buffer.
- Returns
The value.
- inline const char * getArray () const EPICS_DEPRECATED
-
template<>
inline bool reverse() const¶
-
template<>
inline bool reverse() const
-
template<>
inline bool reverse() const
-
template<>
inline bool reverse() const
-
template<>
inline bool reverse() const
-
inline ByteBuffer(std::size_t size, int byteOrder = EPICS_BYTE_ORDER)¶