Note: This mapping is currently only meant for the
proto3
language, though it could be adapted toproto2
.
Protobuf | WIT |
---|---|
float |
float32 |
double |
float64 |
int32 sint32 sfixed32 |
s32 |
int64 sint64 sfixed64 |
s64 |
uint32 fixed32 |
u32 |
uint64 fixed64 |
u64 |
bool |
bool |
string |
string |
bytes |
list<u8> |
Enums are mapped to WIT variant
s. Each enum constant name is mapped to a variant case. Additionally, an extra case is defined with payload type i32
to store unknown enum values, e.g. unknown-value(i32)
TODO: Decide on a standard "unknown value" case name and how to resolve name collisions.
TODO: Consider generating functions to convert between enum constant and variant values.
Messages are mapped to WIT record
s.
Message names are mapped to kebab-case for the record name.
TBD: nested message name scoping
Fields are mapped in order of increasing tag number. Field names are mapped by converting to kebab-case.
An optional
field is mapped by wrapping its type with option<...>
.
A repeated
field is mapped by wrapping its type with list<...>
.
A oneof
is mapped to a WIT variant
. The first case of the variant is unset
, and the other cases correspond to the fields of the oneof
.
TBD: what if one of the fields is named
unset
?
A map<K,V>
is mapped (!) to a WIT list<tuple<K, V>>
.