.\" This manpage is Copyright (C) 2016 MongoDB, Inc. .\" .\" Permission is granted to copy, distribute and/or modify this document .\" under the terms of the GNU Free Documentation License, Version 1.3 .\" or any later version published by the Free Software Foundation; .\" with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. .\" A copy of the license is included in the section entitled "GNU .\" Free Documentation License". .\" .TH "BSON_WRITER_T" "3" "2016\(hy10\(hy12" "libbson" .SH NAME bson_writer_t \- Bulk BSON serialization Abstraction .SH "SYNOPSIS" .nf .nf #include typedef struct _bson_writer_t bson_writer_t; bson_writer_t *bson_writer_new (uint8_t **buf, size_t *buflen, size_t offset, bson_realloc_func realloc_func, void *realloc_func_ctx); void bson_writer_destroy (bson_writer_t *writer); .fi .fi .SH "DESCRIPTION" The .B bson_writer_t API provides an abstraction for serializing many BSON documents to a single memory region. The memory region may be dynamically allocated and re\(hyallocated as more memory is demanded. This can be useful when building network packets from a high\(hylevel language. For example, you can serialize a Python Dictionary directly to a single buffer destined for a TCP packet. .SH "EXAMPLE" .nf .nf #include int main (int argc, char *argv[]) { bson_writer_t *writer; uint8_t *buf = NULL; size_t buflen = 0; bson_t *doc; writer = bson_writer_new (&buf, &buflen, 0, bson_realloc_ctx, NULL); for (i = 0; i < 1000; i++) { bson_writer_begin (writer, &doc); BSON_APPEND_INT32 (&doc, "i", i); bson_writer_end (writer); } bson_writer_destroy (writer); bson_free (buf); return 0; } .fi .fi .B .SH COLOPHON This page is part of libbson. Please report any bugs at https://jira.mongodb.org/browse/CDRIVER.