1BSON_WRITER_T(3) libbson BSON_WRITER_T(3)
2
3
4
6 bson_writer_t - bson_writer_t
7
8 Bulk BSON serialization Abstraction
9
11 #include <bson/bson.h>
12
13 typedef struct _bson_writer_t bson_writer_t;
14
15 bson_writer_t *
16 bson_writer_new (uint8_t **buf,
17 size_t *buflen,
18 size_t offset,
19 bson_realloc_func realloc_func,
20 void *realloc_func_ctx);
21 void
22 bson_writer_destroy (bson_writer_t *writer);
23
25 The bson_writer_t API provides an abstraction for serializing many BSON
26 documents to a single memory region. The memory region may be dynami‐
27 cally allocated and re-allocated as more memory is demanded. This can
28 be useful when building network packets from a high-level language. For
29 example, you can serialize a Python Dictionary directly to a single
30 buffer destined for a TCP packet.
31
33 #include <bson/bson.h>
34
35 int
36 main (int argc, char *argv[])
37 {
38 bson_writer_t *writer;
39 uint8_t *buf = NULL;
40 size_t buflen = 0;
41 bson_t *doc;
42
43 writer = bson_writer_new (&buf, &buflen, 0, bson_realloc_ctx, NULL);
44
45 for (i = 0; i < 1000; i++) {
46 bson_writer_begin (writer, &doc);
47 BSON_APPEND_INT32 (&doc, "i", i);
48 bson_writer_end (writer);
49 }
50
51 bson_writer_destroy (writer);
52
53 bson_free (buf);
54
55 return 0;
56 }
57
59 MongoDB, Inc
60
62 2017-present, MongoDB, Inc
63
64
65
66
671.17.6 Jun 03, 2021 BSON_WRITER_T(3)