evio  6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
evio::ByteBuffer Class Reference

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...
 
ByteBufferoperator= (ByteBuffer &&other) noexcept
 Move assignment operator. More...
 
ByteBufferoperator= (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...
 
ByteBuffercompact ()
 This method compacts this buffer. More...
 
ByteBufferzero ()
 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 ByteOrderorder () 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...
 
ByteBuffermark ()
 Sets the buffer's mark at its position. More...
 
ByteBufferclear ()
 Clears this buffer. More...
 
ByteBufferflip ()
 Flips this buffer. More...
 
ByteBufferreset ()
 Resets this buffer's position to the previously-marked position. More...
 
ByteBufferrewind ()
 Rewinds this buffer. More...
 
ByteBufferposition (size_t p)
 Sets the position of the buffer. More...
 
ByteBufferlimit (size_t l)
 Sets the limit of the buffer. More...
 
ByteBufferorder (ByteOrder const &order)
 Sets the byte order of the data. More...
 
ByteBufferduplicate (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< ByteBufferduplicate ()
 Returns a byte buffer that shares this buffer's content. More...
 
ByteBufferslice (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< ByteBufferslice ()
 Creates a new byte buffer whose content is a shared subsequence of this buffer's content. More...
 
const ByteBuffergetBytes (uint8_t *dst, size_t length) const
 Relative bulk get method. More...
 
const ByteBuffergetBytes (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...
 
ByteBufferput (const ByteBuffer &src)
 Relative bulk put method. More...
 
ByteBufferput (const std::shared_ptr< ByteBuffer > &src)
 Relative bulk put method. More...
 
ByteBufferput (const uint8_t *src, size_t length)
 Relative bulk put method. More...
 
ByteBufferput (const std::vector< uint8_t > &src, size_t offset, size_t length)
 Relative bulk put method. More...
 
ByteBufferput (uint8_t val)
 Relative put method. More...
 
ByteBufferput (size_t index, uint8_t val)
 Absolute put method. More...
 
ByteBufferputChar (wchar_t val)
 Relative put method for writing a wide char value. More...
 
ByteBufferputChar (size_t index, wchar_t val)
 Absolute put method for writing a wide char value. More...
 
ByteBufferputShort (uint16_t val)
 Relative put method for writing a short value. More...
 
ByteBufferputShort (size_t index, uint16_t val)
 Absolute put method for writing a short value. More...
 
ByteBufferputInt (uint32_t val)
 Relative put method for writing an int value. More...
 
ByteBufferputInt (size_t index, uint32_t val)
 Absolute put method for writing an int value. More...
 
ByteBufferputLong (uint64_t val)
 Relative put method for writing a long long value. More...
 
ByteBufferputLong (size_t index, uint64_t val)
 Absolute put method for writing a long long value. More...
 
ByteBufferputFloat (float val)
 Relative put method for writing a float value. More...
 
ByteBufferputFloat (size_t index, float val)
 Absolute put method for writing a float value. More...
 
ByteBufferputDouble (double val)
 Relative put method for writing a double value. More...
 
ByteBufferputDouble (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...
 

Detailed Description

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.

Date
04/18/2018
Author
timmer

Constructor & Destructor Documentation

evio::ByteBuffer::ByteBuffer ( )

Default constructor, size of 4096 bytes.

evio::ByteBuffer::ByteBuffer ( size_t  size)
explicit

Constructor.

Reserves specified size in internal array.

Parameters
sizesize (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++.

Parameters
srcBufByteBuffer to copy.

References copy().

evio::ByteBuffer::ByteBuffer ( ByteBuffer &&  srcBuf)
noexcept

Move constructor.

Parameters
srcBufByteBuffer 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!

Parameters
byteArraypointer to array which this object will wrap.
lenlength of array in bytes.
isMappedMemis 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!

Parameters
byteArraypointer to array which this object will wrap.
lenlength of array in bytes.
isMappedMemis 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.

Member Function Documentation

size_t evio::ByteBuffer::capacity ( ) const
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.

Returns
this buffer.

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.

Returns
reference to this ByteBuffer.

References remaining().

void evio::ByteBuffer::copy ( const ByteBuffer srcBuf)

Copy data and everything else from arg.

Parameters
srcBufByteBuffer to copy.

Referenced by ByteBuffer(), and copy().

void evio::ByteBuffer::copy ( const std::shared_ptr< const ByteBuffer > &  srcBuf)

Copy data and everything else from arg.

Parameters
srcBufByteBuffer to copy.

References copy().

std::shared_ptr< ByteBuffer > evio::ByteBuffer::copyBuffer ( const std::shared_ptr< const ByteBuffer > &  srcBuf)
static

Copy the given buffer into a new buffer which is accessed thru shared pointer.

Parameters
srcBufByteBuffer to copy.
Returns
new ByteBuffer.
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.

Parameters
srcBufByteBuffer to copy data from.
positionposition in srcByf to start from.
limitposition 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.

Parameters
destBufbyte buffer to be made a duplicate of this one.
Returns
the same byte buffer as passed in as the argument.

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.

Parameters
destBufbyte buffer to be made a duplicate of this one.
Returns
the same byte buffer as passed in as the argument.

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.

Parameters
destBufbyte buffer to be made a duplicate of this one.
Returns
the same byte buffer as passed in as the argument.

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.

Parameters
otherA reference to a ByteBuffer to compare to this one
Returns
True if the internal buffers match, otherwise False.

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.

Parameters
sizenew 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.

Returns
this buffer.

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.

Returns
byte at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the byte will be read
Returns
byte at the given index
Exceptions
underflow_errorif 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.

Parameters
dstarray into which bytes are to be written.
lengthnumber of bytes to be written to the given array; must be no larger than dst size - offset.
Returns
this buffer.
Exceptions
underflow_errorif 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.

Parameters
dstvector into which bytes are to be written.
offsetoffset (bytes) within the vector of the first byte to be written.
lengthnumber of bytes to be written to the given vector.
Returns
this buffer.
Exceptions
underflow_errorif 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.

Returns
wchar_t value at buffer's current position
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
wchar_t value at the given index.
Exceptions
underflow_errorif 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.

Returns
shared pointer to the data array.
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.

Returns
double value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
double value at the given index.
Exceptions
underflow_errorif 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.

Returns
float value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
float value at the given index.
Exceptions
underflow_errorif 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.

Returns
int value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
int value at the given index.
Exceptions
underflow_errorif 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.

Returns
long long value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
long long value at the given index.
Exceptions
underflow_errorif 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.

Returns
short value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
short value at the given index.
Exceptions
underflow_errorif 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.

Returns
unsigned int value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
unsigned int value at the given index.
Exceptions
underflow_errorif 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.

Returns
unsigned long long value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
unsigned long long value at the given index.
Exceptions
underflow_errorif 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.

Returns
unsigned short value at buffer's current position.
Exceptions
underflow_errorif 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.

Parameters
indexindex from which the bytes will be read.
Returns
unsigned short value at the given index.
Exceptions
underflow_errorif 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.

Returns
true.
bool evio::ByteBuffer::hasRemaining ( ) const

Returns whether there are bytes remaining between the position and limit, i.e.

position() < limit().

Returns
position < limit.
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.

Returns
false.
bool evio::ByteBuffer::isReadOnly ( ) const

Returns whether this buffer is read only.

Always returns false;

Returns
false.
ByteBuffer & evio::ByteBuffer::limit ( size_t  l)

Sets the limit of the buffer.

Parameters
llimit of the buffer.
Returns
this buffer.
Exceptions
EvioExceptionif l > capacity.
ByteBuffer & evio::ByteBuffer::mark ( )

Sets the buffer's mark at its position.

Returns
this buffer.
bool evio::ByteBuffer::operator!= ( const ByteBuffer rhs)
noexcept

Inequality operator.

Way of checking if the 2 buffers are not pointing to the same data.

Parameters
rhsright side object.
Returns
false if equal.
ByteBuffer & evio::ByteBuffer::operator= ( ByteBuffer &&  other)
noexcept

Move assignment operator.

Parameters
otherright side object.
Returns
left side object.
ByteBuffer & evio::ByteBuffer::operator= ( const ByteBuffer other)

Assignment operator.

Parameters
otherright side object.
Returns
left side object.
bool evio::ByteBuffer::operator== ( const ByteBuffer rhs)
noexcept

Equality operator.

Way of checking if the 2 buffers are pointing to the same data.

Parameters
rhsright side object.
Returns
true if equal.
uint8_t & evio::ByteBuffer::operator[] ( size_t  index)

Subscript operator for absolute access to data bytes without limit check.

This has no Java counterpart.

Parameters
indexindex into internal data vector.
Returns
reference to internal byte in data vector at the given index.
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.

Parameters
indexindex into internal data vector.
Returns
reference to internal byte in data vector at the given index.
ByteBuffer & evio::ByteBuffer::order ( ByteOrder const &  order)

Sets the byte order of the data.

It does NOT do any byte swapping.

Parameters
orderactual byte order of the data.
Returns
this buffer.

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.

Returns
byte at buffer's current position.
Exceptions
underflow_errorif buffer's current position is not smaller than its limit.
ByteBuffer & evio::ByteBuffer::position ( size_t  p)

Sets the position of the buffer.

Parameters
pposition of the buffer.
Returns
this buffer.
Exceptions
EvioExceptionif 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.

Parameters
offsetoffset into data
bytesnumber of bytes to print in hex
labela 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.

Parameters
srcsource buffer from which bytes are to be read; must not be this buffer.
Returns
this buffer.
Exceptions
EvioExceptionif source buffer is this buffer.
overflow_errorif 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.

Parameters
srcsource buffer from which bytes are to be read; must not be this buffer.
Returns
this buffer.
Exceptions
EvioExceptionif source buffer is this buffer.
overflow_errorif 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.

Parameters
srcarray from which bytes are to be read
lengthnumber of bytes to be read from the given array; must be no larger than src array's size - offset.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
srcarray from which bytes are to be read
offsetoffset (bytes) within the array of the first byte to be read; must be no larger than src array's size.
lengthnumber of bytes to be read from the given array; must be no larger than src array's size - offset.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valbyte value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the byte will be written.
valbyte value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valchar value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
valchar value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valdouble value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
valdouble value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valfloat value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
valfloat value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valint value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
valint value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
vallong long value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
vallong long value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
valshort value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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.

Parameters
indexindex at which the bytes will be written.
valshort value to be written.
Returns
this buffer.
Exceptions
overflow_errorif 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::reset ( )

Resets this buffer's position to the previously-marked position.

Returns
this buffer.
Exceptions
EvioExceptionif mark < 0.
ByteBuffer & evio::ByteBuffer::rewind ( )

Rewinds this buffer.

The position is set to 0 and the mark is discarded.

Returns
this buffer.
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.

Parameters
destBufbyte buffer to be made a slice of this one.
Returns
the same byte buffer as passed in as the argument.

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.

Parameters
destBufbyte buffer to be made a slice of this one.
Returns
the same byte buffer as passed in as the argument.

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.

Returns
The new byte buffer.

References remaining().

Referenced by slice().

std::string evio::ByteBuffer::toString ( ) const

Obtain a string representation of the buffer.

Returns
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.

Returns
reference to this ByteBuffer.

The documentation for this class was generated from the following files: