|
ledger-core
|
#include <BytesReader.h>
Public Types | |
| enum | Seek { SET, CUR, END } |
Public Member Functions | |
| BytesReader (const std::vector< uint8_t > &data, unsigned long offset, unsigned long length) | |
| BytesReader (const std::vector< uint8_t > &data) | |
| void | seek (long offset, Seek origin) |
| uint8_t | peek () const |
| std::vector< uint8_t > | read (unsigned long length) |
| void | read (unsigned long length, std::vector< uint8_t > &out) |
| uint8_t | readNextByte () |
| std::string | readString (unsigned long length) |
| std::string | readNextString () |
| uint32_t | readNextBeUint () |
| uint32_t | readNextLeUint () |
| uint64_t | readNextBeUlong () |
| uint64_t | readNextLeUlong () |
| ledger::core::BigInt | readNextBeBigInt (size_t bytes) |
| ledger::core::BigInt | readNextLeBigInt (size_t bytes) |
| uint64_t | readNextVarInt () |
| std::string | readNextVarString () |
| std::vector< uint8_t > | readUntilEnd () |
| void | reset () |
| unsigned long | getCursor () const |
| bool | hasNext () const |
| unsigned long | available () const |
A helper class used to symplify parsing of data. Beware that every reading or seeking method can throw a std::out_of_range exception.
| ledger::core::BytesReader::BytesReader | ( | const std::vector< uint8_t > & | data, |
| unsigned long | offset, | ||
| unsigned long | length | ||
| ) |
Creates a new bytes reader starting at the given offset and able to read up to length bytes.
| data | The data to read. |
| offset | The reader will start reading at this index in the vector. |
| length | The maximum size on which the reader can read data. |
|
inline |
Creates a new bytes reader starting at byte 0 and able to read bytes until the end of data.
| data | The data to read. |
| unsigned long ledger::core::BytesReader::available | ( | ) | const |
Gets the number of bytes before the end.
| unsigned long ledger::core::BytesReader::getCursor | ( | ) | const |
Gets current cursor position
| bool ledger::core::BytesReader::hasNext | ( | ) | const |
Checks if the reader can read further.
| std::vector< uint8_t > ledger::core::BytesReader::read | ( | unsigned long | length | ) |
Reads length bytes and advance the cursor in the reader.
| length | Number of bytes to read. |
| uint32_t ledger::core::BytesReader::readNextBeUint | ( | ) |
Reads the next big endian unsigned int.
| uint64_t ledger::core::BytesReader::readNextBeUlong | ( | ) |
Reads the next little endian int.
| uint8_t ledger::core::BytesReader::readNextByte | ( | ) |
Reads a single byte.
| uint32_t ledger::core::BytesReader::readNextLeUint | ( | ) |
Reads the next little endian unsigned int.
| uint64_t ledger::core::BytesReader::readNextLeUlong | ( | ) |
Reads the next little endian unsigned long.
| std::string ledger::core::BytesReader::readNextString | ( | ) |
Reads characters until it reach a '\0'
| std::string ledger::core::BytesReader::readString | ( | unsigned long | length | ) |
Reads the next string with the given length.
| length | The length of the string. |
| void ledger::core::BytesReader::reset | ( | ) |
Reset cursor position and offset to 0
| void ledger::core::BytesReader::seek | ( | long | offset, |
| BytesReader::Seek | origin | ||
| ) |
Sets the position indicator associated with the BytesReader to a new position.
| offset | Number of bytes to offset from origin. |
| origin | Position used as reference for the offset. |
1.8.13