bufferlist bl(1000000);
encode(src, bl);
T dst;
- bufferlist::iterator i(bl.begin());
+ auto i = bl.cbegin();
decode(dst, i);
ASSERT_EQ(src, dst) << "Encoding roundtrip changed the string: orig=" << src << ", but new=" << dst;
}
encode(len, bl);
encode_nohead(src, bl);
T dst;
- bufferlist::iterator i(bl.begin());
+ auto i = bl.cbegin();
decode(len, i);
decode_nohead(len, dst, i);
ASSERT_EQ(src, dst) << "Encoding roundtrip changed the string: orig=" << src << ", but new=" << dst;
return data == rhs.data;
}
- friend void decode(ConstructorCounter &s, bufferlist::iterator& p)
+ friend void decode(ConstructorCounter &s, bufferlist::const_iterator& p)
{
- ::decode(s.data, p);
+ decode(s.data, p);
}
friend void encode(const ConstructorCounter &s, bufferlist& p)
{
- ::encode(s.data, p);
+ encode(s.data, p);
}
friend ostream& operator<<(ostream &oss, const ConstructorCounter &cc)
EXPECT_EQ(my_val_t::get_assigns(), 0);
}
+namespace ceph {
// make sure that the legacy encode/decode methods are selected
// over the ones defined using templates. the later is likely to
// be slower, see also the definition of "WRITE_INT_DENC" in
// make sure the test fails if i get called
ASSERT_TRUE(false);
}
+}
+
+namespace {
+ // search `underlying_type` in denc.h for supported underlying types
+ enum class Colour : int8_t { R,G,B };
+ ostream& operator<<(ostream& os, Colour c) {
+ switch (c) {
+ case Colour::R:
+ return os << "Colour::R";
+ case Colour::G:
+ return os << "Colour::G";
+ case Colour::B:
+ return os << "Colour::B";
+ default:
+ return os << "Colour::???";
+ }
+ }
+}
TEST(EncodingRoundTrip, Integers) {
// int types
i = 42;
test_encode_and_decode(i);
}
+ // enum
+ {
+ test_encode_and_decode(Colour::R);
+ // this should not build, as the size of unsigned is not the same on
+ // different archs, that's why denc_traits<> intentionally leaves
+ // `int` and `unsigned int` out of supported types.
+ //
+ // enum E { R, G, B };
+ // test_encode_and_decode(R);
+ }
}
const char* expected_what[] = {
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][1]);
uint32_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_varint(u, p);
ASSERT_EQ(v[i][0], u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][2]);
int32_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_signed_varint(u, p);
ASSERT_EQ((int32_t)v[i][0], u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][3]);
int64_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_signed_varint(u, p);
ASSERT_EQ(x, u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][1]);
uint32_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_varint_lowz(u, p);
ASSERT_EQ(v[i][0], u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][2]);
int64_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_signed_varint_lowz(u, p);
ASSERT_EQ(x, u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][3]);
int64_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_signed_varint_lowz(u, p);
ASSERT_EQ(x, u);
}
cout << std::endl;
ASSERT_EQ(bl.length(), v[i][1]);
uint64_t u;
- auto p = bl.begin().get_current_ptr().begin();
+ auto p = bl.begin().get_current_ptr().cbegin();
denc_lba(u, p);
ASSERT_EQ(v[i][0], u);
}