ClickHouse/dbms/src/IO/tests/var_uint.cpp

53 lines
908 B
C++
Raw Normal View History

2010-09-14 16:43:00 +00:00
#include <string>
#include <iostream>
#include <DB/IO/VarInt.h>
#include <DB/IO/WriteBufferFromString.h>
#include <DB/IO/ReadBufferFromString.h>
2013-06-21 21:05:16 +00:00
#include <DB/IO/ReadHelpers.h>
2010-09-14 16:43:00 +00:00
#include <Poco/HexBinaryEncoder.h>
int main(int argc, char ** argv)
{
if (argc != 2)
{
std::cerr << "Usage: " << std::endl
<< argv[0] << " unsigned_number" << std::endl;
return 1;
}
2016-08-05 02:41:41 +00:00
2013-06-21 21:05:16 +00:00
DB::UInt64 x = DB::parse<UInt64>(argv[1]);
2010-09-14 16:43:00 +00:00
Poco::HexBinaryEncoder hex(std::cout);
DB::writeVarUInt(x, hex);
std::cout << std::endl;
std::string s;
{
DB::WriteBufferFromString wb(s);
DB::writeVarUInt(x, wb);
wb.next();
}
hex << s;
std::cout << std::endl;
2016-08-05 02:41:41 +00:00
s.clear();
s.resize(9);
s.resize(DB::writeVarUInt(x, &s[0]) - s.data());
hex << s;
std::cout << std::endl;
DB::UInt64 y = 0;
2016-08-05 02:41:41 +00:00
DB::ReadBufferFromString rb(s);
DB::readVarUInt(y, rb);
std::cerr << "x: " << x << ", y: " << y << std::endl;
2016-08-05 02:41:41 +00:00
2010-09-14 16:43:00 +00:00
return 0;
}