BSON_APPEND_VE...AT32_FROM_ARRAY(3)

πŸ“¦
version 2.5.6 Β· 3 versions
, in epel 10

πŸ’… BSON_APPEND_VE...AT32_FROM_ARRAY πŸ’…

okay so bestie, this is a libbson page β€” yes the title is literally truncated with ... in the middle, that's just how the header renders, don't panic 🫢 β€” and it's all about turning a BSON Array into a Vector of float32 elements. no cap, it's a niche little function but she's iconic at what she does ✨


🌸 SYNOPSIS 🌸

first up, the ✨glamorous✨ macro wrapper, and then the real function underneath her:

#define BSON_APPEND_VECTOR_FLOAT32_FROM_ARRAY(b, key, iter, err) \
   bson_append_vector_float32_from_array (b, key, (int) strlen (key), iter, err)

bool
bson_append_vector_float32_from_array (bson_t *bson,
                                       const char *key,
                                       int key_length,
                                       const bson_iter_t *iter,
                                       bson_error_t *error);

notice how the macro handles the strlen (key) for you and casts it to (int)? she's doing the boring math so you don't have to πŸ’–


πŸŽ€ PARAMETERS πŸŽ€

every single one, no skipping, i got you:

  • bson β€” a bson_t. the document getting the new field, main character energy πŸ‘‘
  • key β€” an ASCII C string holding the name of the field. keep it ASCII, bestie, that's the spec πŸ¦‹
  • key_length β€” the length of key in bytes, or -1 if you want it to just figure the length out with strlen(). lazy girl math, but sanctioned ✨
  • iter β€” a bson_iter_t referencing the array elements that will be converted 🧚
  • error β€” optional bson_error_t for the tea on conversion failures. optional, so you can totally skip it, but then you get no details if it flops πŸ™ˆ

πŸ’œ DESCRIPTION πŸ’œ

so what she does: appends a new field to bson by converting an Array to a Vector of float32 elements. that's the whole gig. and the way she does it? flawless πŸ’…

for the conversion to actually succeed, every single item in the Array has to be a double-precision floating point number β€” that's BSON_TYPE_DOUBLE, write it down πŸ“. one wrong type in there and the vibe check fails, fr fr.

now the important part, don't skip this:

the provided iter must be positioned just prior to the first element of the BSON Array. so if your input is a bare BSON Array, set up iter using bson_iter_init(). if the input is chillin' inside a document field, use bson_iter_recurse() instead. two different setups, pick the right one 😭

⭐ RETURNS ⭐

returns true if the operation was applied successfully β€” slay πŸŽ‰

on error it returns false and writes additional error info to error without modifying bson. so your document stays untouched, she's very polite about it 🫢. and that error? it'll have a domain of BSON_ERROR_VECTOR and a code from bson_vector_error_code_t, iykyk πŸ”₯


🌈 AUTHOR 🌈

MongoDB, Inc β€” yeah, them. the whole squad πŸ’€


2009-present, MongoDB, Inc. β€” iconic longevity, we love to see it πŸ‘‘


and that's the page, bestie!! the footer says this is libbson version 2.5.6, dated Oct 09, 20 (yes it literally cuts off mid-year in the footer, the truncation goblin got that one too πŸ˜­πŸ’€), so go forth and append those float32 vectors responsibly πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from