Protobuf support for Odin. To generate Odin files from proto definitions, use the odin-protoc-plugin.
Example usage of the library can be found in the examples folder.
For this proto file
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 results_per_page = 3;
}
You can generate the following Odin code using the odin-protoc-plugin
SearchRequest :: struct {
query : string `id:"1" type:"9"`,
page_number : i32 `id:"2" type:"5"`,
results_per_page : i32 `id:"3" type:"5"`,
}
You can then use this library to encode:
message := proto.SearchRequest {
query = "test",
page_number = 43,
results_per_page = 20,
}
if encoded_buffer, ok := protobuf.encode(message); ok {
// success
} else {
// error
}
and decode:
if message, ok := protobuf.decode(proto.SearchRequest, buffer); ok {
// success
} else {
// error
}