Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Elitriare/ByteNet-Max/llms.txt

Use this file to discover all available pages before exploring further.

ByteNetMax.auto is a flexible catch-all data type for when you want to send a value without committing to an exact type at definition time. Instead of encoding structure up front, auto inspects the value at send-time, writes a 1-byte type marker, and then serializes the value using the most compact matching codec. On the receiving end, the marker is read first, the correct codec is selected, and the original value is reconstructed — all transparently.

How it works

Every call to .send() on an auto packet writes exactly one extra byte — the type ID — before the payload. The serializer then picks the best-fit codec for the runtime value:
  • Integers use the smallest fitting unsigned or signed type (uint8, uint16, uint32, int8, int16, int32).
  • Floats that round-trip losslessly through a 32-bit buffer use float32; anything else falls back to float64.
  • Roblox types (Vector2, Vector3, Color3, CFrame) use their fixed-size codecs.
  • Strings use the standard 2-byte length-prefixed encoding.
  • nil and boolean have dedicated single-byte codecs.
  • Anything else (Instance, buffer, custom userdata) falls back to the unknown/reference codec.

Supported types and type IDs

Type IDLua/Roblox typeCodec used
0nilNo payload written
1booleanbool (1 byte)
2number (0–255, integer)uint8 (1 byte)
3number (256–65,535, integer)uint16 (2 bytes)
4number (65,536–4,294,967,295, integer)uint32 (4 bytes)
5number (-128–127, integer)int8 (1 byte)
6number (-32,768–32,767, integer)int16 (2 bytes)
7number (-2,147,483,648–2,147,483,647, integer)int32 (4 bytes)
8number (fits float32 exactly)float32 (4 bytes)
9number (all remaining)float64 (8 bytes)
10stringstring (2-byte header + N bytes)
12Vector2vec2 (8 bytes)
13Vector3vec3 (12 bytes)
14Color3color3 (3 bytes)
15CFramecframe (24 bytes)
17anything elseunknown (reference/fallback)

Number selection logic

For integer values, auto checks ranges in order from smallest to largest. Positive integers are tested against unsigned types first; negative integers skip straight to signed types:
-- value = 200   → fits 0–255 → uint8  (type ID 2, 1 byte payload)
-- value = 1000  → fits 0–65535 → uint16 (type ID 3, 2 bytes payload)
-- value = -50   → fits -128–127 → int8  (type ID 5, 1 byte payload)
-- value = 3.14  → fits float32 exactly → float32 (type ID 8, 4 bytes payload)
-- value = math.pi → requires float64 (type ID 9, 8 bytes payload)

Defining a packet with auto

local ByteNetMax = require(path.to.ByteNetMax)

return ByteNetMax.defineNamespace("AutoDemo", function()
    return {
        packets = {
            DebugValue = ByteNetMax.definePacket({
                value = ByteNetMax.auto,
            }),
        },
    }
end)

Sending values

local AutoDemo = require(path.to.AutoDemo)

AutoDemo.packets.DebugValue.send(123)                  -- serializes as uint8
AutoDemo.packets.DebugValue.send("hello")              -- serializes as string
AutoDemo.packets.DebugValue.send(true)                 -- serializes as bool
AutoDemo.packets.DebugValue.send(Vector3.new(1, 2, 3)) -- serializes as vec3
AutoDemo.packets.DebugValue.send(nil)                  -- serializes as nil
Each send is independent — you can send different types through the same auto packet on different calls.
auto adds exactly 1 byte of overhead per value for the type marker. This cost is paid on every send, regardless of which codec is selected for the payload.
auto is excellent for prototyping, debug tooling, and mixed-payload scenarios where the type varies at runtime. Once your packet’s shape stabilizes, switching to a struct with explicit field types eliminates the per-value marker byte and gives the Luau type checker full visibility into your data.
Instance, buffer, and custom Roblox userdata types fall through to the unknown/reference fallback codec (type ID 17). This codec does not perform compact binary serialization — treat it as a last resort and prefer dedicated primitive types where possible.

Build docs developers (and LLMs) love