BSON_OID_T(3)
π BSON_OID_T β BSON ObjectID Abstraction π
okay bestie, this is the libbson manual page for bson_oid_t, and it's literally the blueprint for BSON ObjectIds. no cap, it's giving tiny-but-mighty main character energy. β¨
β¨ SYNOPSIS β¨
#include <bson/bson.h>
typedef struct {
uint8_t bytes[12];
} bson_oid_t;
π¦ DESCRIPTION π¦
The bson_oid_t structure contains the 12-byte ObjectId notation defined by the BSON ObjectID specification. periodt. π
ObjectId is a 12-byte BSON type, constructed using:
- a 4-byte value representing the seconds since the Unix epoch (in Big Endian).
- a 5-byte random value.
- a 3-byte counter (Big Endian), starting with a random value.
π STRING CONVERSION π
you can convert an Object ID to a string using bson_oid_to_string() and back with bson_oid_init_from_string(). so reversible, so cute. π
πΈ HASHING πΈ
a bson_oid_t can be used in hashtables using the function bson_oid_hash() and bson_oid_equal(). hashable icon behavior. π¦
π COMPARING π
a bson_oid_t can be compared to another using bson_oid_compare() for qsort() style comparing and bson_oid_equal() for direct equality. lowkey perfect for putting things in order. π
β VALIDATING β
you can validate that a string containing a hex-encoded ObjectID is valid using the function bson_oid_is_valid(). vibe check for hex strings, fr fr. β
π₯ EXAMPLE π₯
okay here's the full example β copy it exactly, bestie, because code is not a vibe you improvise:
#include <bson/bson.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
bson_oid_t oid;
char str[25];
bson_oid_init (&oid, NULL);
bson_oid_to_string (&oid, str);
printf ("%s\n", str);
if (bson_oid_is_valid (str, sizeof str)) {
bson_oid_init_from_string (&oid, str);
}
printf ("The UNIX time was: %u\n", (unsigned) bson_oid_get_time_t (&oid));
return 0;
}
π«Ά AUTHOR π«Ά
MongoDB, Inc β iconic. π
π COPYRIGHT π
2009-present, MongoDB, Inc.
mwah π that's the whole page, brought to you by libbson 2.5.6, dated Oct 09, 2026 β slay and goodbye. πππ
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms