From 8918d30170eb2d32ad7fa10d52e5f47e1d8a74cf Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 11 Oct 2012 14:52:45 +0300 Subject: [PATCH] Fix dummy error in reading opt-string. --- coding/value_opt_string.hpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/coding/value_opt_string.hpp b/coding/value_opt_string.hpp index 8ccf9c7f3c..1b197cd1ee 100644 --- a/coding/value_opt_string.hpp +++ b/coding/value_opt_string.hpp @@ -12,8 +12,6 @@ class StringNumericOptimal { string m_s; - static const uint8_t numeric_bit = 1; - public: inline bool operator== (StringNumericOptimal const & rhs) const { @@ -40,11 +38,16 @@ public: inline bool IsEmpty() const { return m_s.empty(); } inline string const & Get() const { return m_s; } + /// First uint64_t value is: + /// - a number if low control bit is 1; + /// - a string size-1 if low control bit is 0; + template void Write(TSink & sink) const { + // If string is a number and we have space for control bit uint64_t n; if (strings::to_uint64(m_s, n) && ((n << 1) >> 1) == n) - WriteVarUint(sink, ((n << 1) | numeric_bit)); + WriteVarUint(sink, ((n << 1) | 1)); else { size_t const sz = m_s.size(); @@ -57,9 +60,9 @@ public: template void Read(TSource & src) { - uint32_t sz = ReadVarUint(src); + uint64_t sz = ReadVarUint(src); - if ((sz & numeric_bit) != 0) + if ((sz & 1) != 0) m_s = strings::to_string(sz >> 1); else {