Auto-generate binary serialization for classes:
@derive(Serialize, Deserialize)
class GameState {
var level: Int
var score: Int
var playerName: String
}
This generates serialize() and deserialize() methods that encode/decode the class fields to/from binary format.
Low-level binary buffer API:
import core.binary
| Function | Signature | Description |
|---|---|---|
newBinaryBuffer |
(capacity: Int) r: Int |
Create buffer (returns handle) |
binaryBufferLength |
(handle: Int) r: Int |
Get buffer length |
| Function | Description |
|---|---|
__BinaryBufferNew(capacity) |
Create binary buffer |
__BinaryBufferData(handle) |
Get data pointer |
__BinaryBufferLength(handle) |
Get length |
__BinaryWriteI64(handle, val) |
Write 64-bit integer |
__BinaryReadI64(handle, offset) |
Read 64-bit integer |
__BinaryWriteF64(handle, val) |
Write 64-bit float |
__BinaryReadF64(handle, offset) |
Read 64-bit float |
let buf = newBinaryBuffer(1024)
__BinaryWriteI64(buf, 42)
__BinaryWriteF64(buf, 3.14)
let len = binaryBufferLength(buf)
println("Buffer size: {len}")
Run-length encoding for binary data:
import core.compress
| Function | Signature | Description |
|---|---|---|
compressRLE |
(src: Int, srcLen: Int, dst: Int, dstCap: Int) r: Int |
Compress data |
decompressRLE |
(src: Int, srcLen: Int, dst: Int, dstCap: Int) r: Int |
Decompress data |
Returns the output length, or -1 on error.
Network packet utilities:
import core.packet
| Function | Signature | Description |
|---|---|---|
packetHeaderId |
(header: Int) r: Int |
Extract packet ID from header |
packetHeaderLength |
(header: Int) r: Int |
Extract payload length from header |
For network protocol types:
@packet(id = 1)
class LoginRequest {
var username: String
var password: String
}
Mark a class for binary layout:
@binary
class RawData {
var header: Int
var payload_size: Int
var checksum: Int
}
