mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
VarInt: fixed error with signed integer.
This commit is contained in:
parent
37d340b404
commit
156533bb1c
@ -27,12 +27,11 @@ inline void writeVarInt(Int x, std::ostream & ostr)
|
||||
}
|
||||
|
||||
|
||||
// TODO: здесь баг
|
||||
/** Прочитать Int64, записанный в формате переменной длины (base128) */
|
||||
inline void readVarInt(Int & x, std::istream & istr)
|
||||
{
|
||||
readVarUInt(*reinterpret_cast<UInt*>(&x), istr);
|
||||
x = (x >> 1) ^ (x << 63);
|
||||
x = (static_cast<UInt>(x) >> 1) ^ -(x & 1);
|
||||
}
|
||||
|
||||
|
||||
|
16
dbms/src/tests/varint.cpp
Normal file
16
dbms/src/tests/varint.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <Poco/Types.h>
|
||||
#include <DB/VarInt.h>
|
||||
#include <DB/Field.h>
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
DB::Int x = -1000000;
|
||||
std::stringstream s;
|
||||
DB::writeVarInt(x, s);
|
||||
DB::readVarInt(x, s);
|
||||
std::cout << x << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user