SDL_ReadU16BE(3)

πŸ’– SDL_ReadU16BE(3) πŸ’–

okay bestie, so this one lives in the SDL3 FUNCTIONS crew, and it's genuinely so useful. Let me put you on. 🫢


✨ NAME ✨

SDL_ReadU16BE β€” use this function to read 16 bits of big-endian data from an SDL_IOStream and return in native format. no cap, that's literally what it does. 🌸


✨ SYNOPSIS ✨

#include <SDL3/SDL_iostream.h>

bool SDL_ReadU16BE(SDL_IOStream *src, Uint16 *value);

✨ DESCRIPTION ✨

okay so here's the tea β˜•: SDL byteswaps the data only if necessary, so the data returned will be in the native byte order. it's giving considerate. it's giving thoughtful. it checks before it wrecks. πŸ’…

this function will return false when the data stream is completely read, and SDL_GetIOStatus() will return SDL_IO_STATUS_EOF. so like, that's your signal that you hit the end, bestie, nothing more to give. πŸŽ€

but wait β€” if false is returned and the stream is not at EOF, then SDL_GetIOStatus() will return a different error value, and SDL_GetError() will offer a human-readable message. so basically: false can mean two different things and you gotta check the status to know which. don't skip the vibe check. πŸ‘‘


✨ FUNCTION PARAMETERS ✨

  • src β€” the stream from which to read data. your source, your origin story, the main character of the read. πŸ¦‹
  • value β€” a pointer filled in with the data read. it gets the goods. ✨

✨ RETURN VALUE ✨

returns true on successful read, or false on failure. 🫠

if it's failing, call SDL_GetError() for more information β€” it will literally tell you what went wrong in actual human words. iconic of it, honestly. πŸ’–


✨ THREAD SAFETY ✨

do not use the same SDL_IOStream from two threads at once. 🚨

like, absolutely not. that's not the move. that's a whole mess. one stream, one thread, periodt. πŸ’€


✨ AVAILABILITY ✨

this function is available since SDL 3.2.0. so if you're on anything older, sorry babe, it's not there yet. 🌈


and that's the whole page, bestie β€” every flag, every pointer, every SDL_IO_STATUS_EOF, preserved with love. πŸ’œ

Simple Directmedia Layer 🌸 SDL 3.4.18 🌸 SDL_ReadU16BE(3) β€” mwah, sending you a kiss, go read some big-endian bytes responsibly. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from