BSON_ITER_INIT...DATA_AT_OFFSET(3)

πŸ’… BSON_ITER_INIT...DATA_AT_OFFSET(3) πŸ’…

okay so bestie, welcome to the libbson manual page for BSON_ITER_INIT...DATA_AT_OFFSET(3) β€” yes, the whole glamorous crew of iteration-starting behavior is here, and no cap, it's lowkey iconic. πŸŽ€βœ¨


🌸 SYNOPSIS 🌸

          bool
          bson_iter_init_from_data_at_offset (bson_iter_t *iter,
                                              const uint8_t *data,
                                              size_t length,
                                              uint32_t offset,
                                              uint32_t keylen);

πŸŽ€ PARAMETERS πŸŽ€

  • iter β€” a bson_iter_t. That's the little iterator baddie getting initialized. πŸ’…
  • data β€” a buffer to initialize with. This is not validated, bestie β€” fr fr, no vibe check happens here.
  • length β€” the length of data in bytes. This is not validated. 😭
  • offset β€” the offset of the field to start iterating. This is not validated. This should be an offset previously obtained from bson_iter_offset(). 🫢
  • keylen β€” the string length of the key of the field to start iterating. This is not validated. This should be a length previously obtained from bson_iter_key_len(). ✨

πŸ’– DESCRIPTION πŸ’–

Creates a bson_iter_t and starts iteration on a field at the offset. It's giving "fresh iterator, who dis" and honestly? Obsessed. πŸ¦‹

bson_iter_init_from_data_at_offset() is useful for situations where the progress of a bson_iter_t must be saved and restored without relying on the bson_iter_t data layout. That's the main character move here. πŸ‘‘

Saving the progress could be accomplished by:

  • Saving the current field's key length with bson_iter_key_len()
  • Saving the current offset with bson_iter_offset()
  • Saving the data pointer of the iterated bson_t with bson_get_data()
  • Saving the data length of the iterated bson_t with the len struct field

Then later, these saved values can be passed to bson_iter_init_from_data_at_offset() to reconstruct the bson_iter_t in constant time. Literally the save-and-restore slay. πŸ’–


✨ RETURNS ✨

Returns true if the iter was successfully initialized. That's it, that's the return. 🌟

πŸ‘‘ SEE ALSO πŸ‘‘

  • bson_iter_key_len()
  • bson_iter_offset()
  • bson_get_data()

🫢 AUTHOR 🫢

MongoDB, Inc


2009-present, MongoDB, Inc.


okay that's the whole page, bestie β€” libbson version 2.5.6, dated Oct 09, 202, and yes, that's exactly what the footer says πŸ’œβœ¨

πŸ“¦ where this page comes from