Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-1700

b_timestamp fields inversion

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0
    • Component/s: BSON
    • None

      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, &timestamp, &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;
      };
      

       

       

       

       

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            criton Cristiano Toninato
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: