BSON_NEW_FROM_BUFFER(3)
π BSON_NEW_FROM_BUFFER(3) π
okay bestie, welcome to the libbson corner of the manual β this one's the bson_new_from_buffer page and honestly it's giving "wrap your existing buffer in a shiny new bson_t" energy β¨
β¨ SYNOPSIS β¨
bson_t *
bson_new_from_buffer (uint8_t **buf,
size_t *buf_len,
bson_realloc_func realloc_func,
void *realloc_func_ctx);
π PARAMETERS π
bufβ an out-pointer pointing at a buffer that's holding a serialized BSON document, or it points atNULL. yep, either situation is legal, she's flexible πbuf_lenβ an out-pointer to how long that buffer is, in bytes πrealloc_funcβ optionalbson_realloc_functhat gets used for reallocating the buffer. optional!! but iconic when you bring it π«Άrealloc_func_ctxβ optional pointer that'll be handed torealloc_funcas thectxargument
π¦ DESCRIPTION π¦
So basically: this function creates a brand-new bson_t out of the data you already have. no copying drama, just vibes πΈ
The realloc_func, if you provide it, gets called to resize buf whenever the document later gets expanded β like, say, when you call one of the bson_append functions. she grows, she calls your allocator, that's the whole deal β¨
If *buf starts out as NULL, then it gets allocated (using realloc_func, or the default allocator if you didn't pass one) and initialized with an empty BSON document. and then *buf_len is set to 5 β yup, 5, that's literally the size of an empty document, no cap π₯
If *buf is initially non-NULL, then *buf_len must be at least as large as the embedded length sitting in the first four bytes of the BSON data in *buf β but it's totally fine if it's bigger than that. any leftover buffer capacity can be used later to grow the BSON document. room to grow = main character energy π
lowkey important: that "at least as large as" bit is a real requirement, not a suggestion. the embedded length in the first four bytes is the vibe check your buffer has to pass π
β RETURNS β
A newly-allocated bson_t if everything slayed, or NULL if it didn't π
π AUTHOR π
MongoDB, Inc β love them for this fr fr π
π§ COPYRIGHT π§
2009-present, MongoDB, Inc.
and that's the whole page, bestie π this was BSON_NEW_FROM_BUFFER(3) from the libbson manual, version 2.5.6, dated Oct 09, 2026 β go forth and wrap those buffers ππ
π¦ where this page comes from
- epel 10: libbson-devel 2.5.6-1.el10_3 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms