turbomcp-wire
Wire format codec abstraction for TurboMCP - JSON-RPC encoding/decoding with pluggable serialization.
Overview
This crate provides the wire format layer for MCP protocol communication. It abstracts over different serialization formats while maintaining MCP protocol compliance.
Features
- JSON Codec - Standard serde_json implementation (default)
- SIMD JSON - High-performance SIMD-accelerated parsing (optional)
- MessagePack - Compact binary format for internal use (optional)
- Streaming Decoder - Newline-delimited JSON for SSE transports
no_stdCompatible - Works in embedded and WASM environments
Usage
use ;
use ;
let codec = new;
// Encode
let request = Request ;
let bytes = codec.encode.unwrap;
// Decode
let decoded: Request = codec.decode.unwrap;
Streaming Decoder
For HTTP/SSE transports with newline-delimited JSON:
use StreamingJsonDecoder;
let mut decoder = new;
// Feed data as it arrives
decoder.feed;
// Try to decode complete messages
while let Some = decoder.?
Feature Flags
| Feature | Description |
|---|---|
std |
Standard library support (default) |
json |
JSON codec (default) |
simd |
SIMD-accelerated JSON (sonic-rs) |
msgpack |
MessagePack binary format |
full |
All features |
Dynamic Codec Selection
Create codecs dynamically by name using AnyCodec:
use AnyCodec;
let codec = from_name.unwrap;
let bytes = codec.encode.unwrap;
println!;
Performance
With simd feature enabled, JSON parsing can be 2-4x faster on supported platforms:
License
MIT