.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "BSON_OID" "3" "Feb 22, 2024" "1.26.0" "libbson" .sp Libbson provides a simple way to generate ObjectIDs. It can be used in a single\-threaded or multi\-threaded manner depending on your requirements. .sp The \fI\%bson_oid_t\fP structure represents an \fBObjectID\fP in MongoDB. It is a 96\-bit identifier. .SH COMPOSITION .INDENT 0.0 .IP \(bu 2 4 bytes : The UNIX timestamp in big\-endian format. .IP \(bu 2 5 bytes : A random number. .IP \(bu 2 3 bytes : A 24\-bit monotonic counter incrementing from \fBrand()\fP in big\-endian. .UNINDENT .SH SORTING OBJECTIDS .sp The typical way to sort in C is using \fBqsort()\fP\&. Therefore, Libbson provides a \fBqsort()\fP compatible callback function named \fI\%bson_oid_compare()\fP\&. It returns \fBless than 1\fP, \fBgreater than 1\fP, or \fB0\fP depending on the equality of two \fI\%bson_oid_t\fP structures. .SH COMPARING OBJECT IDS .sp If you simply want to compare two \fI\%bson_oid_t\fP structures for equality, use \fI\%bson_oid_equal()\fP\&. .SH GENERATING .sp To generate a \fI\%bson_oid_t\fP, you may use the following. .INDENT 0.0 .INDENT 3.5 .sp .EX bson_oid_t oid; bson_oid_init (&oid, NULL); .EE .UNINDENT .UNINDENT .SH PARSING OBJECTID STRINGS .sp You can also parse a string containing a \fI\%bson_oid_t\fP\&. The input string \fIMUST\fP be 24 characters or more in length. .INDENT 0.0 .INDENT 3.5 .sp .EX bson_oid_t oid; bson_oid_init_from_string (&oid, \(dq123456789012345678901234\(dq); .EE .UNINDENT .UNINDENT .INDENT 0.0 .INDENT 3.5 .sp .EX bson_oid_t oid; bson_oid_init_from_string_unsafe (&oid, \(dq123456789012345678901234\(dq); .EE .UNINDENT .UNINDENT .SH HASHING OBJECTIDS .sp If you need to store items in a hashtable, you may want to use the \fI\%bson_oid_t\fP as the key. Libbson provides a hash function for just this purpose. It is based on DJB hash. .INDENT 0.0 .INDENT 3.5 .sp .EX unsigned hash; hash = bson_oid_hash (oid); .EE .UNINDENT .UNINDENT .SH FETCHING OBJECTID CREATION TIME .sp You can easily fetch the time that a \fI\%bson_oid_t\fP was generated using \fI\%bson_oid_get_time_t()\fP\&. .INDENT 0.0 .INDENT 3.5 .sp .EX time_t t; t = bson_oid_get_time_t (oid); printf (\(dqThe OID was generated at %u\en\(dq, (unsigned) t); .EE .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .