|
Electroneum
|
provides the implementation of varint's More...
#include <limits>#include <type_traits>#include <utility>#include <sstream>#include <string>

Go to the source code of this file.
Namespaces | |
| tools | |
| Various Tools. | |
Enumerations | |
| enum | { tools::EVARINT_OVERFLOW = -1, tools::EVARINT_REPRESENT = -2 } |
| Error codes for varint. More... | |
Functions | |
| template<typename OutputIt , typename T > | |
| std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value, void >::type | tools::write_varint (OutputIt &&dest, T i) |
| writes a varint to a stream. More... | |
| template<typename T > | |
| std::string | tools::get_varint_data (const T &v) |
| Returns the string that represents the varint. More... | |
provides the implementation of varint's
The representation of varints is rather odd. The first bit of each octet is significant, it represents wheter there is another part waiting to be read. For example 0x8002 would return 0x200, even though 0x02 does not have its msb set. The actual way they are read is as follows: Strip the msb of each byte, then from left to right, read in what remains, placing it in reverse, into the buffer. Thus, the following bit stream: 0xff02 would return 0x027f. 0xff turns into 0x7f, is placed on the beginning of the buffer, then 0x02 is unchanged, since its msb is not set, and placed at the end of the buffer.
Definition in file varint.h.