b = *p++; val |= (b & 0x7f) << 42; if (b >= 0) break;
b = *p++; val |= (b & 0x7f) << 49; if (b >= 0) break;
b = *p++; val |= (b & 0x7f) << 56; if (b >= 0) break;
- b = *p++; val |= (b & 0x7f) << 63; if (b >= 0) break;
+ b = *p++; val |= (b & 0x01) << 63; if (b >= 0) break;
return makeUnexpected(DecodeVarintError::TooManyBytes);
} while (false);
} else {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01});
}
+void testVarintFail(std::initializer_list<uint8_t> bytes) {
+ size_t n = bytes.size();
+ ByteRange data(&*bytes.begin(), n);
+ auto ret = tryDecodeVarint(data);
+ EXPECT_FALSE(ret.hasValue());
+}
+
+TEST(Varint, Fail) {
+ testVarintFail({0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff});
+}
+
TEST(ZigZag, Simple) {
EXPECT_EQ(0, encodeZigZag(0));
EXPECT_EQ(1, encodeZigZag(-1));