29 static const std::array<unsigned char, 8> masks = {{
30 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
33 for (k = 0; k < 8; ++k) {
38 throw ebmlInvalidVint(
"Variable-length integer cannot start with null byte.");
53 if (n == 0xffffffffffffffffULL) {
57 if (n < ((1ULL << (7 * k)) - 1ULL)) {
62 throw std::overflow_error(
63 std::string(
"int too big to convert (") + std::to_string(__LINE__)
64 + std::string(
":") + std::string(__FILE__) + std::string(
")")
82 unsigned long long val = unpack<unsigned long long>(
data,
size);
83 val &= ~(1ULL << (7 *
size));
84 if (val == ((1ULL << (7 *
size)) - 1ULL)) {
85 return 0xffffffffffffffffULL;
115 inline void packVint(
unsigned long long n,
unsigned char size,
char* dest) {
117 throw std::invalid_argument(
118 std::string(
"packVint: invalid value for size (") + std::to_string(__LINE__)
119 + std::string(
":") + std::string(__FILE__) + std::string(
")")
123 if (n == 0xffffffffffffffffULL) {
128 if (((1ULL << (7 *
size)) - 1ULL) <= n) {
129 throw std::overflow_error(
130 std::string(
"int too big to convert (") + std::to_string(__LINE__)
131 + std::string(
":") + std::string(__FILE__) + std::string(
")")
148 inline unsigned char packVint(
unsigned long long n,
char* dest) {
165 unsigned long long unpackVint(
const char*
data,
size_t dataSize,
unsigned char& vintw);
177 unsigned long long unpackVint(ioBase& file,
unsigned char& vintw);
191 unsigned long long unpackVint(ioBase& file, off_t offset,
unsigned char& vintw);
T & data(const ebmlElement_sp &elem)
unsigned char vintWidth(char b)
Determines the width (in bytes) of a variable-length integer (vint) based on its first byte...
Definition: vint.h:28
size_t size(const std::string &value)
Definition: binary.h:8
void packVint(unsigned long long n, unsigned char size, char *dest)
Encodes an unsigned long long as a variable-length integer (vint) with a specified width...
Definition: vint.h:115
Definition: exceptions.h:56
Definition: basictypes.h:40
unsigned char widthAsVint(unsigned long long n)
Computes the minimal width (in bytes) required to encode an unsigned long long as a vint...
Definition: vint.h:51
const size_t UNKNOWN
Special constant representing an unknown or maximum value.
Definition: vint.cpp:15
unsigned long long unpackVint(const char *data, size_t dataSize, unsigned char &vintw)
Decodes a vint from a byte array of known size.
Definition: vint.cpp:20
size_t pack(const std::string &value, size_t size, char *dest)
Definition: binary.h:12