Comments (8)
@Mathspy hi! Thank you for the kind words! <3
So I actually think this comes down to the fact that each proto is in their own package. So prost-build
will build one rs
file per package
. Generally in protobuf if you have folder structure like proto/helloworld/...proto
all protos within this folder are under the helloworld
package. So to fix your problems here change hello.proto
to:
syntax = "proto3";
package helloworld;
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
This will generate the messages and the service within the same rs file.
from tonic.
I encoutered similar problem and wrote a little proc-macro to deal with it.
https://crates.io/crates/tonic_include_protos
It will import all generated files and put it into corresponding mod structure.
I guess i leave it here for someone in the future not to struggle.
from tonic.
Oh sweet! This actually does work really well, thank you! It seems to have an edge case when there are several ENUMs with similarly named variants like:
enum EnumTypeThing {
HELLO = 0;
NAME = 1;
}
and
enum EnumTypeThingInDifferentFile {
NAME = 0;
FILE = 1;
}
This would lead to an error during build like:
"protoc failed: file1.proto:9:5: \"helloworld.NAME\" is already defined in file \"hello.proto\".\nhelloworld.proto:9:5: Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, \"NAME\" must be unique within \"helloworld\", not just within \"EnumTypeThing\"
So I guess that makes this solution not work in this one edge case but in my use case it works so I will leave it up to you to leave the issue open to keep track of that or close it! ❤️
from tonic.
One way to make the conflicting enum variants work would be to prefix them.
enum EnumType1 {
ENUM_TYPE_1_HELLO = 0;
ENUM_TYPE_1_NAME = 1;
}
enum EnumType2 {
ENUM_TYPE_2_HELLO = 0;
ENUM_TYPE_2_NAME = 1;
}
Another way would be to nest your enums in messages. This causes them to be put into their own "namespace". With Tonic this causes the generated enums to be put into their own Rust modules. enum_type_thing::EnumTypeThing
, and enum_type_thing_in_different_file::EnumTypeThingInDifferentFile
.
message EnumTypeThing {
enum EnumTypeThing {
HELLO = 0;
NAME = 1;
}
}
message EnumTypeThingInDifferentFile {
enum EnumTypeThingInDifferentFile {
NAME = 0;
FILE = 1;
}
}
from tonic.
There will be some who don't want to adjust protobuf files - as they are often interfaces for other languages. That fact, and some of the challenges around what Prost generates (especially Option predictability) - is there a way to decouple the the 'models' from the client/server impls?
from tonic.
@blittable could you explain more what you mean by decoupling the models?
from tonic.
@LucioFranco
I was mocking up a food ordering system, so I had types like Order
, Delivery
, etc. and ended up adjusting some namespaces to fit the client/server generation code. That would be sub-optimal if I had other clients (iOS, Android) dependent on those. But, that might be my inexperience with the pf namespaces and imports, so I'll try to demonstrate and write it up if it's still problematic.
Likewise, it might be my inexperience with protoc
, but I wish I could use my .rs code as inputs to tonic. I'm adjusting an interface to fit the tool (option types, namespaces, etc.) and then (hypothetically) telling other clients (e.g. iOS) to accommodate.
from tonic.
@blittable agreed, I will think about it a bit.
from tonic.
Related Issues (20)
- Naming collisions with std::marker::Sync/Send HOT 1
- How to make tonic support tls HOT 4
- nit: inconsistent use of crate::Error vs Error in single transport src file
- calling grpc server hosted on cloud run with https fails with transport error HOT 2
- version 0.12.1 causes ClientTlsConfig to explode with invalid CryptoProvider HOT 2
- Configuring Timeout for Graceful Shutdown HOT 1
- How to get grpc-status in Layer? HOT 1
- Make the TimeoutExpired a public tonic type rather than a transport type
- tonic_build clone server
- long headers from the server hang tonic HOT 5
- Non-Anonymous Authentication
- The trait `Message` is not implemented HOT 1
- Remove trait bound on generated server struct
- NamedService makes it impossible to wrap individual services with non-intercept layers HOT 2
- After tonic is updated from 0.8.3 to 0.11.0 in the csi driver, an error message "PROTOCOL_ERROR" is displayed when kubelet calls the get_info interface.
- Share tonic server port with other http routes HOT 3
- Protobuf bytes field incorrectly parsed as String when generating gRPC code with tonic_build HOT 1
- tonic-build can no longer build code with rust < 1.77.0, due to newer build-script syntax HOT 1
- Tonic v0.13 fails to build what worked on v0.12 HOT 1
- The tonic server process exit unexpected when the client get a wrong tls config HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tonic.