1BSON_ITER_INIT_FROM_DATA(3) libbson BSON_ITER_INIT_FROM_DATA(3)
2
3
4
6 bson_iter_init_from_data - bson_iter_init_from_data()
7
9 bool
10 bson_iter_init_from_data (bson_iter_t *iter, const uint8_t *data, size_t length);
11
13 • iter: A bson_iter_t.
14
15 • data: A buffer to initialize with.
16
17 • length: The length of data in bytes.
18
20 The bson_iter_init_from_data() function shall initialize iter to iter‐
21 ate upon the buffer data, which must contain a BSON document. Upon ini‐
22 tialization, iter is placed before the first element. Callers must call
23 bson_iter_next(), bson_iter_find(), or bson_iter_find_case() to advance
24 to an element.
25
27 Returns true if the iter was successfully initialized.
28
30 static void
31 print_doc_id (const uint8_t *data, size_t length)
32 {
33 bson_iter_t iter;
34 bson_oid_t oid;
35 char oidstr[25];
36
37 if (bson_iter_init_from_data (&iter, data, length) && bson_iter_find (&iter, "_id") &&
38 BSON_ITER_HOLDS_OID (&iter)) {
39 bson_iter_oid (&iter, &oid);
40 bson_oid_to_string (&oid, oidstr);
41 printf ("%s\n", oidstr);
42 } else {
43 printf ("Document is missing _id.\n");
44 }
45 }
46
48 MongoDB, Inc
49
51 2017-present, MongoDB, Inc
52
53
54
55
561.21.1 Mar 02, 2022 BSON_ITER_INIT_FROM_DATA(3)