Tide 0.1.0
|
Functions for managing integers coded for EBML. More...
Functions | |
std::streamsize | size_u (uint64_t integer) |
Get the size of an unsigned integer after encoding. | |
std::streamsize | size_s (int64_t integer) |
Get the size of a signed integer after encoding. | |
std::vector< char > | encode_u (uint64_t integer) |
Encode an unsigned integer into a buffer. | |
std::vector< char > | encode_s (int64_t integer) |
Encode a signed integer into a buffer. | |
std::streamsize | write_u (uint64_t integer, std::ostream &output) |
Encode and write an unsigned integer into a byte stream. | |
std::streamsize | write_s (int64_t integer, std::ostream &output) |
Encode and write a signed integer into a byte stream. | |
uint64_t | decode_u (std::vector< char > const &buffer) |
Decode an unsigned integer from a buffer. | |
int64_t | decode_s (std::vector< char > const &buffer) |
Decode a signed integer from a buffer. | |
uint64_t | read_u (std::istream &input, std::streamsize n) |
Read and decode an unsigned integer from a byte stream. | |
int64_t | read_s (std::istream &input, std::streamsize n) |
Read and decode a signed integer from a byte stream. |
Functions for managing integers coded for EBML.
This namespace contains the functions used to mange the way integers, both signed and unsigned, are stored in EBML files. Rather than writing a constant number of bytes regardless of the value being stored, EBML specifies that leading 0x00 bytes and, for negative signed integers, leading 0xFF bytes, be trimmed. For example, a value of 2 will be stored as 0x02, even if the variable that holds it is 32-bit (i.e. 0x00000002). Similarly, a value of -30000, or 0xFFFFF530 in 32 bits, will be stored as 0xF530.
Note that this is distinct from the coding used on EBML Element IDs and data sizes, which relies on leading zero bits to indicate the stored size.
int64_t tide::ebml_int::decode_s | ( | std::vector< char > const & | buffer | ) |
Decode a signed integer from a buffer.
Decodes the unsigned integer stored in the buffer according to the EBML specification for unsigned integers.
[in] | buffer | The buffer holding the raw data. The size of the buffer defines the number of bytes to use for the integer; it must be 8 or less. |
uint64_t tide::ebml_int::decode_u | ( | std::vector< char > const & | buffer | ) |
Decode an unsigned integer from a buffer.
Decodes the unsigned integer stored in the buffer according to the EBML specification for unsigned integers.
[in] | buffer | The buffer holding the raw data. The size of the buffer defines the number of bytes to use for the integer; it must be 8 or less. |
std::vector<char> tide::ebml_int::encode_s | ( | int64_t | integer | ) |
Encode a signed integer into a buffer.
Encodes an unsigned integer according to the EBML specification for signed integers. Leading zero or 0xFF bytes are trimmed.
[in] | integer | The integer to encode. |
std::vector<char> tide::ebml_int::encode_u | ( | uint64_t | integer | ) |
Encode an unsigned integer into a buffer.
Encodes an unsigned integer according to the EBML specification for unsigned integers. Leading zero bytes are trimmed.
[in] | integer | The integer to encode. |
int64_t tide::ebml_int::read_s | ( | std::istream & | input, |
std::streamsize | n | ||
) |
Read and decode a signed integer from a byte stream.
This function performs the same task as tide::ebml_int::decode_s(), but instead of reading from a basic buffer, it reads from a std::istream object.
[in] | input | The std::istream object to read from. |
[in] | n | The number of bytes from the buffer to read. |
ReadError | if there is an error reading the input stream. |
uint64_t tide::ebml_int::read_u | ( | std::istream & | input, |
std::streamsize | n | ||
) |
Read and decode an unsigned integer from a byte stream.
This function performs the same task as tide::ebml_int::decode_u(), but instead of reading from a basic buffer, it reads from a std::istream object.
[in] | input | The std::istream object to read from. |
[in] | n | The number of bytes from the buffer to read. |
ReadError | if there is an error reading the input stream. |
std::streamsize tide::ebml_int::size_s | ( | int64_t | integer | ) |
Get the size of a signed integer after encoding.
The size required by an encoded integer depends on the value of that integer, and will range from 1 to 8 bytes.
[in] | integer | The integer to get the size of. |
std::streamsize tide::ebml_int::size_u | ( | uint64_t | integer | ) |
Get the size of an unsigned integer after encoding.
The size required by an encoded integer depends on the value of that integer, and will range from 1 to 8 bytes.
[in] | integer | The integer to get the size of. |
std::streamsize tide::ebml_int::write_s | ( | int64_t | integer, |
std::ostream & | output | ||
) |
Encode and write a signed integer into a byte stream.
This function performs the same task as tide::ebml_int::encode_s(), but instead of writing to a basic buffer, it writes to a std::ostream object.
[in] | integer | The integer to encode. |
[in] | output | The std::ostream object to write to. |
WriteError | if there is an error writing the output stream. |
std::streamsize tide::ebml_int::write_u | ( | uint64_t | integer, |
std::ostream & | output | ||
) |
Encode and write an unsigned integer into a byte stream.
This function performs the same task as tide::ebml_int::encode_u(), but instead of writing to a basic buffer, it writes to a std::ostream object.
[in] | integer | The integer to encode. |
[in] | output | The std::ostream object to write to. |
WriteError | if there is an error writing the output stream. |