Crates.io | power-protobuf |
lib.rs | power-protobuf |
version | 0.1.11 |
source | src |
created_at | 2024-04-19 05:26:45.979596 |
updated_at | 2024-04-24 03:55:24.443328 |
description | a proc-macro for embedding protobuf inside rust code |
homepage | https://github.com/powermacros/power-protobuf |
repository | https://github.com/powermacros/power-protobuf |
max_upload_size | |
id | 1213298 |
size | 38,763 |
power_protobuf is a proc-macro to let you write protobuf in rust source code directly like this way!:
protobuf! {
syntax = "proto3";
package helloworld;
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello ({
// 'simplize_rpc_params' feature simplize to define Request/Response messages for rpc
string name
}) returns (HelloReply) {}
}
// The response message containing the greetings
message HelloReply {
string message // 'tagless' feature omit to assign tag number at design stage, it will do auto-increment as by refering previous number
}
}
both protobuf version (2 to 3 yet) has been supported.
protobuf!
also allows you not to declare the version explicitly, it will parse as proto3 syntax by default.
package
will be generated into a rust mod
in current source file if you define it. And by opposite, it expand to current place as not deinfed.
use protobuf!
you can write protocol like this:
message A {
int32 field1,
string field2,
repeated string field10 = 10,
string field11
sfix32 field12
}
the tags of field1, field2, field11, field12 will be assign as '1', '2', '11', '12' automatically.
defines Request and Response message types for multiple rpc methods would be a redundant work for sometime.
protobuf!
provides an option to simplize this:
service Greeter {
rpc SayHello ({
string name
}) returns (HelloReply) {}
}
message SayHelloRequest
will be generated as fields defined in {}
. the type name for request/response combines rpc name and suffix(Request
/Response
) in upper camel case.
protobuf!
let's you easy to use external types in other protobuf definitions. it will check the type of fields by reading corresponding .rs files.
FIXME: more details will be introduced in this doc later.
enable feature impl_prost
to expand codes using prost/tonic stack.
the impl_prost
feature is enabled defaultly.
features | progress |
---|---|
proto2 and proto3 syntax | Done |
tagless | Done |
free request/response param type | Done |
support prost | Partly |
support rust-protobuf | Not yet |
stream support | Not yet |