1BSON_WRITER_T(3)                    libbson                   BSON_WRITER_T(3)
2
3
4
5Bulk BSON serialization Abstraction
6

SYNOPSIS

8          #include <bson/bson.h>
9
10          typedef struct _bson_writer_t bson_writer_t;
11
12          bson_writer_t *
13          bson_writer_new (uint8_t **buf,
14                           size_t *buflen,
15                           size_t offset,
16                           bson_realloc_func realloc_func,
17                           void *realloc_func_ctx);
18          void
19          bson_writer_destroy (bson_writer_t *writer);
20

DESCRIPTION

22       The bson_writer_t API provides an abstraction for serializing many BSON
23       documents to a single memory region. The memory region may  be  dynami‐
24       cally  allocated  and re-allocated as more memory is demanded. This can
25       be useful when building network packets from a high-level language. For
26       example,  you  can  serialize  a Python Dictionary directly to a single
27       buffer destined for a TCP packet.
28

EXAMPLE

30          #include <bson/bson.h>
31
32          int
33          main (int argc, char *argv[])
34          {
35             bson_writer_t *writer;
36             uint8_t *buf = NULL;
37             size_t buflen = 0;
38             bson_t *doc;
39
40             writer = bson_writer_new (&buf, &buflen, 0, bson_realloc_ctx, NULL);
41
42             for (i = 0; i < 1000; i++) {
43                bson_writer_begin (writer, &doc);
44                BSON_APPEND_INT32 (&doc, "i", i);
45                bson_writer_end (writer);
46             }
47
48             bson_writer_destroy (writer);
49
50             bson_free (buf);
51
52             return 0;
53          }
54

AUTHOR

56       MongoDB, Inc
57
59       2017-present, MongoDB, Inc
60
61
62
63
641.25.1                           Nov 08, 2023                 BSON_WRITER_T(3)
Impressum