![]() |
![]()
| ![]() |
![]()
SYNOPSISuint8_t * bson_reserve_buffer (bson_t *bson, uint32_t total_size); PARAMETERS
DESCRIPTIONGrow the internal buffer of bson to total_size and set the document length to total_size. Useful for eliminating copies when reading BSON bytes from a stream. First, initialize bson with bson_init() or bson_new(), then call this function. After it returns, the length of bson is set to total_size but its contents are uninitialized memory: you must fill the contents with a BSON document of the correct length before any other operations. The document must be freed with bson_destroy(). Note that, in this usage, the BSON header and footer bytes will not be verified or used by Libbson. The bson_t document length and buffer size limit are both set to total_size regardless of the value encoded in the document header. RETURNSA pointer to the internal buffer, which is at least total_size bytes, or NULL if the space could not be allocated. EXAMPLEUse bson_reserve_buffer to write a function that takes a bson_t pointer and reads a file into it directly: #include <stdio.h> #include <bson/bson.h> bool read_into (bson_t *bson, FILE *fp) { AUTHORMongoDB, Inc COPYRIGHT2009-present, MongoDB, Inc.
|