The difference between all the "read" and "write" functions in the Buffer library

I’m currently working on buffers, and I’d like some clarification on the terms “write” and “read”. What exactly do they mean, and how are they used? I understand the differences between Base 2 (binary), Base 8 (octal), and Base 16 (hexadecimal), but I’m unsure how to apply them when working with buffers. Could you please provide some guidance?

Best regards,

I’d look into how memory works and how different data types are stored and read.
After learning those topics you should be able to understand most of the functions by just reading their names.

Each function explains how many bits it should read/write from.

local Buffer = buffer.create(1) -- 1 byte = 8 bits

buffer.writeu8(Buffer, 0, 5) -- offset starts at 0
print(buffer.readu8(Buffer, 0)) -- prints 5

Here’s a table of what ranges each type can store:

u8		0 to 255
u16		0 to 65535
u32		0 to 4294967295

i8		-128 to 127
i16		-32768 to 32767
i32		-2147483648 to 2147483647

f32		Single-Precision Float
f64		Double-Precision Float

(Note there is no u64/i64 because Lua uses double-precision floats for numbers, which can’t represent high numbers properly).

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.