How to use ObjectID (OID) interfaces.
Basic Usage
void example() {
{
EXPECT(a != b);
}
{
char bytes[bsoncxx::oid::k_oid_length]{};
{
std::time_t time = oid.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
EXPECT(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) ==
sizeof(str) - 1u);
EXPECT(std::string(str) == "1970-01-01 00:00:00");
}
EXPECT(oid.bytes() != bytes);
EXPECT(oid.size() == bsoncxx::oid::k_oid_length);
EXPECT(std::memcmp(bytes, oid.bytes(), oid.size()) == 0);
EXPECT(oid.to_string() == "000000000000000000000000");
}
{
{
std::time_t time = oid.get_time_t();
char str[sizeof("YYYY-MM-DD HH:MM:SS")];
EXPECT(std::strftime(str, sizeof(str), "%F %T", std::gmtime(&time)) ==
sizeof(str) - 1u);
EXPECT(std::string(str) == "2000-01-01 23:59:59");
}
}
}
Error Handling
void example() {
try {
EXPECT(false && "should not reach this point");
EXPECT(ex.code() == bsoncxx::error_code::k_invalid_oid);
}
try {
char bytes[1]{};
EXPECT(false && "should not reach this point");
EXPECT(ex.code() == bsoncxx::error_code::k_invalid_oid);
}
}