BSON_NEW_FROM_DATA(3)
π BSON_NEW_FROM_DATA π
okay bestie, so this one is from libbson β the bson_new_from_data(3) page β and it's honestly pretty straightforward, so let's get into it β¨
πΈ SYNOPSIS πΈ
bson_t *
bson_new_from_data (const uint8_t *data, size_t length);
that's the whole signature, no cap. two args, one bson_t * coming back at you π«Ά
π PARAMETERS π
dataβ a BSON encoded document buffer. like, the actual bytes, sitting there in memory πlengthβ the length ofdatain bytes. the size, the count, the how-much π¦
β¨ DESCRIPTION β¨
so bson_new_from_data() shall create a new bson_t on the heap and copy the contents of data right into it. allocated on the heap, contents copied, all of it π
it "may be helpful when working with language bindings" β that's the intended vibe, iykyk β but ngl it's generally expected to be slower. the copy is doing copy things. it's giving convenient but not free π
π¨ important vibe check: it is an error iflengthdoes not match the length embedded in the first four bytes of the BSON data indata. like, those have to agree. the first four bytes ofdataliterally encode a length, and if yourlengthargument disagrees with it, that's an error. no negotiation on this one π₯
β RETURNS β
a newly allocated bson_t if successful β otherwise NULL. simple as that. slay when it works, NULL when it doesn't π
π AUTHOR π
MongoDB, Inc β they wrote it, we're thanking them π
π COPYRIGHT π
2009-present, MongoDB, Inc. β the full notice, untouched, as it should be π
so yeah, that's the whole page π§ memcpy energy, heap allocation energy, and one very specific error condition you should not sleep on. fr fr, make sure your length matches those first four bytes or it's not gonna be a good time π
later bestie, and happy BSON-ing!! π¦ π
β aka this is from libbson 2.5.6, dated Oct 09, 2026, and that's the whole sign-off β¨
π¦ 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