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