CTIO(3CTYPE)

πŸ“¦ version 4.6.6, in nixos 26.05, nixpkgs unstable

πŸŽ€ CTIO πŸ’… β€” the 3CTYPE manual, but make it make sense

okay bestie so listen: this is the ctype manual page, page CTIO(3CTYPE) if you're being ✨official✨ about it β€” it's literally just integer and float operations and honestly it's giving "I do one thing and I ate." No cap.


✨ NAME ✨

ctio, ruint8, ruint16, ruint32, ruint64, wuint8, wuint16, wuint32, wuint64, rsint8, rsint16, rsint32, rsint64, wsint8, wsint16, wsint32, wsint64, rfloat, rdouble, wfloat, wdouble β€” integer and float operations 🧚


🌸 SYNOPSIS 🌸

okay so first you gotta get the module:

var mod_ctype = require('ctype');

then the reads πŸ‘‡

Number mod_ctype.ruint8(Buffer buf, String endian, Number offset);

Number mod_ctype.ruint16(Buffer buf, String endian, Number offset);

Number mod_ctype.ruint32(Buffer buf, String endian, Number offset);

Number[2] mod_ctype.ruint64(Buffer buf, String endian, Number offset);

Number mod_ctype.rsint8(Buffer buf, String endian, Number offset);

Number mod_ctype.rsint16(Buffer buf, String endian, Number offset);

Number mod_ctype.rsint32(Buffer buf, String endian, Number offset);

Number[2] mod_ctype.rsint64(Buffer buf, String endian, Number offset);

Number mod_ctype.rfloat(Buffer buf, String endian, Number offset);

Number mod_ctype.rdouble(Buffer buf, String endian, Number offset);

and the writes πŸ‘‡ (notice the argument order flips, value comes first β€” lowkey iconic of it)

void mod_ctype.wuint8(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wuint16(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wuint32(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wuint64(Number[2] value, String endian, Buffer buf, Number offset);

void mod_ctype.wsint8(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wsint16(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wsint32(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wsint64(Number[2] value, String endian, Buffer buf, Number offset);

void mod_ctype.wfloat(Number value, String endian, Buffer buf, Number offset);

void mod_ctype.wdouble(Number value, String endian, Buffer buf, Number offset);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the deets, bestie, let's break down the arguments because they're literally the whole personality of this module πŸ’–

  • buf β€” this is a valid buffer, like the kind you get from calling new Buffer(). that's the vibe. that's where the bytes live.
  • endian β€” either the string 'big' or the string 'little' (nothing else, don't try it πŸ™ˆ). this controls whether the data in the buffer gets interpreted as big endian or little endian.
  • offset β€” the starting index into the buffer where you read or write. and like, all the functions make sure that starting at offset does not overflow the end of the buffer. safety first, we love a boundary check πŸ‘‘
  • value β€” a Number that is the valid type for the specific function. and every single function that takes value as an argument verifies that the passed value is valid. no clownery allowed πŸ’…

⭐ ruint8(), ruint16(), ruint32() ⭐

These three read an 8, 16, and 32-bit unsigned value from buf and return it. What you get back is influenced by the values of offset and endian. slay ✨


⭐ rsint8(), rsint16(), rsint32() ⭐

okay so the original text here literally says "The ruint8(), ruint16(), and ruint32() functions work just as ruint8(), ruint16(), and ruint32()" β€” bestie, that's a typo in the source doc, not me, I'm just the messenger 😭. The actual point: this section is about rsint8(), rsint16(), rsint32(), and they work just like their unsigned siblings except they return signed integers. that's it, that's the tea πŸ“


⭐ ruint64(), rsint64() ⭐

ruint64() and rsint64() read unsigned and signed 64-bit integers respectively from buf. Here's the situation though β€” due to the limitations of ECMAScript's Number type, they cannot be stored as one value without a loss of precision. so instead of returning the values as a single Number, these functions return an array of two numbers πŸ’€

  • the first entry always contains the upper 32-bits
  • the second value contains the lower 32-bits

The lossy transformation into a number would be:

res[0]*Math.pow(2,32)+res[1]
Note that, unless an entry is zero, both array entries are guaranteed to have the same sign. so like, don't panic, the signs are matching, that's the whole point 🫢

⭐ wuint8(), wuint16(), wuint32() ⭐

These bad boys modify the contents of buf by writing an 8, 16, and 32-bit unsigned integer respectively to buf. It is illegal to pass a number that is not an integer within the domain of the integer size β€” for example, for wuint8() the valid range is [0, 255]. no cap, do not test this one πŸ™ˆ

The value gets written in either big or little endian format based upon the value of endian.


⭐ wsint8(), wsint16(), wsint32() ⭐

These function identically to wuint8(), wuint16(), and wuint32() except that the valid domain for value is that of a signed number instead of an unsigned number. For example wsint8() has a domain of [-128, 127]. negative girlies finally get to write 🌈


⭐ wuint64(), wsint64() ⭐

wuint64() and swint64() write out 64-bit unsigned and signed integers to buf. (yes, the prose text says swint64() there β€” another little typo gremlin in the original, the section's about wuint64() and wsint64() πŸ’…)

The value argument must be in the same format as described in ruint64() and rsint64() β€” so, the two-element array situation. πŸ’–


⭐ rfloat(), rdouble() ⭐

The functions "rfloat() and rdouble()" work like the other read functions, except that they read a single precision and double precision IEEE-754 floating point value instead. floating point! fancy! πŸ”₯


⭐ wfloat(), wdouble() ⭐

The functions "rfloat() and rdouble()" work like the other write functions (yep, the original prose names the read functions here too, quoting it exactly because I'm not out here fixing the source 😭), except that:

  • the domain for a float is that of a single precision 4 byte value
  • the domain for a double is any Number in ECMAScript, which is defined to be represented by a double

πŸ‘‘ ATTRIBUTES πŸ‘‘

See attributes(5) for descriptions of the following attributes:

  • ATTRIBUTE TYPE: Interface Stability β€” ATTRIBUTE VALUE: Committed
  • ATTRIBUTE TYPE: MT-Level β€” ATTRIBUTE VALUE: See below.
  • ATTRIBUTE TYPE: Standard β€” ATTRIBUTE VALUE: Not standardized.

and here's the "see below" βœ… β€” all functions are MT-safe in so far as there aren't shared memory MT concerns in most node programs. If one were to concoct such an environment, these functions wouldn't be MT-safe. so like, don't concoct that environment, bestie πŸ’€


πŸ’œ SEE ALSO πŸ’œ

this section is literally sitting here empty in the source β€” no references listed, nothing to link, an absolute main character of a blank space. so uh. yeah. that's the whole bit. πŸŽ€


ok that's the page!! written by the 3CTYPE girlies on December 12, 2011 β€” yep, 2011, she's been iconic since before some of y'all were even on the internet πŸ˜­πŸ’– periodt. now go read some buffers responsibly πŸ¦‹πŸŒΈ
πŸ“¦ where this page comes from