procwire-client
Rust client SDK for Procwire v2.0 IPC protocol.
This crate enables Rust workers (child processes) to communicate with a Node.js parent process running @procwire/core using a high-performance binary protocol.
Features
- High Performance: Binary protocol with MsgPack serialization, achieving >1 GB/s throughput
- Zero-copy: Uses
bytes::BytesMutfor efficient buffer management - Async/await: Built on Tokio for non-blocking I/O
- Cross-platform: Works on Linux, macOS, and Windows
- Type-safe: Strongly typed handlers with Serde integration
- Streaming: Support for chunked responses and backpressure
- Cancellation: Full abort signal support with
CancellationToken
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Quick Start
use ClientBuilder;
use ;
async
Architecture
Procwire uses a dual-channel architecture:
- Control Plane (stdio): JSON-RPC for the
$inithandshake - Data Plane (named pipe/Unix socket): Binary protocol for high-throughput communication
┌─────────────────┐ ┌─────────────────┐
│ Node.js Parent │ │ Rust Worker │
│ (@procwire/core)│ │ (this crate) │
├─────────────────┤ ├─────────────────┤
│ │◄── $init (JSON) ───│ │
│ │ │ │
│ │◄═══ Binary ═══════►│ │
│ │ (Named Pipe) │ │
└─────────────────┘ └─────────────────┘
Wire Format
All data plane messages use an 11-byte binary header:
┌──────────┬───────┬──────────┬──────────┬──────────────────────┐
│ Method ID│ Flags │ Req ID │ Length │ Payload │
│ 2 bytes │ 1 byte│ 4 bytes │ 4 bytes │ N bytes │
│ uint16 BE│ │ uint32 BE│ uint32 BE│ (MsgPack) │
└──────────┴───────┴──────────┴──────────┴──────────────────────┘
Response Types
Simple Response
ctx.respond.await?;
Acknowledgment (for fire-and-forget)
ctx.ack.await?;
Streaming Response
for chunk in chunks
ctx.end.await?;
Error Response
ctx.error.await?;
Events (Fire-and-Forget)
Send events to the parent process:
client.emit.await?;
Cancellation Support
Handlers can respond to abort signals from the parent:
.method
Configuration
new
.max_concurrent_handlers // Limit concurrent handler tasks
.backpressure_timeout
.method
.build
.await?;
Platform Support
| Platform | Transport |
|---|---|
| Linux | Unix Domain Socket |
| macOS | Unix Domain Socket |
| Windows | Named Pipe |
Related Projects
- procwire - Node.js/TypeScript parent library (
@procwire/core)
License
MIT License - see LICENSE for details.