1BSON_OID_T(3)                       libbson                      BSON_OID_T(3)
2
3
4

NAME

6       bson_oid_t - bson_oid_t
7
8       BSON ObjectID Abstraction
9

SYNOPSIS

11          #include <bson/bson.h>
12
13          typedef struct {
14             uint8_t bytes[12];
15          } bson_oid_t;
16

DESCRIPTION

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

STRING CONVERSION

31       You can convert an Object ID to a string using bson_oid_to_string() and
32       back with bson_oid_init_from_string().
33

HASHING

35       A  bson_oid_t  can  be  used   in   hashtables   using   the   function
36       bson_oid_hash() and bson_oid_equal().
37

COMPARING

39       A  bson_oid_t  can  be compared to another using bson_oid_compare() for
40       qsort() style comparing and bson_oid_equal() for direct equality.
41

VALIDATING

43       You can validate that a string containing  a  hex-encoded  ObjectID  is
44       valid using the function bson_oid_is_valid().
45

EXAMPLE

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

AUTHOR

70       MongoDB, Inc
71
73       2017-present, MongoDB, Inc
74
75
76
77
781.17.6                           Jun 03, 2021                    BSON_OID_T(3)
Impressum