Tawara  0.1.0
Functions
tawara::ebml_int Namespace Reference

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. More...
 
std::streamsize size_s (int64_t integer)
 Get the size of a signed integer after encoding. More...
 
std::vector< char > encode_u (uint64_t integer)
 Encode an unsigned integer into a buffer. More...
 
std::vector< char > encode_s (int64_t integer)
 Encode a signed integer into a buffer. More...
 
std::streamsize write_u (uint64_t integer, std::ostream &output)
 Encode and write an unsigned integer into a byte stream. More...
 
std::streamsize write_s (int64_t integer, std::ostream &output)
 Encode and write a signed integer into a byte stream. More...
 
uint64_t decode_u (std::vector< char > const &buffer)
 Decode an unsigned integer from a buffer. More...
 
int64_t decode_s (std::vector< char > const &buffer)
 Decode a signed integer from a buffer. More...
 
uint64_t read_u (std::istream &input, std::streamsize n)
 Read and decode an unsigned integer from a byte stream. More...
 
int64_t read_s (std::istream &input, std::streamsize n)
 Read and decode a signed integer from a byte stream. More...
 

Detailed Description

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.

Function Documentation

int64_t tawara::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.

Parameters
[in]bufferThe 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.
Returns
The decoded unsigned integer.
uint64_t tawara::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.

Parameters
[in]bufferThe 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.
Returns
The decoded unsigned integer.
std::vector<char> tawara::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.

Parameters
[in]integerThe integer to encode.
Returns
A vector containing the encoded data.
std::vector<char> tawara::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.

Parameters
[in]integerThe integer to encode.
Returns
A vector containing the encoded data.
int64_t tawara::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 tawara::ebml_int::decode_s(), but instead of reading from a basic buffer, it reads from a std::istream object.

Parameters
[in]inputThe std::istream object to read from.
[in]nThe number of bytes from the buffer to read.
Returns
The decoded signed integer.
Exceptions
ReadErrorif there is an error reading the input stream.
uint64_t tawara::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 tawara::ebml_int::decode_u(), but instead of reading from a basic buffer, it reads from a std::istream object.

Parameters
[in]inputThe std::istream object to read from.
[in]nThe number of bytes from the buffer to read.
Returns
The decoded unsigned integer.
Exceptions
ReadErrorif there is an error reading the input stream.
std::streamsize tawara::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.

Parameters
[in]integerThe integer to get the size of.
Returns
The size, in bytes, that the integer will require when coded.
std::streamsize tawara::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.

Parameters
[in]integerThe integer to get the size of.
Returns
The size, in bytes, that the integer will require when coded.
std::streamsize tawara::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 tawara::ebml_int::encode_s(), but instead of writing to a basic buffer, it writes to a std::ostream object.

Parameters
[in]integerThe integer to encode.
[in]outputThe std::ostream object to write to.
Returns
The number of bytes written.
Exceptions
WriteErrorif there is an error writing the output stream.
std::streamsize tawara::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 tawara::ebml_int::encode_u(), but instead of writing to a basic buffer, it writes to a std::ostream object.

Parameters
[in]integerThe integer to encode.
[in]outputThe std::ostream object to write to.
Returns
The number of bytes written.
Exceptions
WriteErrorif there is an error writing the output stream.