Wire Types
Define a network message format that can evolve without breaking existing consumers.
Hew
Wire types live in the same .hew file as your code. Field numbers (@N) ensure binary compatibility across versions. #[serial(case = "camelCase")] controls JSON serialization naming. The compiler checks field-number consistency for Hew-to-Hew schemas.
#[wire]
#[serial(case = "camelCase")]
type UserEvent {
user_id: i32 @1;
user_age: i32 @2;
}
// Adding a new field later:
// email: Option<string> @3 optional; <- older consumers ignore @3
fn main() {
let event = UserEvent {
user_id: 42,
user_age: 30,
};
println(f"User {event.user_id}, age {event.user_age}");
}Go + Protobuf
Protobuf definitions live in a separate .proto file using a different language. A code generation step (protoc) produces Go structs before you can compile. The split suits cross-language teams and adds a build-tool boundary.
// user_event.proto — separate file, separate language
syntax = "proto3";
message UserEvent {
int32 user_id = 1;
int32 user_age = 2;
}# Generate Go code from .proto definition
protoc --go_out=. user_event.proto// Use the generated code
import pb "myapp/proto"
event := &pb.UserEvent{UserId: 42, UserAge: 30}
data, err := proto.Marshal(event)
if err != nil {
log.Fatal(err)
}
var decoded pb.UserEvent
proto.Unmarshal(data, &decoded)Rust + serde
Serde gives you JSON serialization with derive macros, but no field-number stability for binary evolution. For binary wire compatibility, you need the protobuf toolchain (same as Go) plus a crate like prost.
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct UserEvent {
user_id: i32,
user_age: i32,
}
// No field numbering — JSON only, no binary wire stability
// For binary stability, need prost crate + .proto file
fn main() {
let event = UserEvent {
user_id: 42,
user_age: 30,
};
let json = serde_json::to_string(&event).unwrap();
let decoded: UserEvent =
serde_json::from_str(&json).unwrap();
}What this shows
Developer experience
Hew has no .proto → codegen → import pipeline: wire types sit alongside the code that uses them and compile in the same step, with no separate build tool or generated code to keep in sync.
Schema evolution
In protobuf, schema evolution discipline matters: field numbers should not be reused, and reserved markers help communicate that contract. Hew moves field-number checks into the Hew compiler for supported Hew-to-Hew schemas, while protobuf keeps the advantage for multi-language APIs.
Trade-offs
Protobuf has mature tooling, cross-language support (Java, Python, C++, and more), and an IDL-first design that forces schema documentation. Teams working across multiple languages benefit from a shared .proto definition. Hew's wire types are Hew-only: they cover Hew-to-Hew communication and do not generate bindings for other languages.