BSON_STEAL(3)
π BSON_STEAL(3) β the libbson glow-up transfer π
okay bestie, so this is page BSON_STEAL(3) from the libbson manual, and honestly? it's giving "give me your whole personality" but in a polite, memory-safe way. no cap. π¦
β¨ SYNOPSIS β¨
bool
bson_steal (bson_t *dst, bson_t *src);
that's it. that's the whole function signature. iconic. π
πΈ PARAMETERS πΈ
dstβ an uninitializedbson_t. like, it has to be a blank slate, a fresh-faced baby, nothing in it yet. π£srcβ abson_t. a real one. an actual filled-in bson document.
π DESCRIPTION π
the way that this function efficiently transfers the contents of src to dst and then destroys srcβ¦ obsessed. it's a full-on move-out, no forwarding address, src is gone. π
β οΈ okay so before you call this, listen up:srcmust be initialized anddstmust be uninitialized. that's the whole vibe check. after this function returns successfully,srcis destroyed, anddstis initialized and must be freed withbson_destroy(). don't forget that part, bestie, that's how you get leaks. π
for example β say you have a higher-level structure that wraps a bson_t, and you wanna use bson_steal to transfer BSON data into it. main character energy:
typedef struct {
bson_t bson;
} bson_wrapper_t;
bson_wrapper_t *
wrap_bson (bson_t *b)
{
bson_wrapper_t *wrapper = bson_malloc (sizeof (bson_wrapper_t));
if (bson_steal (&wrapper->bson, b)) {
return wrapper;
}
bson_free (wrapper);
return NULL;
}
void
bson_wrapper_destroy (bson_wrapper_t *wrapper)
{
bson_destroy (&wrapper->bson);
bson_free (wrapper);
}
int
main (int argc, char *argv[])
{
bson_t bson = BSON_INITIALIZER;
bson_wrapper_t *wrapper;
BSON_APPEND_UTF8 (&bson, "key", "value");
/* now "bson" is destroyed */
wrapper = wrap_bson (&bson);
/* clean up */
bson_wrapper_destroy (wrapper);
}
see how the comment literally says /* now "bson" is destroyed */? not me being dramatic, that's just the truth. π₯
π«Ά RETURNS π«Ά
returns true if src was successfully moved to dst. slay. π
returns false if src is invalid, or was statically initialized, or another error occurred. in that case, no move, no party. π
SEE ALSO:
bson_destroy_with_steal()β a lower-level function that returns the raw contents of abson_t. iykyk, this one's the deep lore. π
π AUTHOR π
MongoDB, Inc β yes, that MongoDB. royalty. π
β COPYRIGHT β
2009-present, MongoDB, Inc. β all rights reserved, all vibes reserved. π
and that's the whole page, bestie! π cute little sign-off for you: this was libbson version 2.5.6, dated Oct 09, 2026, and it lives at BSON_STEAL(3). go forth and steal (bson contents, legally) π§β¨
π¦ 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