BSON_STRING_T(3)
π BSON_STRING_T π
okay bestie, welcome to bson_string_t, straight outta the libbson manual, section 3. this one's the string-building girlie of the BSON world and she is literally so useful β just mind the warning below first, mwah π
β οΈ WARNING β οΈ
Deprecated since version 1.29.0. π bestie she's been retired. still iconic, still documented, but likeβ¦ she's in her legacy era. no cap.
π§΅ String Building Abstraction
β¨ SYNOPSIS β¨
#include <bson/bson.h>
typedef struct {
char *str;
uint32_t len;
uint32_t alloc;
} bson_string_t;
πΈ DESCRIPTION πΈ
okay so bson_string_t is an abstraction for building strings β like, the whole point is you just keep slapping chunks onto it and it handles the growing for you. and the way it grows?? allocations are performed in powers of two β¨ 2, 4, 8, 16β¦ she's doubling, she's thriving, she's not doing a million tiny reallocs like some clown.
and this API is the move if you need to build UTF-8 encoded strings. fr fr. that's the vibe. π
π¦ EXAMPLE π¦
here's her in action, main character energy:
bson_string_t *str;
str = bson_string_new (NULL);
bson_string_append_printf (str, "%d %s %f\n", 0, "some string", 0.123);
printf ("%s\n", str->str);
bson_string_free (str, true);
π TIP π
okay so here's the lil secret: you can call bson_string_free() with false if you would like to take ownership of str->str π some APIs that do this might legit just
return bson_string_free (str, false);
after building the string. so the string survives the free, you keep the goods, and nobody gets hurt. iykyk. π§
π AUTHOR π
MongoDB, Inc β yeah, the MongoDB girlies wrote her. legends only. π«Ά
π COPYRIGHT π
2009-present, MongoDB, Inc. β all the rights, all the years, all the respect. β¨
and that's a wrap bestie!! this page came to you from libbson, version 1.30.13, dated Oct 09, 2026 π go build some strings (just maybe not with this one, she's deprecated, ok ily bye) ππ¦β¨
π¦ where this page comes from
- fedora 43: libbson-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- fedora 43: libbson-devel 1.30.13-1.fc43 Β· Apache-2.0 AND ISC AND MIT AND Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms