Platform-agnostic binary communication protocol for GPU command serialization
npm install @fluxgpu/protocolbash
pnpm add @fluxgpu/protocol
`
Usage
$3
`typescript
import { serializeCommand, deserializeCommand } from '@fluxgpu/protocol';
import type { CommandBuffer } from '@fluxgpu/contracts';
import { Opcode } from '@fluxgpu/contracts';
const command: CommandBuffer = {
id: 'cmd-001',
opcode: Opcode.CreateBuffer,
payload: new Uint8Array([1, 2, 3, 4]),
dependencies: [],
};
// Serialize to binary
const bytes = serializeCommand(command);
// Deserialize back
const restored = deserializeCommand(bytes);
`
$3
`typescript
import { serializeBatch, deserializeBatch } from '@fluxgpu/protocol';
const commands = [command1, command2, command3];
const batch = serializeBatch(commands);
const restored = deserializeBatch(batch);
`
Wire Format
Commands are serialized as:
`
┌──────────┬──────────┬──────────┬──────────┬──────────�?
�? Header �? Opcode �? ID Len �? ID �?Payload �?
�? 4 bytes �? 1 byte �? 2 bytes �? N bytes �? M bytes �?
└──────────┴──────────┴──────────┴──────────┴──────────�?
``