BSON_ITER_BINARY(3)

πŸ’… BSON_ITER_BINARY(3) β€” like, the libbson girlies know ✨

okay so bestie, you're in the libbson corner of the universe and you need to pull the binary payload out of a BSON element? say less, this is literally the page for you 🫢


🌸 SYNOPSIS 🌸

#define BSON_ITER_HOLDS_BINARY(iter) \
   (bson_iter_type ((iter)) == BSON_TYPE_BINARY)

void
bson_iter_binary (const bson_iter_t *iter,
                  bson_subtype_t *subtype,
                  uint32_t *binary_len,
                  const uint8_t **binary);

πŸŽ€ PARAMETERS πŸŽ€

  • iter β€” a bson_iter_t. the iterator itself, the main character of this whole operation πŸ‘‘
  • subtype β€” a location to stash a bson_subtype_t, or NULL if you literally don't care. your call, no pressure πŸ’…
  • binary_len β€” a location for the length of binary. so you know how much data you're dealing with ✨
  • binary β€” a location for a pointer to the immutable buffer. that's where the data pointer gets dropped off πŸ¦‹

πŸ’– DESCRIPTION πŸ’–

so this function bson_iter_binary() shall return the binary data of a BSON_TYPE_BINARY element. periodt. that's the whole job and it ate πŸ”₯

ngl bestie, big warning: it is a programming error to call this on a field that is not of type BSON_TYPE_BINARY. like, do not do that. it's giving chaos 😭

you can vibe-check the type first with the BSON_ITER_HOLDS_BINARY() macro or with bson_iter_type(). use them, they're right there, they're iconic πŸ’œ

also super important: the buffer that binary points to is only valid until the iterator's bson_t is modified or freed. like it is not yours forever, it's a borrowed fit, return it to the universe 🧚

πŸ‘€ SEE ALSO πŸ‘€

  • bson_iter_binary_equal()
  • bson_iter_binary_subtype()

⭐ AUTHOR ⭐

MongoDB, Inc β€” the legends themselves 🫢

2009-present, MongoDB, Inc. β€” all the rights reserved, no cap πŸ“œ


πŸ’– and that's the whole page bestie! go forth and read those binary buffers responsibly, mwah πŸ’–

this lil dream was brought to you by libbson version 2.5.6, dated Oct 09, 2026 β€” see you in the next release, slay πŸŽ€βœ¨

πŸ“¦ where this page comes from