1BSON_OID_T(3)                       libbson                      BSON_OID_T(3)
2
3
4
5BSON ObjectID Abstraction
6

SYNOPSIS

8          #include <bson/bson.h>
9
10          typedef struct {
11             uint8_t bytes[12];
12          } bson_oid_t;
13

DESCRIPTION

15       The bson_oid_t structure contains the 12-byte ObjectId notation defined
16       by the BSON ObjectID specification.
17
18       ObjectId is a 12-byte BSON type, constructed using:
19
20       • a 4-byte value representing the seconds since the Unix epoch (in  Big
21         Endian).
22
23       • a 5-byte random value.
24
25       • a 3-byte counter (Big Endian), starting with a random value.
26

STRING CONVERSION

28       You can convert an Object ID to a string using bson_oid_to_string() and
29       back with bson_oid_init_from_string().
30

HASHING

32       A  bson_oid_t  can  be  used   in   hashtables   using   the   function
33       bson_oid_hash() and bson_oid_equal().
34

COMPARING

36       A  bson_oid_t  can  be compared to another using bson_oid_compare() for
37       qsort() style comparing and bson_oid_equal() for direct equality.
38

VALIDATING

40       You can validate that a string containing  a  hex-encoded  ObjectID  is
41       valid using the function bson_oid_is_valid().
42

EXAMPLE

44          #include <bson/bson.h>
45          #include <stdio.h>
46
47          int
48          main (int argc, char *argv[])
49          {
50             bson_oid_t oid;
51             char str[25];
52
53             bson_oid_init (&oid, NULL);
54             bson_oid_to_string (&oid, str);
55             printf ("%s\n", str);
56
57             if (bson_oid_is_valid (str, sizeof str)) {
58                bson_oid_init_from_string (&oid, str);
59             }
60
61             printf ("The UNIX time was: %u\n", (unsigned) bson_oid_get_time_t (&oid));
62
63             return 0;
64          }
65

AUTHOR

67       MongoDB, Inc
68
70       2017-present, MongoDB, Inc
71
72
73
74
751.25.1                           Nov 08, 2023                    BSON_OID_T(3)
Impressum