# Wire format

> The primitive encodings under every Roblox packet, with a live decoder you can paste bytes into.
> Rove documentation: https://docs.rove.wtf/wire

Every packet is built from a small set of primitives. Numbers are little-endian. Lengths and counts are usually variable-length integers. Signed variable-length integers are zig-zag encoded so small negative numbers stay small.

## Primitives

| Primitive | Encoding |
|---|---|
| readUInt8 / readInt8 | u8 / i8 (1B) |
| readBool | u8 (0 or 1, 1B) |
| readUInt16 / readInt16 | u16 / i16 LE (2B) |
| readUInt32 / readInt32 | u32 / i32 LE (4B) |
| readUInt64 / readInt64 | u64 / i64 LE (8B) |
| readFloat / readDouble | IEEE-754 f32 (4B LE) / f64 (8B LE) |
| readVarUInt32 / readVarUInt64 | Unsigned LEB128 (7 bits/byte, max 5B / 10B) |
| readVarUInt16 | Unsigned LEB128 bounded <= 0xFFFF |
| readZigZagInt32 / readZigZagInt64 | (u >> 1) ^ -(u & 1) over varuint32 / varuint64 |
| readBoundedString | u32 byte_len LE (4B) + byte_len raw bytes |
| readVarIntString | varuint32 byte_len + byte_len raw bytes |
| RakString::Deserialize | u16 byte_len LE (2B) + byte_len raw bytes (packet 147) |
| Replicator::readGuid | varuint32 scope: 0 -> Null (1B); else u32 index LE (1..5 + 4B) |
| StreamRegion::Id::read | u8 is_i32: 0 -> 3 x i8 (4B total); 1 -> 3 x i32 LE (13B total) |
| readCompressedBitStream | u32 comp_len LE + u32 raw_len LE + comp_len Zstd bytes |
| readContextTrail | Per unresolved SharedString/ProtectedString (6, 46, 47): 16B key + u8 cached (1 = 0B; 0 = varuint32 len + lenB Blake2b-128) |

## Decode bytes yourself

Pick a type, paste hex, and see how Rove reads it, byte by byte. The examples are real encodings. Select a byte and drag it up or down, or use the arrow keys, and watch the value move; flip single bits in the row that appears underneath.

(Interactive on the web page: a decoder for varuint32, zig-zag, Int64, Bool, Float, Double, String, Vector3, Vector3int16, CFrame, Color3, Color3uint8, BrickColor, UDim2, NumberRange, DateTime and Guid. Paste hex and see each byte's role; for example `00 00 00 00 00 00 28 41 00 00 80 C0` is `Vector3.new(0, 10.5, -4)`.)

## Variable-length integers

`varuint32` is LEB128: seven bits per byte, low bits first, with the top bit set on every byte except the last. Small numbers, which is most counts and lengths, take one byte.

Signed values are zig-zag encoded first, so the sign moves to the lowest bit and small negative numbers stay small too. Type a number, or step it across a boundary like 127 → 128 and watch a byte appear.

(Interactive on the web page: type a number and see its 7-bit groups and bytes. Examples: 0 → `00`, 127 → `7F`, 128 → `80 01`, 300 → `AC 02`, 16384 → `80 80 01`; zig-zag: −1 → `01`, −64 → `7F`, −300 → `D7 04`.)

## Compressed blocks

Large payloads (join data, terrain clusters, the schema) are Zstandard frames with both sizes up front: `u32 compressed length`, `u32 uncompressed length`, then the frame. Rove refuses frames whose declared size is over its limit before decompressing them.

## CFrames

A CFrame is a position (three `f32`) and an orientation byte. Ids `1`–`36` name the rotations that keep a part lined up with the axes. The id is computed from where the part's right and top faces point, `6 × right + up + 1`, so only the 24 pairs that are perpendicular are real rotations. Most CFrames in a build are one of them and cost 13 bytes.

Id `0` means "the full rotation follows": nine floats for the matrix form (49 bytes) or a packed quaternion for the quaternion form (19 bytes).

The 24 valid orientation ids (right axis × up axis; the third column is their cross product):

| Right \ Up | +X | +Y | +Z | −X | −Y | −Z |
|---|---|---|---|---|---|---|
| +X | · | 2 | 3 | · | 5 | 6 |
| +Y | 7 | · | 9 | 10 | · | 12 |
| +Z | 13 | 14 | · | 16 | 17 | · |
| −X | · | 20 | 21 | · | 23 | 24 |
| −Y | 25 | · | 27 | 28 | · | 30 |
| −Z | 31 | 32 | · | 34 | 35 | · |

Id 2 (right +X, up +Y) is no rotation.

Rove's decoder builds the matrix the same way this does: the right and up vectors from the id, and the third column as their cross product.
