.\" 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_T" "3" "Feb 22, 2024" "1.26.0" "libbson" .sp BSON ObjectID Abstraction .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX #include typedef struct { uint8_t bytes[12]; } bson_oid_t; .EE .UNINDENT .UNINDENT .SH DESCRIPTION .sp The \fI\%bson_oid_t\fP structure contains the 12\-byte ObjectId notation defined by the \fI\%BSON ObjectID specification\fP\&. .sp ObjectId is a 12\-byte BSON type, constructed using: .INDENT 0.0 .IP \(bu 2 a 4\-byte value representing the seconds since the Unix epoch (in Big Endian). .IP \(bu 2 a 5\-byte random value. .IP \(bu 2 a 3\-byte counter (Big Endian), starting with a random value. .UNINDENT .SH STRING CONVERSION .sp You can convert an Object ID to a string using \fI\%bson_oid_to_string()\fP and back with \fI\%bson_oid_init_from_string()\fP\&. .SH HASHING .sp A \fI\%bson_oid_t\fP can be used in hashtables using the function \fI\%bson_oid_hash()\fP and \fI\%bson_oid_equal()\fP\&. .SH COMPARING .sp A \fI\%bson_oid_t\fP can be compared to another using \fI\%bson_oid_compare()\fP for \fBqsort()\fP style comparing and \fI\%bson_oid_equal()\fP for direct equality. .SH VALIDATING .sp You can validate that a string containing a hex\-encoded ObjectID is valid using the function \fI\%bson_oid_is_valid()\fP\&. .SH EXAMPLE .INDENT 0.0 .INDENT 3.5 .sp .EX #include #include 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 (\(dq%s\en\(dq, str); if (bson_oid_is_valid (str, sizeof str)) { bson_oid_init_from_string (&oid, str); } printf (\(dqThe UNIX time was: %u\en\(dq, (unsigned) bson_oid_get_time_t (&oid)); return 0; } .EE .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .