Details
-
Bug
-
Resolution: Duplicate
-
Major - P3
-
None
-
3.2.0
-
None
Description
Hi all.
I suspect increment and timestamp fields in struct b_timestamp are swapped.
Output of this snippet
{
|
auto before = bsoncxx::types::b_timestamp();
|
before.timestamp = 10; |
before.increment = 5; |
bsoncxx::builder::basic::document builder{};
|
builder.append(bsoncxx::builder::basic::kvp("ts", before)); |
auto vv = builder.extract();
|
std::cout << bsoncxx::to_json(vv) << std::endl;
|
auto after = vv.view()["ts"].get_timestamp(); |
std::cout << (before == after) << std::endl;
|
std::cout << "t: " << after.timestamp << ", i: " << after.increment << std::endl; |
}
|
is
{ "ts" : { "$timestamp" : { "t" : 10, "i" : 5 } } }
|
0
|
t: 5, i: 10
|
I verified it happens with mongocxx 3.2.0, but it should be the same with current version of mongocxx.
It seems depending on get_timestamp code (return statement):
types::b_timestamp element::get_timestamp() const { |
BSONCXX_TYPE_CHECK(k_timestamp);
|
BSONCXX_CITER; uint32_t timestamp;
|
uint32_t increment;
|
bson_iter_timestamp(&iter, ×tamp, &increment);
|
return types::b_timestamp{timestamp, increment}; |
}
|
|
because b_timestamp is defined
struct BSONCXX_API b_timestamp {
|
static constexpr auto type_id = type::k_timestamp; |
uint32_t increment;
|
uint32_t timestamp;
|
};
|