MTBL_FIXED(3)

πŸ’– MTBL_FIXED(3) πŸ’–

okay bestie, welcome to the mtbl_fixed page from the MTBL_FIXED(3) manual β€” it's short, it's sweet, it's literally just little-endian integers going in and out of buffers, and we're gonna get you fluent in it in like ninety seconds. periodt. πŸŽ€


✨ NAME ✨

mtbl_fixed β€” fixed-width encoding and decoding of 32 and 64 bit integers πŸ¦‹


🌸 SYNOPSIS 🌸

#include <mtbl.h>

size_t mtbl_fixed_encode32(uint8_t *dst, uint32_t value);

size_t mtbl_fixed_encode64(uint8_t *dst, uint64_t value);

uint32_t mtbl_fixed_decode32(const uint8_t *ptr);

uint64_t mtbl_fixed_decode64(const uint8_t *ptr);

πŸ‘‘ DESCRIPTION πŸ‘‘

mtbl_fixed_encode32() and mtbl_fixed_encode64() take the 32 or 64 bit quantity respectively that lives in the argument value, and they write it straight into the buffer you handed over as the argument dst. πŸ’…

and the way that they write it? little endian order, no matter what your host architecture is doing. like, your machine can have whatever opinions it wants, this function is not asking. it's little endian. periodt. πŸ”₯

mtbl_fixed_decode32() and mtbl_fixed_decode64() are the reverse glow-up: they read the 32 or 64 bit quantity respectively out of the argument ptr, and they return it to you. 🌈

and yes, same energy β€” the quantity gets read in little endian order, regardless of host architecture. no cap. ⭐

🚨 okay real talk for one sec bestie: bounds checking must be performed by the caller. these functions are not your babysitter, they will not check that dst or ptr actually points at enough bytes. that's on you. do not skip this. i'm serious. 😭

πŸ’€ RETURN VALUE πŸ’€

  • mtbl_fixed_encode32() and mtbl_fixed_encode64() return the number of bytes written to the buffer β€” that's 4 or 8, respectively. icon behavior, honestly. ✨
  • mtbl_fixed_decode32() and mtbl_fixed_decode64() return the decoded quantity. the actual number. the main character. πŸ‘‘

🫢 lowkey the whole vibe of this page is "tiny little byte-shufflers that always go little endian and trust you to not overflow your own buffer." ate. no notes. πŸ“

and that's the whole page, babe! this was the MTBL_FIXED(3) manual, dated 01/31/2014 β€” go forth and encode responsibly πŸ’œπŸ§š