Skip to content

Binary Serialization & Streaming

Aegis flat memory arenas are binary data by design. Unlike JSON or Protocol Buffers, no serialization or encoding step is required to write an arena to disk or stream it over a TCP/WebSocket connection.


Zero-Copy Binary Output

To obtain a Uint8Array view of your arena's memory:

typescript
import { IO } from '@aventine/aegis-js';

// Get a binary slice of all active records in the list
const binaryBytes = IO.toBinary(myList);

console.log(`Active binary payload size: ${binaryBytes.byteLength} bytes`);

Because this returns a Uint8Array pointing directly into the underlying buffer, it executes in 0.00 milliseconds with zero memory copies.


Writing to Disk & Network

In Node.js, you can write the binary buffer directly to a file or socket:

typescript
import fs from 'node:fs';
import { IO } from '@aventine/aegis-js';

// Write 1,000,000 records to disk at full NVMe SSD speed (3+ GB/s)
fs.writeFileSync('market_data.bin', IO.toBinary(orderBook));

Reading Binary Streams Directly into Aegis

To load binary data back into an arena:

typescript
import fs from 'node:fs';
import { IO, Aegis } from '@aventine/aegis-js';
import { OrderSchema } from './schema.js';

// Read raw binary from disk
const buffer = fs.readFileSync('market_data.bin');

// Mount an AegisList directly over the existing buffer
const restoredList = IO.fromBinary(OrderSchema, buffer.buffer);

console.log(`Restored ${restoredList.length} orders in 0.01 ms with zero parsing overhead.`);

Protocol Comparison:

FormatParsing Time (1M Records)Memory OverheadGC Impact
JSON.parse()450 ms - 900 ms3.5x payload sizeExtreme (Full GC triggered)
Protocol Buffers120 ms - 280 ms1.8x payload sizeModerate
Aegis.js Flat Arena0.00 ms (Zero Copy)1.0x (Exact bytes)Zero (Flatline)

Released under the Apache 2.0 License. Built for sovereign silicon performance.