Skip to content

Commit

Permalink
Merge pull request #8809 from vespa-engine/toregge/handle-long-long-i…
Browse files Browse the repository at this point in the history
…n-statebuf

Also handle long long in search::StateBuf.
  • Loading branch information
baldersheim committed Mar 17, 2019
2 parents 62e2421 + ca51f81 commit 5d85d59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
12 changes: 9 additions & 3 deletions searchlib/src/tests/util/statebuf/statebuf_test.cpp
Expand Up @@ -52,10 +52,16 @@ TEST_F("keys can be appended to stream", Fixture)
}


TEST_F("integers can be appended to stream", Fixture)
TEST_F("positive integers can be appended to stream", Fixture)
{
f << (UINT64_C(1) << 63) << " " << -42l << " " << 0l;
EXPECT_EQUAL("9223372036854775808 -42 0", f.str());
f << (1ull << 63) << " " << 42l << " " << 21 << " " << 0;
EXPECT_EQUAL("9223372036854775808 42 21 0", f.str());
}

TEST_F("negative integers can be appended to stream", Fixture)
{
f << (1ll << 63) << " " << -42l << " " << -21;
EXPECT_EQUAL("-9223372036854775808 -42 -21", f.str());
}

TEST_F("struct timespec can be appended to stream", Fixture)
Expand Down
28 changes: 22 additions & 6 deletions searchlib/src/vespa/searchlib/util/statebuf.cpp
Expand Up @@ -72,7 +72,7 @@ StateBuf::appendKey(const char *s) noexcept


StateBuf &
StateBuf::operator<<(unsigned long val) noexcept
StateBuf::operator<<(unsigned long long val) noexcept
{
char buf[22];
char *p = buf;
Expand All @@ -92,29 +92,45 @@ StateBuf::operator<<(unsigned long val) noexcept


StateBuf &
StateBuf::operator<<(long val) noexcept
StateBuf::operator<<(long long val) noexcept
{
if (val < 0) {
*this << '-' << static_cast<unsigned long>(- val);
*this << '-' << static_cast<unsigned long long>(- val);
} else {
*this << static_cast<unsigned long>(val);
*this << static_cast<unsigned long long>(val);
}
return *this;
}


StateBuf &
StateBuf::operator<<(unsigned long val) noexcept
{
*this << static_cast<unsigned long long>(val);
return *this;
}


StateBuf &
StateBuf::operator<<(long val) noexcept
{
*this << static_cast<long long>(val);
return *this;
}


StateBuf &
StateBuf::operator<<(unsigned int val) noexcept
{
*this << static_cast<unsigned long>(val);
*this << static_cast<unsigned long long>(val);
return *this;
}


StateBuf &
StateBuf::operator<<(int val) noexcept
{
*this << static_cast<long>(val);
*this << static_cast<long long>(val);
return *this;
}

Expand Down
6 changes: 6 additions & 0 deletions searchlib/src/vespa/searchlib/util/statebuf.h
Expand Up @@ -58,6 +58,12 @@ class StateBuf
StateBuf &
appendAddr(void *addr) noexcept;

StateBuf &
operator<<(unsigned long long val) noexcept;

StateBuf &
operator<<(long long val) noexcept;

StateBuf &
operator<<(unsigned long val) noexcept;

Expand Down

0 comments on commit 5d85d59

Please sign in to comment.