BSON_INIT_STATIC(3)
π BSON_INIT_STATIC(3) β the libbson one, bestie π
Okay so picture this: it's a libbson manual page, it's about bson_init_static, and it's literally the β¨ zero-copy β¨ girlie of the initialize-the-bson family. Let's get into it π«Ά
β¨ SYNOPSIS β¨
bool
bson_init_static (bson_t *b, const uint8_t *data, size_t length);
That's the whole vibe check: it hands you back a bool, takes a bson_t *, a const uint8_t *, and a size_t. Clean. Iconic. No notes π
π§ PARAMETERS π§
bβ abson_t. Yeah. That one. The thing you're initializing. π€dataβ a buffer to initialize with. This is the raw BSON bytes, the moment, the main character.lengthβ the length ofdatain bytes. Count 'em. Don't lie to me about 'em. π₯
π¦ DESCRIPTION π¦
So bson_init_static() shall initialize a read-only bson_t on the stack, using the data you provided. And here's the part where I need you to lean in, bestie: no copies of the data will be made. π«’ None. Zero. Therefore the data must remain valid for the lifetime of the bson_t. Like, the whole lifetime. Not just the cute part. If you free that buffer while the bson_t is still out here living its life, that's on you and it is not going to be a slay π
The resulting bson_t has internal references and therefore must not be copied β because copying it would leave dangling pointers in the copy. So do not copy it. I'm so serious. π
And one more thing: it is an error if length does not match the length embedded in the first four bytes of the BSON data in data. The first four bytes said one thing, you said another, and now we're in our error era. β οΈ They have to match. Periodt.
π¨ Recap for the girlies in the back: read-only, stack-allocated, zero copies, buffer stays alive forever, no copying thebson_t, andlengthhas to agree with those first four bytes. Do all that and you ate. π
π RETURNS π
Returns true if the bson_t was successfully initialized, otherwise false. The function can fail if data or length are invalid. So like, check the return value. Be a responsible icon. π
π AUTHOR π
MongoDB, Inc β yes, that MongoDB. Authors of the whole libbson situation. Respect. π«‘
πΈ COPYRIGHT πΈ
2009-present, MongoDB, Inc. β the full run, no gaps, we love a consistent queen.
π And that's the page!! Written by your girl for libbson 2.5.6, dated Oct 09, 2026 β mwah, go forth and initialize statically, bestie, and remember: don't copy the bson_t πβ¨
π¦ 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