Myra Codec
Schema-driven binary codec with zero-copy serialization
Serialization LayerZero-Copy
Overview
Myra Codec is a high-performance binary serialization library with a schema-first design. It supports full schema evolution, union types, and zero-copy encoding/decoding paths for maximum throughput.
Key Features
Schema-First Design
- YAML/JSON schema definitions for type safety
- Code generation producing idiomatic Java classes
- Compile-time validation of schema compatibility
Zero-Copy Serialization
- Direct buffer encoding without intermediate objects
- Off-heap support via Roray FFM Utils integration
- Streaming encode/decode for large messages
Schema Evolution
- Forward and backward compatibility
- Field additions without breaking changes
- Union type evolution with proper versioning
Rich Type System
- Primitive types: int8-64, float32/64, bool, string, bytes
- Complex types: struct, list, map, union
- Optional fields with proper null handling
Schema Example
# schema.myra.yml
namespace: com.example.trading
types:
Order:
id: int64
symbol: string
quantity: int32
price: float64
side: OrderSide
timestamp: int64
metadata: OrderMetadata?
OrderSide:
enum:
OrderMetadata:
union:
- MarketOrder:
- LimitOrder:
expiry: int64
- StopOrder:
triggerPrice: float64
Generated Code Usage
// Create and encode
var order ;
// Encode to buffer (zero-copy)
var buffer ;
order.;
// Decode from buffer (zero-copy)
buffer.;
var decoded ;
Performance Comparison
| Codec | Throughput | Alloc/Op | Message Size |
|---|---|---|---|
| Myra Codec | 850K ops/s | 0 bytes | 128 bytes |
| Protocol Buffers | 620K ops/s | 48 bytes | 134 bytes |
| JSON (Jackson) | 180K ops/s | 512 bytes | 245 bytes |
| Java Serialization | 45K ops/s | 2.1 KB | 512 bytes |
Use Cases
- High-frequency trading message serialization
- Distributed systems RPC payloads
- Event sourcing compact event storage
- Network protocols efficient wire format
Installation
Gradle (Kotlin DSL)
plugins {
id("express.mvp.myra-codec") version "0.1.0"
}
dependencies {
implementation("express.mvp:myra-codec:0.1.0")
}
myraCodec {
schemaDir = file("src/main/schemas")
outputDir = file("build/generated/sources/myra")
}
Maven
express.mvp
myra-codec
0.1.0