gRPC: kavach proto
● Intermediate2 min
kavach proto writes the .proto file for your types, so a service in any other language can generate matching code.
type Status = Pending | Paid(amount: Float)
type Order {
id: Int
item: String
qty: Int = 1
status: Status
tags: [String]
notes: [String: String]
}
fn main() {
}kavach proto src/main.kav
// Written by `kavach proto` from src/main.kav.
syntax = "proto3";
message Status {
oneof value {
Pending pending = 1;
Paid paid = 2;
}
message Pending {}
message Paid {
double amount = 1;
}
}
message Order {
int64 id = 1;
string item = 2;
int64 qty = 3;
Status status = 4;
repeated string tags = 5;
map<string, string> notes = 6;
}- A union becomes a message with a
oneof; a list isrepeated; a map with text keys is amap. - Add new fields at the end of a record: older clients keep working. Reordering fields breaks them.