#include <Buffer.h>
Tipos Públicos | |
BIG_ENDIAN_ORDER | |
Constant denoting big-endian byte order. In this order, the bytes of a multibyte value are ordered from most significant to least significant. | |
LITTLE_ENDIAN_ORDER | |
Constant denoting little-endian byte order. In this order, the bytes of a multibyte value are ordered from least significant to most significant. | |
enum | ByteOrder { BIG_ENDIAN_ORDER, LITTLE_ENDIAN_ORDER } |
A typesafe enumeration for byte orders. Mais... | |
Métodos Públicos | |
Buffer (size_t capacity) | |
The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero. | |
Buffer (char *buffer, size_t size) | |
Wraps a byte array into a buffer. | |
~Buffer () | |
Destrutor. | |
void | clear () |
Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded. | |
void | flip () |
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded. | |
size_t | limit () const |
Gets this buffer's limit. | |
void | limit (size_t limit) |
Sets this buffer's limit. | |
void | mark () |
Sets this buffer's mark at its position. | |
size_t | size () const |
Buffer's capacity. | |
size_t | position () const |
Gets this buffer's position. | |
void | position (size_t position) |
Sets this buffer's position. | |
size_t | remaining () const |
Returns the number of elements between the current position and the limit (remaining in this buffer). | |
bool | hasRemaining () const |
Tells whether there are any elements between the current position and the limit. | |
void | reset () |
Resets this buffer's position to the previously-marked position. | |
void | rewind () |
Rewinds this buffer. The position is set to zero and the mark is discarded. Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:. | |
void | putLongInt (uint64_t value) |
Writes eight bytes containing the given long value, in the current byte order, into this buffer at the current position, and then increments the position by eight. | |
uint64_t | getLongInt () |
Reads the next eight bytes at this buffer's current position, composing them into a long value according to the current byte order, and then increments the position by eight. | |
void | putInteger (uint32_t 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. | |
uint32_t | getInteger () |
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. | |
void | putShortInt (uint16_t 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. | |
uint16_t | getShortInt () |
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. | |
void | putByte (uint8_t value) |
Writes the given byte into this buffer at the current position, and then increments the position. | |
uint8_t | getByte () |
Relative method. Reads the byte at this buffer's current position, and then increments the position. | |
uint8_t | getByte (size_t index) const |
Absolute get method. Reads the byte at the given index. | |
void | putBytes (void *source, size_t nbytes) |
Relative bulk put method (optional operation). This method transfers the entire content of the given source byte array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation:. | |
void | getBytes (void *dest, size_t nbytes) |
Relative bulk get method. | |
ByteOrder | order () const |
Gets this buffer's byte order. | |
void | order (ByteOrder order) |
Sets this buffer's byte order. | |
char * | buffer () |
Returns the byte array that backs this buffer (optional operation). Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa. |
A typesafe enumeration for byte orders.
tecgraf::ftc::v1_04_01::Buffer::Buffer | ( | size_t | capacity | ) |
The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero.
capacity | The new buffer's capacity, in bytes |
tecgraf::ftc::v1_04_01::Buffer::Buffer | ( | char * | buffer, | |
size_t | size | |||
) |
Wraps a byte array into a buffer.
The new buffer will be backed by the the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be array.length, its position will be zero, and its mark will be undefined. Its backing array will be the given array, and its array offset will be zero.
buffer | The array that will back this buffer | |
size | The size of array |
char* tecgraf::ftc::v1_04_01::Buffer::buffer | ( | ) |
Returns the byte array that backs this buffer (optional operation). Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa.
void tecgraf::ftc::v1_04_01::Buffer::clear | ( | ) |
Clears this buffer. The position is set to zero, the limit is set to the capacity, and the mark is discarded.
Invoke this method before using a sequence of channel-read or put operations to fill this buffer. For example:
buf.clear(); // Prepare buffer for reading in.read(buf); // Read data
This method does not actually erase the data in the buffer, but it is named as if it did because it will most often be used in situations in which that might as well be the case.
void tecgraf::ftc::v1_04_01::Buffer::flip | ( | ) |
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.
After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations. For example:
buf.write(magic); // Prepend header in.read(buf); // Read data into rest of buffer buf.flip(); // Flip buffer out.write(buf); // Write header + data to out
This method is often used in conjunction with the compact method when transferring data from one place to another.
uint8_t tecgraf::ftc::v1_04_01::Buffer::getByte | ( | size_t | index | ) | const |
Absolute get method. Reads the byte at the given index.
index | The index from which the byte will be read |
std::out_of_range | If index is negative or not smaller than the buffer's limit |
uint8_t tecgraf::ftc::v1_04_01::Buffer::getByte | ( | ) |
Relative method. Reads the byte at this buffer's current position, and then increments the position.
std::underflow_error | If the buffer's current position is not smaller than its limit |
void tecgraf::ftc::v1_04_01::Buffer::getBytes | ( | void * | dest, | |
size_t | nbytes | |||
) |
Relative bulk get method.
This method transfers bytes from this buffer into the given destination array. An invocation of this method of the form src.get(a) behaves in exactly the same way as the invocation:
src.getBytes(a, 0, a.length)
dest | The array into which bytes are to be written | |
nbytes | The size of array |
std::underflow_error | If there are fewer than length bytes remaining in this buffer |
uint32_t tecgraf::ftc::v1_04_01::Buffer::getInteger | ( | ) |
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.
std::underflow_error | If there are fewer than four bytes remaining in this buffer |
uint64_t tecgraf::ftc::v1_04_01::Buffer::getLongInt | ( | ) |
Reads the next eight bytes at this buffer's current position, composing them into a long value according to the current byte order, and then increments the position by eight.
std::underflow_error | If there are fewer than eight bytes remaining in this buffer |
uint16_t tecgraf::ftc::v1_04_01::Buffer::getShortInt | ( | ) |
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.
std::underflow_error | If there are fewer than two bytes remaining in this buffer |
bool tecgraf::ftc::v1_04_01::Buffer::hasRemaining | ( | ) | const |
Tells whether there are any elements between the current position and the limit.
void tecgraf::ftc::v1_04_01::Buffer::limit | ( | size_t | limit | ) |
Sets this buffer's limit.
If the position is larger than the new limit then it is set to the new limit. If the mark is defined and larger than the new limit then it is discarded. The new limit value must be non-negative and no larger than this buffer's capacity
std::range_error | If the preconditions on new limit do not hold |
size_t tecgraf::ftc::v1_04_01::Buffer::limit | ( | ) | const |
Gets this buffer's limit.
void tecgraf::ftc::v1_04_01::Buffer::order | ( | ByteOrder | order | ) |
Sets this buffer's byte order.
order | The new byte order. |
ByteOrder tecgraf::ftc::v1_04_01::Buffer::order | ( | ) | const |
Gets this buffer's byte order.
void tecgraf::ftc::v1_04_01::Buffer::position | ( | size_t | position | ) |
Sets this buffer's position.
If the mark is defined and larger than the new position then it is discarded. The new position value must be non-negative and no larger than the current limit.
size_t tecgraf::ftc::v1_04_01::Buffer::position | ( | ) | const |
Gets this buffer's position.
void tecgraf::ftc::v1_04_01::Buffer::putByte | ( | uint8_t | value | ) |
Writes the given byte into this buffer at the current position, and then increments the position.
value | The byte to be written |
std::overflow_error | If this buffer's current position is not smaller than its limit |
void tecgraf::ftc::v1_04_01::Buffer::putBytes | ( | void * | source, | |
size_t | nbytes | |||
) |
Relative bulk put method (optional operation). This method transfers the entire content of the given source byte array into this buffer. An invocation of this method of the form dst.put(a) behaves in exactly the same way as the invocation:.
dst.putBytes(a, 0, nbytes)
source | The array from which bytes are to be read | |
nbytes | The size of array |
std::overflow_error | If there is insufficient space in this buffer |
void tecgraf::ftc::v1_04_01::Buffer::putInteger | ( | uint32_t | 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.
value | The int value to be written |
std::overflow_error | If there are fewer than four bytes remaining in this buffer |
void tecgraf::ftc::v1_04_01::Buffer::putLongInt | ( | uint64_t | value | ) |
Writes eight bytes containing the given long value, in the current byte order, into this buffer at the current position, and then increments the position by eight.
value | The long value to be written |
std::overflow_error | If there are fewer than eight bytes remaining in this buffer |
void tecgraf::ftc::v1_04_01::Buffer::putShortInt | ( | uint16_t | 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.
value | The short value to be written |
std::overflow_error | If there are fewer than two bytes remaining in this buffer |
size_t tecgraf::ftc::v1_04_01::Buffer::remaining | ( | ) | const |
Returns the number of elements between the current position and the limit (remaining in this buffer).
void tecgraf::ftc::v1_04_01::Buffer::reset | ( | ) |
Resets this buffer's position to the previously-marked position.
Invoking this method neither changes nor discards the mark's value.
std:logic_error | If the mark has not been set |
void tecgraf::ftc::v1_04_01::Buffer::rewind | ( | ) |
Rewinds this buffer. The position is set to zero and the mark is discarded. Invoke this method before a sequence of channel-write or get operations, assuming that the limit has already been set appropriately. For example:.
out.put(buf); // Write remaining data buf.rewind(); // Rewind buffer buf.get(array); // Copy data into array
size_t tecgraf::ftc::v1_04_01::Buffer::size | ( | ) | const |
Buffer's capacity.