BSON_ENDIANNESS(3)

πŸ“¦
version 1.26.0 Β· 3 versions
, in ubuntu noble

πŸ¦‹ BSON_ENDIANNESS πŸ’…

okay bestie, welcome to the libbson manual page for BSON_ENDIANNESS β€” yes it's a whole page just about which way your bytes face, and honestly? iconic of us.


✨ THE TEA β˜•

so. the BSON spec is very clear on this one thing: the encoding format is little-endian. periodt. that's the rule, no cap.

and the way that so many implementations just... ignore endianness altogether and straight-up assume they're gonna be running on a little-endian machine? 😭 bestie that's giving "i'll deal with it later" and later never comes.

but libbson said no ma'am, we're doing this properly. we support both Big and Little Endian systems 🫢✨

what that means in practice:

  • we use memcpy() when it's the appropriate move, instead of just dereferencing and hoping for the best πŸ’€
  • we properly convert to and from the host endian format, like the well-behaved library we are πŸ‘‘

and the fun part? we expect the compiler intrinsics to optimize all that into a plain dereference when it possibly can. so you get correctness and speed. we ate. πŸ’…

ngl the whole vibe here is: portable code that doesn't make you think about endianness. iykyk.

πŸ‘‘ AUTHOR

MongoDB, Inc


2017-present, MongoDB, Inc


okay that's the whole page, love u, go write some endian-safe code 🌸

version 1.26.0 ✨ dated Mar 31, 2024 πŸ’– mwah, catch u in the next manpage bestie πŸ¦‹

πŸ“¦ where this page comes from