1BSON_T(3)                           Libbson                          BSON_T(3)
2
3
4

NAME

6       bson_t - bson_t
7
8       BSON Document Abstraction
9

SYNOPSIS

11          #include <bson/bson.h>
12
13          /**
14           * bson_empty:
15           * @b: a bson_t.
16           *
17           * Checks to see if @b is an empty BSON document. An empty BSON document is
18           * a 5 byte document which contains the length (4 bytes) and a single NUL
19           * byte indicating end of fields.
20           */
21          #define bson_empty(b) /* ... */
22
23          /**
24           * bson_empty0:
25           *
26           * Like bson_empty() but treats NULL the same as an empty bson_t document.
27           */
28          #define bson_empty0(b) /* ... */
29
30          /**
31           * bson_clear:
32           *
33           * Easily free a bson document and set it to NULL. Use like:
34           *
35           * bson_t *doc = bson_new();
36           * bson_clear (&doc);
37           * BSON_ASSERT (doc == NULL);
38           */
39          #define bson_clear(bptr) /* ... */
40
41          /**
42           * BSON_MAX_SIZE:
43           *
44           * The maximum size in bytes of a BSON document.
45           */
46          #define BSON_MAX_SIZE /* ... */
47
48          #define BSON_APPEND_ARRAY(b, key, val) \
49             bson_append_array (b, key, (int) strlen (key), val)
50
51          #define BSON_APPEND_ARRAY_BEGIN(b, key, child) \
52             bson_append_array_begin (b, key, (int) strlen (key), child)
53
54          #define BSON_APPEND_BINARY(b, key, subtype, val, len) \
55             bson_append_binary (b, key, (int) strlen (key), subtype, val, len)
56
57          #define BSON_APPEND_BOOL(b, key, val) \
58             bson_append_bool (b, key, (int) strlen (key), val)
59
60          #define BSON_APPEND_CODE(b, key, val) \
61             bson_append_code (b, key, (int) strlen (key), val)
62
63          #define BSON_APPEND_CODE_WITH_SCOPE(b, key, val, scope) \
64             bson_append_code_with_scope (b, key, (int) strlen (key), val, scope)
65
66          #define BSON_APPEND_DBPOINTER(b, key, coll, oid) \
67             bson_append_dbpointer (b, key, (int) strlen (key), coll, oid)
68
69          #define BSON_APPEND_DOCUMENT_BEGIN(b, key, child) \
70             bson_append_document_begin (b, key, (int) strlen (key), child)
71
72          #define BSON_APPEND_DOUBLE(b, key, val) \
73             bson_append_double (b, key, (int) strlen (key), val)
74
75          #define BSON_APPEND_DOCUMENT(b, key, val) \
76             bson_append_document (b, key, (int) strlen (key), val)
77
78          #define BSON_APPEND_INT32(b, key, val) \
79             bson_append_int32 (b, key, (int) strlen (key), val)
80
81          #define BSON_APPEND_INT64(b, key, val) \
82             bson_append_int64 (b, key, (int) strlen (key), val)
83
84          #define BSON_APPEND_MINKEY(b, key) \
85             bson_append_minkey (b, key, (int) strlen (key))
86
87          #define BSON_APPEND_DECIMAL128(b, key, val) \
88             bson_append_decimal128 (b, key, (int) strlen (key), val)
89
90          #define BSON_APPEND_MAXKEY(b, key) \
91             bson_append_maxkey (b, key, (int) strlen (key))
92
93          #define BSON_APPEND_NULL(b, key) bson_append_null (b, key, (int) strlen (key))
94
95          #define BSON_APPEND_OID(b, key, val) \
96             bson_append_oid (b, key, (int) strlen (key), val)
97
98          #define BSON_APPEND_REGEX(b, key, val, opt) \
99             bson_append_regex (b, key, (int) strlen (key), val, opt)
100
101          #define BSON_APPEND_UTF8(b, key, val) \
102             bson_append_utf8 (b, key, (int) strlen (key), val, (int) strlen (val))
103
104          #define BSON_APPEND_SYMBOL(b, key, val) \
105             bson_append_symbol (b, key, (int) strlen (key), val, (int) strlen (val))
106
107          #define BSON_APPEND_TIME_T(b, key, val) \
108             bson_append_time_t (b, key, (int) strlen (key), val)
109
110          #define BSON_APPEND_TIMEVAL(b, key, val) \
111             bson_append_timeval (b, key, (int) strlen (key), val)
112
113          #define BSON_APPEND_DATE_TIME(b, key, val) \
114             bson_append_date_time (b, key, (int) strlen (key), val)
115
116          #define BSON_APPEND_TIMESTAMP(b, key, val, inc) \
117             bson_append_timestamp (b, key, (int) strlen (key), val, inc)
118
119          #define BSON_APPEND_UNDEFINED(b, key) \
120             bson_append_undefined (b, key, (int) strlen (key))
121
122          #define BSON_APPEND_VALUE(b, key, val) \
123             bson_append_value (b, key, (int) strlen (key), (val))
124
125          BSON_ALIGNED_BEGIN (128)
126          typedef struct {
127             uint32_t flags;       /* Internal flags for the bson_t. */
128             uint32_t len;         /* Length of BSON data. */
129             uint8_t padding[120]; /* Padding for stack allocation. */
130          } bson_t BSON_ALIGNED_END (128);
131

DESCRIPTION

133       The bson_t structure represents a BSON document. This structure manages
134       the underlying BSON encoded  buffer.  For  mutable  documents,  it  can
135       append new data to the document.
136

PERFORMANCE NOTES

138       The  bson_t  structure  attempts to use an inline allocation within the
139       structure to speed up performance of small documents. When this  inter‐
140       nal  buffer has been exhausted, a heap allocated buffer will be dynami‐
141       cally allocated. Therefore, it is essential to call  bson_destroy()  on
142       allocated documents.
143

EXAMPLE

145          static void
146          create_on_heap (void)
147          {
148             bson_t *b = bson_new ();
149
150             BSON_APPEND_INT32 (b, "foo", 123);
151             BSON_APPEND_UTF8 (b, "bar", "foo");
152             BSON_APPEND_DOUBLE (b, "baz", 1.23f);
153
154             bson_destroy (b);
155          }
156

AUTHOR

158       MongoDB, Inc
159
161       2017-present, MongoDB, Inc
162
163
164
165
1661.14.0                           Feb 22, 2019                        BSON_T(3)
Impressum