Skip to content

Commit bdbf400

Browse files
Merge branch 'fix-varint' of https://github.com/artpaul/clickhouse-cpp
2 parents 7c67c6d + 1405179 commit bdbf400

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

clickhouse/base/coded.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ bool CodedInputStream::Skip(size_t count) {
4545
bool CodedInputStream::ReadVarint64(uint64_t* value) {
4646
*value = 0;
4747

48-
for (size_t i = 0; i < 9; ++i) {
48+
for (size_t i = 0; i < MAX_VARINT_BYTES; ++i) {
4949
uint8_t byte;
5050

5151
if (!input_->ReadByte(&byte)) {
5252
return false;
5353
} else {
54-
*value |= (byte & 0x7F) << (7 * i);
54+
*value |= uint64_t(byte & 0x7F) << (7 * i);
5555

5656
if (!(byte & 0x80)) {
5757
return true;
@@ -81,7 +81,7 @@ void CodedOutputStream::WriteVarint64(uint64_t value) {
8181
uint8_t bytes[MAX_VARINT_BYTES];
8282
int size = 0;
8383

84-
for (size_t i = 0; i < 9; ++i) {
84+
for (size_t i = 0; i < MAX_VARINT_BYTES; ++i) {
8585
uint8_t byte = value & 0x7F;
8686
if (value > 0x7F)
8787
byte |= 0x80;

clickhouse/client.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ class Client::Impl {
106106
void WriteBlock(const Block& block, CodedOutputStream* output);
107107

108108
private:
109-
void Disconnect() {
110-
socket_.Close();
111-
}
112-
113109
/// In case of network errors tries to reconnect to server and
114110
/// call fuc several times.
115111
void RetryGuard(std::function<void()> fuc);
@@ -186,9 +182,8 @@ Client::Impl::Impl(const ClientOptions& opts)
186182
}
187183
}
188184

189-
Client::Impl::~Impl() {
190-
Disconnect();
191-
}
185+
Client::Impl::~Impl()
186+
{ }
192187

193188
void Client::Impl::ExecuteQuery(Query query) {
194189
EnsureNull en(static_cast<QueryEvents*>(&query), &events_);

ut/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
ADD_EXECUTABLE (clickhouse-cpp-ut
22
main.cpp
33

4-
columns_ut.cpp
5-
types_ut.cpp
6-
type_parser_ut.cpp
74
client_ut.cpp
5+
columns_ut.cpp
86
socket_ut.cpp
7+
stream_ut.cpp
98
tcp_server.cpp
9+
type_parser_ut.cpp
10+
types_ut.cpp
1011
)
1112

1213
TARGET_LINK_LIBRARIES (clickhouse-cpp-ut

ut/stream_ut.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <clickhouse/base/coded.h>
2+
#include <contrib/gtest/gtest.h>
3+
4+
using namespace clickhouse;
5+
6+
TEST(CodedStreamCase, Varint64) {
7+
Buffer buf;
8+
9+
{
10+
BufferOutput output(&buf);
11+
CodedOutputStream coded(&output);
12+
coded.WriteVarint64(18446744071965638648ULL);
13+
}
14+
15+
16+
{
17+
ArrayInput input(buf.data(), buf.size());
18+
CodedInputStream coded(&input);
19+
uint64_t value;
20+
ASSERT_TRUE(coded.ReadVarint64(&value));
21+
ASSERT_EQ(value, 18446744071965638648ULL);
22+
}
23+
}

0 commit comments

Comments
 (0)