BSON_ITER_UTF8(3)
π BSON_ITER_UTF8 (3) β a libbson moment
ok so bestie, this is the page for bson_iter_utf8 from libbson, and it's honestly not that deep β it just grabs a string out of your BSON iterator. but there are β¨rulesβ¨ and we're gonna respect them. let's go π
β¨ SYNOPSIS β¨
the whole thing, verbatim, no cap:
#define BSON_ITER_HOLDS_UTF8(iter) (bson_iter_type ((iter)) == BSON_TYPE_UTF8)
const char *
bson_iter_utf8 (const bson_iter_t *iter, uint32_t *length);
so you've got a cute lil macro that tells you "hey, is this thing a UTF-8 string?" and then the actual function that hands you the goods. π«Ά
πΈ PARAMETERS πΈ
iterβ abson_iter_t. your iterator. the main character. π«lengthβ an optional spot to stash the length of the resulting UTF-8 encoded string. optional bestie, so you can literally pass nothing if you don't care. π
π DESCRIPTION π
bson_iter_utf8() retrieves the contents of a BSON_TYPE_UTF8 element that iter is currently looking at. that's it. that's the vibe check. β
π¨ BUT β it is invalid to call this function while your iterator is observing an element that is not BSON_TYPE_UTF8. like, do not do that. it's giving "reading the wrong file" energy and the function will not be happy. π
that's why BSON_ITER_HOLDS_UTF8 exists up in the synopsis β check first, slay after. π
π₯ RETURNS π₯
you get back a UTF-8 encoded string β not modified, not freed. it's a borrowed string, so don't go freeing it yourself, that's not your job. π
it is suggested that you validate the content is actually valid UTF-8 before using it elsewhere. nobody's forcing you, but likeβ¦ it's a good idea, iykyk. you can do that by calling bson_utf8_validate(), or by validating the underlying bson_t before you even start iterating it. two paths, both valid. π
β οΈ heads up: not all drivers use multi-byte representation for\0in UTF-8 encodings β this is commonly referred to as modified-UTF8 β so you probably wanna take a look at thelengthfield when you're marshaling to other runtimes. like, actually look at it. don't just assume. π
π AUTHOR π
MongoDB, Inc β yes, the whole company. iconic. π
π¦ COPYRIGHT π¦
2009-present, MongoDB, Inc. β that's a long run fr fr, respect. πΈ
and that's the page bestie!! this was libbson 2.5.6, dated Oct 09, 2026 β go forth and iterate responsibly π β¨π
π¦ 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