Skip to content

Commit 2a38678

Browse files
committed
Add a utility class for creating / reading a PackedByteArray
1 parent 8edfbb8 commit 2a38678

File tree

8 files changed

+1471
-9
lines changed

8 files changed

+1471
-9
lines changed

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ godot = { version = "0.4.2", features = ["api-4-3", "register-docs"] }
99
mcap = "0.23.4"
1010
enumset = "1.1.10"
1111
memmap2 = "0.9.8"
12+
half = "2.4.1"
1213

1314

1415
[lib]

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ This extension is built with godot-rust and targets Godot >=4.3 APIs.
3030
- `MCAPReplay` Node to emit messages over time (idle or physics), with speed/looping
3131
- Godot-friendly Resources for common MCAP types (Channel, Schema, Message, Attachment, Metadata)
3232
- Error handling via `get_last_error()` on reader/writer
33+
- Binary stream helper
34+
- `BinaryStream` to pack/unpack primitives and Godot builtins (Vector2/3, Transform2D/3D, Basis)
35+
- Load existing `PackedByteArray` instances, seek, and export the stream back to Godot
3336

3437

3538
## Installation
@@ -159,6 +162,24 @@ if reader.get_last_error() != "":
159162
```
160163

161164

165+
### Serialize binary data (GDScript)
166+
167+
```gdscript
168+
var stream := BinaryStream.new()
169+
stream.write_u32(123)
170+
stream.write_vector3(Vector3(1, 2, 3))
171+
var bytes := stream.to_packed_byte_array()
172+
173+
var reader := BinaryStream.new()
174+
reader.load_bytes(bytes)
175+
reader.seek(0)
176+
var id := reader.read_u32()
177+
var pos := reader.read_vector3()
178+
```
179+
180+
Use `seek`, `skip`, and the typed read/write helpers (integers, floats, half, Vector2/3, Basis, Transform2D/3D, etc.) to build binary payloads that round-trip cleanly between Rust and GDScript.
181+
182+
162183
### Replay in real-time (Node)
163184

164185
```gdscript

0 commit comments

Comments
 (0)