BSON_APPEND_DECIMAL128(3)

πŸ’… BSON_APPEND_DECIMAL128 β€” bestie's guide to the libbson decimal128 append

okay so real talk, this is a page from libbson (the BSON_APPEND_DECIMAL128(3) one, yes that's the whole title, we're doing this) and honestly? it's a little baby page. one function, one macro, four params, zero drama. let's get into it ✨


✨ SYNOPSIS ✨

here's the whole vibe, copy it exactly bestie:

#define BSON_APPEND_DECIMAL128(b, key, val) \
   bson_append_decimal128 (b, key, (int) strlen (key), val)

bool
bson_append_decimal128 (bson_t *bson,
                        const char *key,
                        int key_length,
                        const bson_decimal128_t *value);

so you got a macro up top that's just a lil shortcut β€” it calls the real function and does the strlen (key) thing for you so you don't have to 🫢 and then the actual function signature underneath, returning a bool like the good little truth-teller it is.


🌸 PARAMETERS 🌸

  • bson β€” a bson_t. it's the document, it's the moment, it's the main character. you're appending into this one πŸ’–
  • key β€” an ASCII C string with the name of the field. yes, ASCII. keep it simple, keep it iconic.
  • key_length β€” the length of key in bytes. ORRR you can be lazy (affectionate) and pass -1 to let it figure the length out with strlen() ✨
  • value β€” a bson_decimal128_t. that's the thing you're shoving in there.

πŸ¦‹ DESCRIPTION πŸ¦‹

so the bson_append_decimal128() function shall append a new element to bson containing a Decimal 128. that's it. that's the whole job. it does one thing and it slays at it πŸ’… no cap, no hidden features, no secret lore.


πŸŽ€ RETURNS πŸŽ€

returns true if the operation was applied successfully β€” we love a success story πŸ₯³

⚠️ but heads up bestie: the function will fail if appending value grows bson larger than INT32_MAX. so if your doc is already living its best absolute unit life, this is where it taps out. not a vibe, just facts 😭

πŸ‘‘ AUTHOR πŸ‘‘

MongoDB, Inc β€” the ones who brought you this whole situation 🫢


2009-present, MongoDB, Inc. β€” periodt, that's the legal bit, we respect it.


🧚 and that's the tea! go forth and append your decimals, you absolute icon ⭐

libbson version 2.5.6, dated Oct 09, 2026 β€” that's when this gem got its timestamp, and honestly? she's timeless πŸ’œ bye bestie!! πŸ“

πŸ“¦ where this page comes from