tafia / quick-protobuf

A rust implementation of protobuf parser
MIT License
452 stars 87 forks source link

Would it support service? #83

Open AndreMouche opened 7 years ago

AndreMouche commented 7 years ago

Would it support service one day, it seems not work for the following situation:

syntax = "proto3";
package grpc;

service HelloService {
  rpc SayHello (HelloRequest) returns (HelloResponse);
}

message HelloRequest {
  string greeting = 1;
}

message HelloResponse {
  string reply = 1;
}
tafia commented 7 years ago

Indeed it is not supported for the moment and there is no short term plan to support it (support goes beyond simple protobuf serialization/deserialization).

On the other hand, I'd be happy to make any modification you think would be missing for another crate to implement it fully (i.e. providing some simple rust structs/traits). The code generation part should be relatively simple.

aep commented 6 years ago

just generating the traits would be very helpful!

nerdrew commented 6 years ago

Prost has a config for plugging in an external service generator: https://docs.rs/prost-build/0.3.2/prost_build/struct.Config.html#method.service_generator

That seems like another solution.

tafia commented 6 years ago

I am not a big fan to be honest, I believe it doesn't fit too well with rust.

I think i prefer a trait based approach, or even a sync and an async which would use Future (you can decide in config which one suits you the best)

pub trait HelloService {
    type Error;
    fn SayHello(_req: &HelloRequest) -> Result<HelloRespone, Self::Error>;
}

pub trait HelloServiceAsync {
    type Error;
    type Response: Future<Item = HelloResponse, Error = Self::Error>;
    fn SayHello(_req: &HelloRequest) -> Self::Response;
}

That being said, I am open to any solution at the moment because I don't plan on working on this right now.