⌂ Modules Module: nupp Module: nupp.bytes Module: nupp.bytes
Typed binary reads and writes over a string.buffer.Buffer.
A Buffer already moves raw bytes with put/get and reserve/commit/ref; Reader and Writer add the missing piece, a sized integer or float landing on those bytes without hand-rolling the ffi.cast each time.
Both read and write host-endian, the same as every other cast in this codebase (nupp.compiler.build.hash): LuaJIT itself only ships little-endian, so that is the honest default. A format that has to be byte-order-fixed casts and swaps explicitly; this module carries no LE/BE variants until something needs one.
A short read raises, matching Buffer:get. Buffer:skip is the one method that clamps instead of raising, and Reader does not inherit that.
Module contents Constructors Constructor Description newReaderWraps data for typed reads. newWriterWraps buf for typed writes, or starts a fresh buffer when omitted.
Types Type Kind Description Readerrecord A cursor for typed reads over a buffer's unconsumed data. Writerrecord A cursor for typed writes, appending to a buffer.
Functions
Constructors
bytes.newReaderconstructor
Wraps data for typed reads.
A string is copied into a fresh buffer. Passing an existing buffer instead lets a caller mix buf:get(...) and reader:readInt32() over the same bytes.
Arguments Name Type Description datastring | string . buffer . Buffer the bytes to read, or the buffer to read from
Returns Type Description bytes . Reader the reader
bytes.newWriterconstructor
Wraps buf for typed writes, or starts a fresh buffer when omitted.
Arguments Name Type Description bufstring . buffer . Buffer ? the buffer to append to
Returns Type Description bytes . Writer the writer
Types
Readerrecord
A cursor for typed reads over a buffer's unconsumed data. Consumes as it reads, the same direction as Buffer:get.
Fields Name Type Description bufstring . buffer . Buffer
Writerrecord
A cursor for typed writes, appending to a buffer.
Fields Name Type Description bufstring . buffer . Buffer
Functions
bytes.Reader:readBytesmethod
Reads n raw bytes. Raises if fewer remain.
function bytes . Reader : readBytes ( n : integer ) : string
Arguments Name Type Description ninteger
Returns
bytes.Reader:readFloat32method
Reads a host-endian 32-bit float.
function bytes . Reader : readFloat32 ( ) : float
Returns
bytes.Reader:readFloat64method
Reads a host-endian 64-bit float.
function bytes . Reader : readFloat64 ( ) : number
Returns
bytes.Reader:readInt16method
Reads a host-endian signed 16-bit integer.
function bytes . Reader : readInt16 ( ) : int16
Returns
bytes.Reader:readInt32method
Reads a host-endian signed 32-bit integer.
function bytes . Reader : readInt32 ( ) : int32
Returns
bytes.Reader:readInt64method
Reads a host-endian signed 64-bit integer.
function bytes . Reader : readInt64 ( ) : int64
Returns
bytes.Reader:readInt8method
Reads one signed byte.
function bytes . Reader : readInt8 ( ) : int8
Returns
bytes.Reader:readUint16method
Reads a host-endian unsigned 16-bit integer.
function bytes . Reader : readUint16 ( ) : uint16
Returns
bytes.Reader:readUint32method
Reads a host-endian unsigned 32-bit integer.
function bytes . Reader : readUint32 ( ) : uint32
Returns
bytes.Reader:readUint64method
Reads a host-endian unsigned 64-bit integer.
function bytes . Reader : readUint64 ( ) : uint64
Returns
bytes.Reader:readUint8method
Reads one unsigned byte.
function bytes . Reader : readUint8 ( ) : uint8
Returns
bytes.Reader:remainingmethod
How many unread bytes remain.
function bytes . Reader : remaining ( ) : integer
Returns
bytes.Reader:skipmethod
Discards n unread bytes. Raises if fewer remain.
Arguments Name Type Description ninteger
Returns
bytes.Writer:buffermethod
The buffer being written to, for :tostring(), passing to a C call, or handing off to bytes.newReader.
Returns Type Description string . buffer . Buffer
bytes.Writer:writeBytesmethod
Appends s unchanged.
Arguments Name Type Description sstring
Returns
bytes.Writer:writeFloat32method
Writes a host-endian 32-bit float.
Arguments Name Type Description vfloat
Returns
bytes.Writer:writeFloat64method
Writes a host-endian 64-bit float.
Arguments Name Type Description vnumber
Returns
bytes.Writer:writeInt16method
Writes a host-endian signed 16-bit integer.
Arguments Name Type Description vint16
Returns
bytes.Writer:writeInt32method
Writes a host-endian signed 32-bit integer.
Arguments Name Type Description vint32
Returns
bytes.Writer:writeInt64method
Writes a host-endian signed 64-bit integer.
Arguments Name Type Description vint64
Returns
bytes.Writer:writeInt8method
Writes one signed byte.
Arguments
Returns
bytes.Writer:writeUint16method
Writes a host-endian unsigned 16-bit integer.
Arguments Name Type Description vuint16
Returns
bytes.Writer:writeUint32method
Writes a host-endian unsigned 32-bit integer.
Arguments Name Type Description vuint32
Returns
bytes.Writer:writeUint64method
Writes a host-endian unsigned 64-bit integer.
Arguments Name Type Description vuint64
Returns
bytes.Writer:writeUint8method
Writes one unsigned byte.
Arguments Name Type Description vuint8
Returns
← Previous Module: nupp Next → Module: nupp.data