BSON_APPEND_VE...AT32_FROM_ARRAY(3)
π 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β abson_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 ofkeyin bytes, or-1if you want it to just figure the length out withstrlen(). lazy girl math, but sanctioned β¨iterβ abson_iter_treferencing the array elements that will be converted π§errorβ optionalbson_error_tfor 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 provideditermust be positioned just prior to the first element of the BSON Array. so if your input is a bare BSON Array, set upiterusingbson_iter_init(). if the input is chillin' inside a document field, usebson_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 π
π COPYRIGHT π
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
- 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