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

b_timestamp fields inversion

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 3.2.0
    • Fix Version/s: None
    • Component/s: BSON
    • Labels:
      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, &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;
      };
      

       

       

       

       

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: