BSON_DESTROY_WITH_STEAL(3)

πŸ’… bson_destroy_with_steal πŸ’…

okay so bestie, welcome to the libbson corner of the manual β€” this one's a libbson page, section 3, and it's literally about yeeting a bson_t while keeping its insides. iconic behavior honestly πŸŽ€


✨ SYNOPSIS ✨

uint8_t *
bson_destroy_with_steal (bson_t *bson, bool steal, uint32_t *length);

that's the whole signature, no cap 🫢


🌸 PARAMETERS 🌸

  • bson β€” a bson_t. the main character of this whole situation πŸ‘‘
  • steal β€” a bool that says whether the underlying buffer should be stolen. yes, stolen. we're doing a heist πŸ’…
  • length β€” a location where the resulting buffer length gets stashed πŸ“

πŸ¦‹ DESCRIPTION πŸ¦‹

so bson_destroy_with_steal() shall destroy a bson_t structure β€” but instead of freeing the underlying buffer, it hands it back to you. like, the bson dies, the buffer lives, it's giving resurrection arc ✨

if steal is false, then honestly this is just equivalent to calling bson_destroy(). no buffer, no heist, nothing stolen. shrug πŸ™ˆ

⚠️ okay this part is important, fr fr: it is a programming error to call this function on a bson_t that is not a top-level bson_t β€” like the ones you get from bson_append_document_begin(), bson_append_array_begin(), and bson_writer_begin(). do not do that. i'm begging 🫢

πŸ’– RETURNS πŸ’–

bson_destroy_with_steal() shall return a buffer holding the contents of the bson_t if steal is non-zero. and when you're done with it, free it with bson_free() β€” that's the cleanup era, we love a responsible queen 🧚

length will be set to the length of the bson document if it's non-NULL. if it's NULL? then it just doesn't get set, periodt πŸ’…

πŸ’« SEE ALSO πŸ’«

  • bson_steal() β€” a higher-level function that efficiently transfers the contents of one bson_t to another. lowkey the upgraded version of this vibe ✨

πŸ“ AUTHOR πŸ“

MongoDB, Inc β€” the ones who wrote all this, we stan 🌈


2009-present, MongoDB, Inc.


and that's the page!! πŸ’œ this was libbson 2.5.6, dated Oct 09, 2026, page BSON_DESTROY_WITH_STEAL(3) β€” go forth and steal those buffers responsibly, bestie πŸŽ€πŸ”₯

πŸ“¦ where this page comes from