evio
6.0
|
This class is copied from one of the same name in the Java programming language. More...
#include <ByteBuffer.h>
Public Member Functions | |
ByteBuffer () | |
Default constructor, size of 4096 bytes. More... | |
ByteBuffer (size_t size) | |
Constructor. More... | |
ByteBuffer (const ByteBuffer &srcBuf) | |
Copy constructor. More... | |
ByteBuffer (ByteBuffer &&srcBuf) noexcept | |
Move constructor. More... | |
ByteBuffer (char *byteArray, size_t len, bool isMappedMem=false) | |
This constructor is equivalent to the ByteBuffer.wrap() method in Java. More... | |
ByteBuffer (uint8_t *byteArray, size_t len, bool isMappedMem=false) | |
This constructor is equivalent to the ByteBuffer.wrap() method in Java. More... | |
~ByteBuffer () | |
Destructor. More... | |
bool | operator== (const ByteBuffer &rhs) noexcept |
Equality operator. More... | |
bool | operator!= (const ByteBuffer &rhs) noexcept |
Inequality operator. More... | |
ByteBuffer & | operator= (ByteBuffer &&other) noexcept |
Move assignment operator. More... | |
ByteBuffer & | operator= (const ByteBuffer &other) |
Assignment operator. More... | |
uint8_t & | operator[] (size_t index) |
Subscript operator for absolute access to data bytes without limit check. More... | |
uint8_t | operator[] (size_t index) const |
Subscript operator for absolute access to data bytes of const ByteBuffers without limit check. More... | |
ByteBuffer & | compact () |
This method compacts this buffer. More... | |
ByteBuffer & | zero () |
This method writes zeroes into the buffer memory (from pos = 0 to capacity). More... | |
void | copyData (const std::shared_ptr< const ByteBuffer > &srcBuf, size_t pos, size_t limit) |
Copy the source buffer's data (position to limit) into this buffer starting at local position 0. More... | |
void | copy (const ByteBuffer &srcBuf) |
Copy data and everything else from arg. More... | |
void | copy (const std::shared_ptr< const ByteBuffer > &srcBuf) |
Copy data and everything else from arg. More... | |
bool | equals (const ByteBuffer &other) |
This method tests for data equivilancy. More... | |
void | expand (size_t newSize) |
This method expands the size of this buffer if it's less than the given size. More... | |
bool | isDirect () const |
This method has no relevance to this C++ library. More... | |
bool | hasArray () const |
Tells whether or not this buffer is backed by an array. More... | |
bool | hasRemaining () const |
Returns whether there are bytes remaining between the position and limit, i.e. More... | |
bool | isReadOnly () const |
Returns whether this buffer is read only. More... | |
const ByteOrder & | order () const |
Get the byte order of the data. More... | |
uint8_t * | array () const |
Get a pointer to this buffer's backing array which contains the data. More... | |
std::shared_ptr< uint8_t > | getData () const |
Get a shared pointer to this buffer's backing array which contains the data. More... | |
size_t | arrayOffset () const |
Get the offset within this buffer's backing array of the first element of the buffer. More... | |
size_t | remaining () const |
Returns the number of bytes from the current position to the end of the data. More... | |
size_t | capacity () const |
Returns the total available bytes in this buffer. More... | |
size_t | limit () const |
Returns the limit, the position of the last valid data byte. More... | |
size_t | position () const |
Returns the position of the buffer. More... | |
ByteBuffer & | mark () |
Sets the buffer's mark at its position. More... | |
ByteBuffer & | clear () |
Clears this buffer. More... | |
ByteBuffer & | flip () |
Flips this buffer. More... | |
ByteBuffer & | reset () |
Resets this buffer's position to the previously-marked position. More... | |
ByteBuffer & | rewind () |
Rewinds this buffer. More... | |
ByteBuffer & | position (size_t p) |
Sets the position of the buffer. More... | |
ByteBuffer & | limit (size_t l) |
Sets the limit of the buffer. More... | |
ByteBuffer & | order (ByteOrder const &order) |
Sets the byte order of the data. More... | |
ByteBuffer & | duplicate (ByteBuffer &destBuf) |
Returns a byte buffer that shares this buffer's content. More... | |
std::shared_ptr< ByteBuffer > & | duplicate (std::shared_ptr< ByteBuffer > &destBuf) |
Returns a byte buffer that shares this buffer's content. More... | |
std::shared_ptr< ByteBuffer > | duplicate () |
Returns a byte buffer that shares this buffer's content. More... | |
ByteBuffer & | slice (ByteBuffer &destBuf) |
The given (and returned) byte buffer is one whose content is a shared subsequence of this buffer's content. More... | |
std::shared_ptr< ByteBuffer > & | slice (std::shared_ptr< ByteBuffer > &destBuf) |
The given (and returned) byte buffer is one whose content is a shared subsequence of this buffer's content. More... | |
std::shared_ptr< ByteBuffer > | slice () |
Creates a new byte buffer whose content is a shared subsequence of this buffer's content. More... | |
const ByteBuffer & | getBytes (uint8_t *dst, size_t length) const |
Relative bulk get method. More... | |
const ByteBuffer & | getBytes (std::vector< uint8_t > &dst, size_t offset, size_t length) const |
Relative bulk get method. More... | |
uint8_t | peek () const |
Relative get method. More... | |
uint8_t | getByte () const |
Relative get method. More... | |
uint8_t | getByte (size_t index) const |
Absolute get method. More... | |
wchar_t | getChar () const |
Relative get method for reading a 16-bit unicode character value which is by nature unsigned. More... | |
wchar_t | getChar (size_t index) const |
Absolute get method for reading a 16-bit unicode character value which is by nature unsigned. More... | |
int16_t | getShort () const |
Relative get method for reading a short value. More... | |
int16_t | getShort (size_t index) const |
Absolute get method for reading a short value. More... | |
uint16_t | getUShort () const |
Relative get method for reading an unsigned short value. More... | |
uint16_t | getUShort (size_t index) const |
Absolute get method for reading an unsigned short value. More... | |
int32_t | getInt () const |
Relative get method for reading an int value. More... | |
int32_t | getInt (size_t index) const |
Absolute get method for reading an int value. More... | |
uint32_t | getUInt () const |
Relative get method for reading an unsigned int value. More... | |
uint32_t | getUInt (size_t index) const |
Absolute get method for reading an unsigned int value. More... | |
int64_t | getLong () const |
Relative get method for reading a long long value. More... | |
int64_t | getLong (size_t index) const |
Absolute get method for reading a long long value. More... | |
uint64_t | getULong () const |
Relative get method for reading an unsigned long long value. More... | |
uint64_t | getULong (size_t index) const |
Absolute get method for reading an unsigned long long value. More... | |
float | getFloat () const |
Relative get method for reading a float value. More... | |
float | getFloat (size_t index) const |
Absolute get method for reading a float value. More... | |
double | getDouble () const |
Relative get method for reading a double value. More... | |
double | getDouble (size_t index) const |
Absolute get method for reading a double value. More... | |
ByteBuffer & | put (const ByteBuffer &src) |
Relative bulk put method. More... | |
ByteBuffer & | put (const std::shared_ptr< ByteBuffer > &src) |
Relative bulk put method. More... | |
ByteBuffer & | put (const uint8_t *src, size_t length) |
Relative bulk put method. More... | |
ByteBuffer & | put (const std::vector< uint8_t > &src, size_t offset, size_t length) |
Relative bulk put method. More... | |
ByteBuffer & | put (uint8_t val) |
Relative put method. More... | |
ByteBuffer & | put (size_t index, uint8_t val) |
Absolute put method. More... | |
ByteBuffer & | putChar (wchar_t val) |
Relative put method for writing a wide char value. More... | |
ByteBuffer & | putChar (size_t index, wchar_t val) |
Absolute put method for writing a wide char value. More... | |
ByteBuffer & | putShort (uint16_t val) |
Relative put method for writing a short value. More... | |
ByteBuffer & | putShort (size_t index, uint16_t val) |
Absolute put method for writing a short value. More... | |
ByteBuffer & | putInt (uint32_t val) |
Relative put method for writing an int value. More... | |
ByteBuffer & | putInt (size_t index, uint32_t val) |
Absolute put method for writing an int value. More... | |
ByteBuffer & | putLong (uint64_t val) |
Relative put method for writing a long long value. More... | |
ByteBuffer & | putLong (size_t index, uint64_t val) |
Absolute put method for writing a long long value. More... | |
ByteBuffer & | putFloat (float val) |
Relative put method for writing a float value. More... | |
ByteBuffer & | putFloat (size_t index, float val) |
Absolute put method for writing a float value. More... | |
ByteBuffer & | putDouble (double val) |
Relative put method for writing a double value. More... | |
ByteBuffer & | putDouble (size_t index, double val) |
Absolute put method for writing a double value. More... | |
void | printBytes (size_t offset, size_t bytes, std::string const &label) |
This method prints out the desired number of data bytes starting from the given index without regard to the limit. More... | |
std::string | toString () const |
Obtain a string representation of the buffer. More... | |
Static Public Member Functions | |
static std::shared_ptr < ByteBuffer > | copyBuffer (const std::shared_ptr< const ByteBuffer > &srcBuf) |
Copy the given buffer into a new buffer which is accessed thru shared pointer. More... | |
This class is copied from one of the same name in the Java programming language.
It wraps an array or buffer of data and is extremely useful in reading and writing data. It's particularly useful when converting Java code to C++. For more info, read the Java ByteBuffer documentation.
evio::ByteBuffer::ByteBuffer | ( | ) |
Default constructor, size of 4096 bytes.
|
explicit |
Constructor.
Reserves specified size in internal array.
size | size (in bytes) of space to preallocate internally. |
References clear(), and evio::ByteOrder::isLittleEndian().
evio::ByteBuffer::ByteBuffer | ( | const ByteBuffer & | srcBuf | ) |
Copy constructor.
Not available in Java, but useful in C++.
srcBuf | ByteBuffer to copy. |
References copy().
|
noexcept |
Move constructor.
srcBuf | ByteBuffer to move. |
evio::ByteBuffer::ByteBuffer | ( | char * | byteArray, |
size_t | len, | ||
bool | isMappedMem = false |
||
) |
This constructor is equivalent to the ByteBuffer.wrap() method in Java.
The byteArray arg needs to be created as a result to calling "new" as it's made part of a shared pointer! There is also some risk here if caller continues to use byteArray pointer independently of this object. Don't do it!
byteArray | pointer to array which this object will wrap. |
len | length of array in bytes. |
isMappedMem | is the byteArray arg a pointer obtained through mmap (file memory mapping)?. |
evio::ByteBuffer::ByteBuffer | ( | uint8_t * | byteArray, |
size_t | len, | ||
bool | isMappedMem = false |
||
) |
This constructor is equivalent to the ByteBuffer.wrap() method in Java.
The byteArray arg needs to be created as a result to calling "new" as it's made part of a shared pointer! There is also some risk here if caller continues to use byteArray pointer independently of this object. Don't do it!
byteArray | pointer to array which this object will wrap. |
len | length of array in bytes. |
isMappedMem | is the byteArray arg a pointer obtained through mmap (file memory mapping)?. |
References clear(), evio::ByteOrder::isLittleEndian(), and evio::null_deleter().
evio::ByteBuffer::~ByteBuffer | ( | ) |
Destructor.
Be sure to unmap any memory mapped file.
uint8_t * evio::ByteBuffer::array | ( | ) | const |
Get a pointer to this buffer's backing array which contains the data.
Note, there may be a non-zero offset which can be found by calling arrayOffset. Do not free or delete this array!
Referenced by evio::RecordOutput::addEvent(), evio::RecordOutput::build(), evio::EventWriter::close(), evio::Compressor::compressLZ4(), evio::Compressor::compressLZ4Best(), evio::Writer::createHeader(), evio::WriterMT::createHeader(), evio::EvioCompactReader::EvioCompactReader(), evio::EvioReader::EvioReader(), evio::RecordInput::getEvent(), evio::EvioReaderV6::getEventBuffer(), evio::EvioReaderV4::getEventBuffer(), evio::RecordInput::getUserHeader(), evio::Util::printBytes(), evio::CompositeData::process(), evio::Util::readBytes(), evio::RecordInput::readRecord(), evio::Reader::scanBuffer(), evio::Reader::scanUncompressedBuffer(), evio::CompositeData::swapAll(), evio::CompositeData::swapData(), evio::CompactEventBuilder::toFile(), evio::CompositeData::toString(), evio::Compressor::uncompressLZ4(), evio::RecordInput::uncompressRecord(), evio::BaseStructure::unpackRawBytesToStrings(), evio::Util::unpackRawBytesToStrings(), evio::BaseStructure::write(), and evio::Util::writeBytes().
size_t evio::ByteBuffer::arrayOffset | ( | ) | const |
Get the offset within this buffer's backing array of the first element of the buffer.
Referenced by evio::RecordOutput::addEvent(), evio::Writer::createHeader(), evio::WriterMT::createHeader(), evio::RecordInput::getEvent(), evio::EvioReaderV6::getEventBuffer(), evio::RecordInput::getUserHeader(), evio::Util::readBytes(), evio::RecordInput::readRecord(), evio::Reader::scanBuffer(), evio::CompositeData::swapAll(), evio::RecordInput::uncompressRecord(), evio::BaseStructure::unpackRawBytesToStrings(), evio::Util::unpackRawBytesToStrings(), evio::BaseStructure::write(), and evio::Util::writeBytes().
size_t evio::ByteBuffer::capacity | ( | ) | const |
Returns the total available bytes in this buffer.
Referenced by evio::Writer::createHeader(), evio::Reader::findRecordInfo(), evio::RecordInput::getEvent(), evio::RecordInput::getUserHeader(), evio::Util::printBytes(), evio::RecordHeader::readHeader(), evio::RecordInput::readRecord(), and evio::RecordInput::uncompressRecord().
ByteBuffer & evio::ByteBuffer::clear | ( | ) |
Clears this buffer.
The position is set to 0, the limit is set to the capacity, and the mark is discarded. Data remains untouched.
Referenced by ByteBuffer(), evio::Writer::createHeader(), evio::EvioReaderV6::getEventBuffer(), and evio::Util::stringToASCII().
ByteBuffer & evio::ByteBuffer::compact | ( | ) |
This method compacts this buffer.
The bytes between the buffer's position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded. The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.
References remaining().
void evio::ByteBuffer::copy | ( | const ByteBuffer & | srcBuf | ) |
Copy data and everything else from arg.
srcBuf | ByteBuffer to copy. |
Referenced by ByteBuffer(), and copy().
void evio::ByteBuffer::copy | ( | const std::shared_ptr< const ByteBuffer > & | srcBuf | ) |
|
static |
Copy the given buffer into a new buffer which is accessed thru shared pointer.
srcBuf | ByteBuffer to copy. |
void evio::ByteBuffer::copyData | ( | const std::shared_ptr< const ByteBuffer > & | srcBuf, |
size_t | position, | ||
size_t | limit | ||
) |
Copy the source buffer's data (position to limit) into this buffer starting at local position 0.
Limit and capacity are set to the "limit - position" bytes of srcBuf. This can reallocate memory if more is needed and can therefore resize this buffer. Existing data in this buffer will be overwritten.
srcBuf | ByteBuffer to copy data from. |
position | position in srcByf to start from. |
limit | position in srcByf to end at. |
References position().
Referenced by evio::EvioNode::getByteData(), and evio::EvioNode::getStructureBuffer().
ByteBuffer & evio::ByteBuffer::duplicate | ( | ByteBuffer & | destBuf | ) |
Returns a byte buffer that shares this buffer's content.
The content of the returned buffer will be that of this buffer. Changes to this buffer's content will be visible in the returned buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The returned buffer's capacity, limit, position, and mark values will initially be identical to those of this buffer.
The C++ version of this method departs from the Java which has no argument. To implement this method, one could return a unique pointer to a locally created ByteBuffer object which would eliminate the need for an argument. However, handling the new buffer would be different from handling those created by the constructor since the caller would have a unique pointer instead of a ByteBuffer reference.
A cleaner way to do this is for the caller to create their own, new ByteBuffer object and pass it in as an argument. This method then makes it identical to this buffer and the data (implemented as a shared pointer) is shared between the objects. The buffer passed in as an argument is also the one returned.
destBuf | byte buffer to be made a duplicate of this one. |
Referenced by evio::CompositeData::swapData().
std::shared_ptr< ByteBuffer > & evio::ByteBuffer::duplicate | ( | std::shared_ptr< ByteBuffer > & | destBuf | ) |
Returns a byte buffer that shares this buffer's content.
The content of the returned buffer will be that of this buffer. Changes to this buffer's content will be visible in the returned buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The returned buffer's capacity, limit, position, and mark values will initially be identical to those of this buffer.
The C++ version of this method departs from the Java which has no argument. To implement this method, one could return a unique pointer to a locally created ByteBuffer object which would eliminate the need for an argument. However, handling the new buffer would be different from handling those created by the constructor since the caller would have a unique pointer instead of a ByteBuffer reference.
A cleaner way to do this is for the caller to create their own, new ByteBuffer object and pass it in as an argument. This method then makes it identical to this buffer and the data (implemented as a shared pointer) is shared between the objects. The buffer passed in as an argument is also the one returned.
destBuf | byte buffer to be made a duplicate of this one. |
References duplicate().
std::shared_ptr< ByteBuffer > evio::ByteBuffer::duplicate | ( | ) |
Returns a byte buffer that shares this buffer's content.
The content of the returned buffer will be that of this buffer. Changes to this buffer's content will be visible in the returned buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The returned buffer's capacity, limit, position, and mark values will initially be identical to those of this buffer.
The C++ version of this method departs from the Java which has no argument. To implement this method, one could return a unique pointer to a locally created ByteBuffer object which would eliminate the need for an argument. However, handling the new buffer would be different from handling those created by the constructor since the caller would have a unique pointer instead of a ByteBuffer reference.
A cleaner way to do this is for the caller to create their own, new ByteBuffer object and pass it in as an argument. This method then makes it identical to this buffer and the data (implemented as a shared pointer) is shared between the objects. The buffer passed in as an argument is also the one returned.
destBuf | byte buffer to be made a duplicate of this one. |
Referenced by duplicate().
bool evio::ByteBuffer::equals | ( | const ByteBuffer & | other | ) |
This method tests for data equivilancy.
Two byte buffers are equal if, and only if, they have the same number of remaining elements, and the two sequences of remaining elements, considered independently of their starting positions, are pointwise equal.
other | A reference to a ByteBuffer to compare to this one |
References remaining().
void evio::ByteBuffer::expand | ( | size_t | size | ) |
This method expands the size of this buffer if it's less than the given size.
Note that all ByteBuffers that currently share memory with this object, either through being assigned, by calling duplicate, or by calling slice, will no longer share memory. New memory is allocated. Useful in C++, but has no counterpart in Java. Bytes up to limit are copied. New memory past limit is not zeroed. All other internals are kept the same, including all data within the limit.
size | new size (in bytes) of space to allocate internally. |
Referenced by evio::EvioReaderV6::getEventBuffer(), evio::EvioReaderV4::getEventBuffer(), and evio::Util::stringToASCII().
ByteBuffer & evio::ByteBuffer::flip | ( | ) |
Flips this buffer.
The limit is set to the current position and then the position is set to 0. The mark is discarded. Gets buffer ready for reading.
Referenced by evio::CompactEventBuilder::toFile().
uint8_t evio::ByteBuffer::getByte | ( | ) | const |
Relative get method.
Reads the byte at this buffer's current position, and then increments the position.
underflow_error | if buffer's current position is not smaller than its limit. |
Referenced by evio::CompositeData::process(), evio::CompositeData::swapAll(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), and evio::CompositeData::toString().
uint8_t evio::ByteBuffer::getByte | ( | size_t | index | ) | const |
Absolute get method.
Reads the byte at the given index.
index | index from which the byte will be read |
underflow_error | if index is not smaller than buffer's limit. |
const ByteBuffer & evio::ByteBuffer::getBytes | ( | uint8_t * | dst, |
size_t | length | ||
) | const |
Relative bulk get method.
This method transfers bytes from this buffer into the given destination array. If there are fewer bytes remaining in the buffer than are required to satisfy the request, then no bytes are transferred and an underflow_error is thrown.
Otherwise, this method copies length
bytes from this buffer into the given array, starting at the current position of this buffer and at the given pointer. The position of this buffer is then incremented by length
.
dst | array into which bytes are to be written. |
length | number of bytes to be written to the given array; must be no larger than dst size - offset. |
underflow_error | if fewer than length bytes remaining in buffer. |
References remaining().
Referenced by evio::CompositeData::process(), and evio::CompositeData::toString().
const ByteBuffer & evio::ByteBuffer::getBytes | ( | std::vector< uint8_t > & | dst, |
size_t | offset, | ||
size_t | length | ||
) | const |
Relative bulk get method.
This method transfers bytes from this buffer into the given destination vector. If there are fewer bytes remaining in the buffer than are required to satisfy the request, then no bytes are transferred and an underflow_error is thrown.
Otherwise, this method copies length
bytes from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length
.
dst | vector into which bytes are to be written. |
offset | offset (bytes) within the vector of the first byte to be written. |
length | number of bytes to be written to the given vector. |
underflow_error | if fewer than length bytes remaining in buffer. |
References remaining().
wchar_t evio::ByteBuffer::getChar | ( | ) | const |
Relative get method for reading a 16-bit unicode character value which is by nature unsigned.
Keeping the name as "getChar" makes it compatible with Java, but be aware it does NOT get a 8-bit "char" type. This method reads the next two bytes at this buffer's current position, composing them into a wchar_t value according to the current byte order, and then increments the position by two.
underflow_error | if fewer than two bytes remaining in buffer. |
wchar_t evio::ByteBuffer::getChar | ( | size_t | index | ) | const |
Absolute get method for reading a 16-bit unicode character value which is by nature unsigned.
Reads at the given index. Keeping the name as "getChar" makes it compatible with Java, but be aware it does NOT get a 8-bit "char" type. This method reads the next two bytes at the given index, composing them into a wchar_t value according to the current byte order, and then increments the position by two.
index | index from which the bytes will be read. |
underflow_error | if fewer than two bytes remaining in buffer. |
std::shared_ptr< uint8_t > evio::ByteBuffer::getData | ( | ) | const |
Get a shared pointer to this buffer's backing array which contains the data.
Note, there may be a non-zero offset which can be found by calling arrayOffset.
double evio::ByteBuffer::getDouble | ( | ) | const |
Relative get method for reading a double value.
Reads the next eight bytes at this buffer's current position, composing them into a double value according to the current byte order, and then increments the position by eight.
underflow_error | if fewer than eight bytes remaining in buffer. |
References evio::ByteOrder::byteSwap().
Referenced by evio::CompositeData::process(), and evio::CompositeData::toString().
double evio::ByteBuffer::getDouble | ( | size_t | index | ) | const |
Absolute get method for reading a double value.
Reads eight bytes at the given index, composing them into a double value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus seven. |
References evio::ByteOrder::byteSwap().
float evio::ByteBuffer::getFloat | ( | ) | const |
Relative get method for reading a float value.
Reads the next four bytes at this buffer's current position, composing them into a float value according to the current byte order, and then increments the position by four.
underflow_error | if fewer than four bytes remaining in buffer. |
References evio::ByteOrder::byteSwap().
Referenced by evio::CompositeData::process(), and evio::CompositeData::toString().
float evio::ByteBuffer::getFloat | ( | size_t | index | ) | const |
Absolute get method for reading a float value.
Reads four bytes at the given index, composing them into a float value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus three. |
References evio::ByteOrder::byteSwap().
int32_t evio::ByteBuffer::getInt | ( | ) | const |
Relative get method for reading an int value.
Reads the next four bytes at this buffer's current position, composing them into an int value according to the current byte order, and then increments the position by four.
underflow_error | if fewer than four bytes remaining in buffer. |
References SWAP_32.
Referenced by evio::EvioNode::extractNode(), evio::Util::findEvioVersion(), evio::Reader::findRecordInfo(), evio::RecordHeader::isCompressed(), evio::CompositeData::process(), evio::FileHeader::readHeader(), evio::RecordHeader::readHeader(), evio::EventHeaderParser::swapBankHeader(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), evio::EventHeaderParser::swapSegmentHeader(), evio::EventHeaderParser::swapTagSegmentHeader(), and evio::CompositeData::toString().
int32_t evio::ByteBuffer::getInt | ( | size_t | index | ) | const |
Absolute get method for reading an int value.
Reads four bytes at the given index, composing them into an int value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus three. |
References SWAP_32.
int64_t evio::ByteBuffer::getLong | ( | ) | const |
Relative get method for reading a long long value.
Reads the next eight bytes at this buffer's current position, composing them into a long long value according to the current byte order, and then increments the position by eight.
underflow_error | if fewer than eight bytes remaining in buffer. |
References SWAP_64.
Referenced by evio::CompositeData::process(), evio::FileHeader::readHeader(), evio::RecordHeader::readHeader(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), and evio::CompositeData::toString().
int64_t evio::ByteBuffer::getLong | ( | size_t | index | ) | const |
Absolute get method for reading a long long value.
Reads eight bytes at the given index, composing them into a long long value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus seven. |
References SWAP_64.
int16_t evio::ByteBuffer::getShort | ( | ) | const |
Relative get method for reading a short value.
Reads the next two bytes at this buffer's current position, composing them into a short value according to the current byte order, and then increments the position by two.
underflow_error | if fewer than two bytes remaining in buffer. |
References SWAP_16.
Referenced by evio::CompositeData::process(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), and evio::CompositeData::toString().
int16_t evio::ByteBuffer::getShort | ( | size_t | index | ) | const |
Absolute get method for reading a short value.
Reads two bytes at the given index, composing them into a short value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus one. |
References SWAP_16.
uint32_t evio::ByteBuffer::getUInt | ( | ) | const |
Relative get method for reading an unsigned int value.
Reads the next four bytes at this buffer's current position, composing them into an unsigned int value according to the current byte order, and then increments the position by four.
underflow_error | if fewer than four bytes remaining in buffer. |
References SWAP_32.
Referenced by evio::EvioNode::extractNode(), evio::Util::findEvioVersion(), evio::CompositeData::process(), and evio::CompositeData::toString().
uint32_t evio::ByteBuffer::getUInt | ( | size_t | index | ) | const |
Absolute get method for reading an unsigned int value.
Reads four bytes at the given index, composing them into an unsigned int value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus three. |
References SWAP_32.
uint64_t evio::ByteBuffer::getULong | ( | ) | const |
Relative get method for reading an unsigned long long value.
Reads the next eight bytes at this buffer's current position, composing them into an unsigned long long value according to the current byte order, and then increments the position by eight.
underflow_error | if fewer than eight bytes remaining in buffer. |
References SWAP_64.
Referenced by evio::CompositeData::process(), and evio::CompositeData::toString().
uint64_t evio::ByteBuffer::getULong | ( | size_t | index | ) | const |
Absolute get method for reading an unsigned long long value.
Reads eight bytes at the given index, composing them into an unsigned long long value according to the current byte order.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus seven. |
References SWAP_64.
uint16_t evio::ByteBuffer::getUShort | ( | ) | const |
Relative get method for reading an unsigned short value.
Reads the next two bytes at this buffer's current position, composing them into an unsigned short value according to the current byte order, and then increments the position by two.
This method is not defined in the Java version.
underflow_error | if fewer than two bytes remaining in buffer. |
References SWAP_16.
Referenced by evio::CompositeData::process(), and evio::CompositeData::toString().
uint16_t evio::ByteBuffer::getUShort | ( | size_t | index | ) | const |
Absolute get method for reading an unsigned short value.
Reads two bytes at the given index, composing them into an unsigned short value according to the current byte order.
This method is not defined in the Java version.
index | index from which the bytes will be read. |
underflow_error | if index is not smaller than buffer's limit, minus one. |
References SWAP_16.
bool evio::ByteBuffer::hasArray | ( | ) | const |
Tells whether or not this buffer is backed by an array.
This always returns true since it is backed by an array.
bool evio::ByteBuffer::hasRemaining | ( | ) | const |
Returns whether there are bytes remaining between the position and limit, i.e.
bool evio::ByteBuffer::isDirect | ( | ) | const |
This method has no relevance to this C++ library.
This always returns false since it is backed by an array.
bool evio::ByteBuffer::isReadOnly | ( | ) | const |
Returns whether this buffer is read only.
Always returns false;
size_t evio::ByteBuffer::limit | ( | ) | const |
Returns the limit, the position of the last valid data byte.
Referenced by evio::Writer::createHeader(), evio::Util::findEvioVersion(), evio::Reader::findRecordInfo(), evio::EvioNode::getByteData(), evio::RecordInput::getEvent(), evio::EvioReaderV4::getEventBuffer(), evio::EvioNode::getStructureBuffer(), evio::RecordInput::getUserHeader(), evio::RecordHeader::isCompressed(), printBytes(), evio::Util::readBytes(), evio::FileHeader::readHeader(), evio::RecordInput::readRecord(), evio::Reader::removeStructure(), evio::CompositeData::swapAll(), evio::CompositeData::swapData(), evio::Compressor::uncompressLZ4(), evio::RecordInput::uncompressRecord(), evio::FileHeader::writeHeader(), and evio::RecordHeader::writeHeader().
ByteBuffer & evio::ByteBuffer::limit | ( | size_t | l | ) |
Sets the limit of the buffer.
l | limit of the buffer. |
EvioException | if l > capacity. |
ByteBuffer & evio::ByteBuffer::mark | ( | ) |
Sets the buffer's mark at its position.
|
noexcept |
Inequality operator.
Way of checking if the 2 buffers are not pointing to the same data.
rhs | right side object. |
|
noexcept |
Move assignment operator.
other | right side object. |
ByteBuffer & evio::ByteBuffer::operator= | ( | const ByteBuffer & | other | ) |
Assignment operator.
other | right side object. |
|
noexcept |
Equality operator.
Way of checking if the 2 buffers are pointing to the same data.
rhs | right side object. |
uint8_t & evio::ByteBuffer::operator[] | ( | size_t | index | ) |
Subscript operator for absolute access to data bytes without limit check.
This has no Java counterpart.
index | index into internal data vector. |
uint8_t evio::ByteBuffer::operator[] | ( | size_t | index | ) | const |
Subscript operator for absolute access to data bytes of const ByteBuffers without limit check.
This has no Java counterpart.
index | index into internal data vector. |
const ByteOrder & evio::ByteBuffer::order | ( | ) | const |
Get the byte order of the data.
Referenced by evio::Writer::addEvent(), evio::WriterMT::addEvent(), evio::EvioCompactReaderV4::addStructure(), evio::Reader::addStructure(), evio::EventWriter::close(), evio::Writer::createHeader(), evio::EvioCompactReader::EvioCompactReader(), evio::EvioReader::EvioReader(), evio::Util::findEvioVersion(), evio::RecordInput::getEvent(), evio::RecordInput::getUserHeader(), evio::RecordHeader::isCompressed(), evio::RecordHeader::main(), order(), evio::CompositeData::process(), evio::FileHeader::readHeader(), evio::RecordHeader::readHeader(), evio::RecordInput::readRecord(), evio::RecordInput::RecordInput(), evio::Reader::scanBuffer(), evio::CompositeData::swapAll(), evio::EventHeaderParser::swapBankHeader(), evio::CompositeData::swapData(), evio::EventHeaderParser::swapSegmentHeader(), evio::EventHeaderParser::swapTagSegmentHeader(), evio::CompactEventBuilder::toFile(), evio::CompositeData::toString(), evio::BaseStructure::write(), and evio::BaseStructure::writeQuick().
ByteBuffer & evio::ByteBuffer::order | ( | ByteOrder const & | order | ) |
Sets the byte order of the data.
It does NOT do any byte swapping.
order | actual byte order of the data. |
References evio::ByteOrder::ENDIAN_LITTLE, evio::ByteOrder::ENDIAN_LOCAL, and order().
uint8_t evio::ByteBuffer::peek | ( | ) | const |
Relative get method.
Reads the byte at this buffer's current position, but does not increments the position.
underflow_error | if buffer's current position is not smaller than its limit. |
size_t evio::ByteBuffer::position | ( | ) | const |
Returns the position of the buffer.
Referenced by evio::RecordOutput::addEvent(), evio::EvioCompactReaderV4::addStructure(), evio::RecordOutput::build(), evio::Compressor::compressLZ4(), evio::Compressor::compressLZ4Best(), copyData(), evio::Writer::createHeader(), evio::WriterMT::createHeader(), evio::EventWriter::examineFileHeader(), evio::CompositeData::process(), evio::Util::readBytes(), evio::Reader::scanBuffer(), evio::CompositeData::swapData(), evio::CompositeData::toString(), evio::Compressor::uncompressLZ4(), evio::RecordInput::uncompressRecord(), evio::RecordHeader::write(), evio::BaseStructure::write(), and evio::Util::writeBytes().
ByteBuffer & evio::ByteBuffer::position | ( | size_t | p | ) |
Sets the position of the buffer.
p | position of the buffer. |
EvioException | if p > capacity. |
void evio::ByteBuffer::printBytes | ( | size_t | offset, |
size_t | bytes, | ||
std::string const & | label | ||
) |
This method prints out the desired number of data bytes starting from the given index without regard to the limit.
offset | offset into data |
bytes | number of bytes to print in hex |
label | a label to print as header |
References limit().
Referenced by evio::FileHeader::readHeader(), and evio::RecordHeader::readHeader().
ByteBuffer & evio::ByteBuffer::put | ( | const ByteBuffer & | src | ) |
Relative bulk put method.
This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining()
>
remaining()
, then no bytes are transferred and a EvioException is thrown.
Otherwise, this method copies n = src.remaining()
bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
src | source buffer from which bytes are to be read; must not be this buffer. |
EvioException | if source buffer is this buffer. |
overflow_error | if insufficient space in this buffer for the remaining bytes in the source buffer. |
References remaining().
Referenced by evio::CompositeData::dataToRawBytes(), put(), evio::Util::stringToASCII(), evio::CompositeData::swapAll(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), evio::RecordInput::uncompressRecord(), and evio::BaseStructure::writeQuick().
ByteBuffer & evio::ByteBuffer::put | ( | const std::shared_ptr< ByteBuffer > & | src | ) |
Relative bulk put method.
This method transfers the bytes remaining in the given source buffer into this buffer. If there are more bytes remaining in the source buffer than in this buffer, that is, if src.remaining()
>
remaining()
, then no bytes are transferred and a EvioException is thrown.
Otherwise, this method copies n = src.remaining()
bytes from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.
src | source buffer from which bytes are to be read; must not be this buffer. |
EvioException | if source buffer is this buffer. |
overflow_error | if insufficient space in this buffer for the remaining bytes in the source buffer. |
References put().
ByteBuffer & evio::ByteBuffer::put | ( | const uint8_t * | src, |
size_t | length | ||
) |
Relative bulk put method.
This method transfers bytes into this buffer from the given source array. If there are more bytes to be copied from the array than remain in this buffer, that is, if length
>
remaining()
, then no bytes are transferred and a EvioException is thrown.
Otherwise, this method copies length
bytes from the given array into this buffer, starting at the given pointer and at the current position of this buffer. The position of this buffer is then incremented by length
.
src | array from which bytes are to be read |
length | number of bytes to be read from the given array; must be no larger than src array's size - offset. |
overflow_error | if insufficient space in this buffer |
References remaining().
ByteBuffer & evio::ByteBuffer::put | ( | const std::vector< uint8_t > & | src, |
size_t | offset, | ||
size_t | length | ||
) |
Relative bulk put method.
This method transfers bytes into this buffer from the given vector. If there are more bytes to be copied from the vector than remain in this buffer, that is, if length
>
remaining()
, then no bytes are transferred and a EvioException is thrown.
Otherwise, this method copies length
bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length
.
src | array from which bytes are to be read |
offset | offset (bytes) within the array of the first byte to be read; must be no larger than src array's size. |
length | number of bytes to be read from the given array; must be no larger than src array's size - offset. |
overflow_error | if insufficient space in this buffer |
ByteBuffer & evio::ByteBuffer::put | ( | uint8_t | val | ) |
Relative put method.
Writes the given byte into this buffer at the current position, and then increments the position by one.
val | byte value to be written. |
overflow_error | if buffer's current position is not smaller than its limit |
ByteBuffer & evio::ByteBuffer::put | ( | size_t | index, |
uint8_t | val | ||
) |
Absolute put method.
Writes the given byte into this buffer at the given index.
index | index at which the byte will be written. |
val | byte value to be written. |
overflow_error | if buffer's current position is not smaller than its limit |
ByteBuffer & evio::ByteBuffer::putChar | ( | wchar_t | val | ) |
Relative put method for writing a wide char value.
Writes two bytes containing the given char value, in the current byte order, into this buffer at the current position, and then increments the position by two.
val | char value to be written. |
overflow_error | if there are fewer than two bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus one. |
References SWAP_16.
ByteBuffer & evio::ByteBuffer::putChar | ( | size_t | index, |
wchar_t | val | ||
) |
Absolute put method for writing a wide char value.
Writes two bytes containing the given char value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | char value to be written. |
overflow_error | if there are fewer than two bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus one. |
References SWAP_16.
ByteBuffer & evio::ByteBuffer::putDouble | ( | double | val | ) |
Relative put method for writing a double value.
Writes eight bytes containing the given double value, in the current byte order, into this buffer at the current position, and then increments the position by eight.
val | double value to be written. |
overflow_error | if there are fewer than eight bytes remaining in this buffer. |
References evio::ByteOrder::byteSwap().
Referenced by evio::CompositeData::dataToRawBytes().
ByteBuffer & evio::ByteBuffer::putDouble | ( | size_t | index, |
double | val | ||
) |
Absolute put method for writing a double value.
Writes eight bytes containing the given double value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | double value to be written. |
overflow_error | if there are fewer than eight bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus seven. |
References evio::ByteOrder::byteSwap().
ByteBuffer & evio::ByteBuffer::putFloat | ( | float | val | ) |
Relative put method for writing a float value.
Writes four bytes containing the given float value, in the current byte order, into this buffer at the current position, and then increments the position by four.
val | float value to be written. |
overflow_error | if there are fewer than four bytes remaining in this buffer. |
References evio::ByteOrder::byteSwap().
Referenced by evio::CompositeData::dataToRawBytes().
ByteBuffer & evio::ByteBuffer::putFloat | ( | size_t | index, |
float | val | ||
) |
Absolute put method for writing a float value.
Writes four bytes containing the given float value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | float value to be written. |
overflow_error | if there are fewer than four bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus three. |
References evio::ByteOrder::byteSwap().
ByteBuffer & evio::ByteBuffer::putInt | ( | uint32_t | val | ) |
Relative put method for writing an int value.
Writes four bytes containing the given int value, in the current byte order, into this buffer at the current position, and then increments the position by four.
val | int value to be written. |
overflow_error | if there are fewer than four bytes remaining in this buffer. |
References SWAP_32.
Referenced by evio::EventWriter::close(), evio::CompositeData::dataToRawBytes(), evio::EventHeaderParser::swapBankHeader(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), evio::EventHeaderParser::swapSegmentHeader(), evio::EventHeaderParser::swapTagSegmentHeader(), evio::CompactEventBuilder::toFile(), evio::RecordInput::uncompressRecord(), evio::SegmentHeader::write(), evio::TagSegmentHeader::write(), evio::BankHeader::write(), evio::BlockHeaderV2::write(), evio::BlockHeaderV4::write(), evio::FileHeader::writeHeader(), and evio::RecordHeader::writeHeader().
ByteBuffer & evio::ByteBuffer::putInt | ( | size_t | index, |
uint32_t | val | ||
) |
Absolute put method for writing an int value.
Writes four bytes containing the given int value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | int value to be written. |
overflow_error | if there are fewer than four bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus three. |
References SWAP_32.
ByteBuffer & evio::ByteBuffer::putLong | ( | uint64_t | val | ) |
Relative put method for writing a long long value.
Writes eight bytes containing the given long long value, in the current byte order, into this buffer at the current position, and then increments the position by eight.
val | long long value to be written. |
overflow_error | if there are fewer than eight bytes remaining in this buffer. |
References SWAP_64.
Referenced by evio::CompositeData::dataToRawBytes(), evio::CompositeData::swapData(), evio::EvioSwap::swapLeafData(), evio::CompactEventBuilder::toFile(), evio::FileHeader::writeHeader(), and evio::RecordHeader::writeHeader().
ByteBuffer & evio::ByteBuffer::putLong | ( | size_t | index, |
uint64_t | val | ||
) |
Absolute put method for writing a long long value.
Writes eight bytes containing the given long long value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | long long value to be written. |
overflow_error | if there are fewer than eight bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus seven. |
References SWAP_64.
ByteBuffer & evio::ByteBuffer::putShort | ( | uint16_t | val | ) |
Relative put method for writing a short value.
Writes two bytes containing the given short value, in the current byte order, into this buffer at the current position, and then increments the position by two.
val | short value to be written. |
overflow_error | if there are fewer than two bytes remaining in this buffer. |
References SWAP_16.
Referenced by evio::CompositeData::dataToRawBytes(), evio::CompositeData::swapData(), and evio::EvioSwap::swapLeafData().
ByteBuffer & evio::ByteBuffer::putShort | ( | size_t | index, |
uint16_t | val | ||
) |
Absolute put method for writing a short value.
Writes two bytes containing the given short value, in the current byte order, into this buffer at the given index.
index | index at which the bytes will be written. |
val | short value to be written. |
overflow_error | if there are fewer than two bytes remaining in this buffer, i.e. not smaller than the buffer's limit, minus one. |
References SWAP_16.
size_t evio::ByteBuffer::remaining | ( | ) | const |
Returns the number of bytes from the current position to the end of the data.
Referenced by evio::EvioCompactReaderV4::addStructure(), evio::Reader::addStructure(), evio::RecordOutput::build(), compact(), evio::Writer::createHeader(), evio::WriterMT::createHeader(), equals(), evio::EvioNode::extractNode(), getBytes(), evio::RecordInput::getUserHeaderAsRecord(), put(), evio::Util::readBytes(), slice(), evio::Compressor::uncompressLZ4(), evio::BlockHeaderV2::write(), evio::BaseStructure::write(), evio::BlockHeaderV4::write(), and evio::Util::writeBytes().
ByteBuffer & evio::ByteBuffer::reset | ( | ) |
Resets this buffer's position to the previously-marked position.
EvioException | if mark < 0. |
ByteBuffer & evio::ByteBuffer::rewind | ( | ) |
Rewinds this buffer.
The position is set to 0 and the mark is discarded.
ByteBuffer & evio::ByteBuffer::slice | ( | ByteBuffer & | destBuf | ) |
The given (and returned) byte buffer is one whose content is a shared subsequence of this buffer's content.
The content of the given buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the given buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The given buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined.
destBuf | byte buffer to be made a slice of this one. |
References remaining().
std::shared_ptr< ByteBuffer > & evio::ByteBuffer::slice | ( | std::shared_ptr< ByteBuffer > & | destBuf | ) |
The given (and returned) byte buffer is one whose content is a shared subsequence of this buffer's content.
The content of the given buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the given buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The given buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined.
destBuf | byte buffer to be made a slice of this one. |
References slice().
std::shared_ptr< ByteBuffer > evio::ByteBuffer::slice | ( | ) |
Creates a new byte buffer whose content is a shared subsequence of this buffer's content.
The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.
The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined.
References remaining().
Referenced by slice().
std::string evio::ByteBuffer::toString | ( | ) | const |
Obtain a string representation of the buffer.
ByteBuffer & evio::ByteBuffer::zero | ( | ) |
This method writes zeroes into the buffer memory (from pos = 0 to capacity).
If this ByteBuffer was obtained through calling slice, the underlying data array may not be fully zeroed as position = 0 may occur at a non-zero offset and the capacity may be less than the array's total size. Although this method does not exist in the original Java ByteBuffer class, in Java, all objects have their memory zeroed so this may be useful.