C12Adapter Opensource C++ Interface
|
Buffer traverser or reader. More...
Public Member Functions | |
MBufferReader () | |
Create an empty reader. More... | |
MBufferReader (MBuffer *buffer) | |
Create a reader for a given buffer. More... | |
MBufferReader (MBuffer *buffer, unsigned readPosition, unsigned readEnd) | |
Create a reader for a given buffer at a given position and size. More... | |
MBufferReader (const MBufferReader &other) | |
Create a reader from a given copy. More... | |
~MBufferReader () | |
Destructor. | |
void | AssignBuffer (MBuffer *buffer) |
Assign the buffer that is to be read. More... | |
void | AssignBuffer (MBuffer *buffer, unsigned readPosition, unsigned readEnd) |
Assign a reader for a given buffer at a given position and end. More... | |
const char * | GetTotalPtr () const |
Access constant pointer of the whole buffer, regardless of the reader position. | |
unsigned | GetTotalSize () const |
Access the size of the whole buffer, regardless of the reader position. | |
char * | GetReadPtr () |
Access the pointer to data to which the current position of the reader points. | |
const char * | GetReadPtr () const |
Access the constant pointer to data to which the current position of the reader points. | |
unsigned | GetRemainingReadSize () const |
The number of bytes left to read to reach the end of the reader. | |
void | IgnoreBytes (unsigned pos) |
Traverse the reader current position by ignoring the given number of bytes. More... | |
void | ReadBuffer (Muint8 *data, unsigned size) |
Read characters from the buffer into the given pointer and size. More... | |
template<typename T > | |
void | Read (T &result) |
Read a typed value from the buffer, return the value. More... | |
template<typename T > | |
T | Read () |
Read a typed value from the buffer, return the value. More... | |
void | ReadBuffer (char *data, unsigned size) |
Read bytes from the buffer into the given pointer and size. More... | |
Muint8 | ReadByte () |
Read a byte from the buffer. More... | |
void | ReadBytes (unsigned size, MByteString &result) |
Read bytes from the buffer into the given result. More... | |
void | ReadRemainingBytes (MByteString &result) |
Read all remaining bytes from the buffer into the given result. More... | |
unsigned | ReadIsoLength () |
Read an ISO 8825 length BER representation from this buffer. More... | |
unsigned | GetReadPosition () const |
void | SetReadPosition (unsigned pos) |
unsigned | GetEndPosition () const |
void | SetEndPosition (unsigned pos) |
Protected Attributes | |
MBuffer * | m_buff |
Client buffer object, not owned by this class. | |
unsigned | m_readPosition |
Current read position within the buffer. | |
unsigned | m_readEnd |
End position within the buffer, possibly smaller than the buffer size. | |
Buffer traverser or reader.
Uses buffer object to walk through it sequentially. The buffer reader has
One buffer can be used by multiple readers, each having its own possibly overlapping read position at the end.
|
inline |
Create an empty reader.
Before use, the buffer has to be assigned to this object with AssignBuffer.
|
inline |
Create a reader for a given buffer.
The read position is zero, the start of the given buffer. The end position is the end of the buffer, buffer size.
buffer | Buffer object that will be read from the start. |
|
inline |
Create a reader for a given buffer at a given position and size.
buffer | Buffer object that will be read from the given position. |
readPosition | Start position, should be within the span of the buffer, as checked with the debug level assert. |
readEnd | End position, should be within the span of the buffer, as checked with the debug level assert. |
|
inline |
Create a reader from a given copy.
The buffer object, as well as the read position and end, are copied and the new object can read the buffer independently.
other | Buffer reader from which this buffer is copied. |
|
inline |
Assign the buffer that is to be read.
The read position is zero, the start of the given buffer. The end position is the end of the buffer, buffer size. It is okay if this reader was pointing to some other buffer prior to this call.
buffer | Buffer object that will be read from the start. |
|
inline |
Assign a reader for a given buffer at a given position and end.
It is okay if this reader was pointing to some other buffer prior to this call.
buffer | Buffer object that will be read from the given position. |
readPosition | Start position, should be within the span of the buffer, as checked with the debug level assert. |
readEnd | End position, should be within the span of the buffer, as checked with the debug level assert. |
|
inline |
Current end position of the buffer reader.
|
inline |
Current read position of the buffer reader.
|
inline |
Traverse the reader current position by ignoring the given number of bytes.
Only debug level checks are present.
|
inline |
Read a typed value from the buffer, return the value.
If the type of such size does not fit in the remainder of the buffer, an exception is thrown.
|
inline |
Read a typed value from the buffer, return the value.
If the type of such size does not fit in the remainder of the buffer, an exception is thrown.
void MBufferReader::ReadBuffer | ( | Muint8 * | data, |
unsigned | size | ||
) |
Read characters from the buffer into the given pointer and size.
data | Pointer into which to read bytes. |
size | How many bytes to read, should not be less than what is available in the data pointer. If the requested size is smaller than what is available to reader, an exception is thrown. |
|
inline |
Read bytes from the buffer into the given pointer and size.
data | Pointer into which to read bytes |
size | How many bytes to read, should not be less than what is available in the data pointer. If the requested size is smaller than what is available to reader, an exception is thrown. |
Muint8 MBufferReader::ReadByte | ( | ) |
Read a byte from the buffer.
If the read position is at the end already, an exception is thrown.
void MBufferReader::ReadBytes | ( | unsigned | size, |
MByteString & | result | ||
) |
Read bytes from the buffer into the given result.
The reason this method takes an 'out' variable is that it is typically kept with some preallocated memory for efficiency of multiple calls.
size | How many bytes to read, should not be less than what is available in the data pointer. If the requested size is smaller than what is available to reader, an exception is thrown. |
result | Write-only parameter into which the data will be read. |
unsigned MBufferReader::ReadIsoLength | ( | ) |
Read an ISO 8825 length BER representation from this buffer.
Exception will be thrown if there is not enough bytes in the buffer reader, or if the bytes do not comprise a proper ISO length.
void MBufferReader::ReadRemainingBytes | ( | MByteString & | result | ) |
Read all remaining bytes from the buffer into the given result.
The reason this method takes an 'out' variable is that it is typically kept with some preallocated memory for efficiency of multiple calls. After this method is called, the read position will be equal to the end position.
result | Write-only parameter into which the data will be read. |
void MBufferReader::SetEndPosition | ( | unsigned | pos | ) |
Current end position of the buffer reader.
|
inline |
Current read position of the buffer reader.