Comments (6)
I am concerned about supporting two output modes (and duplicating the tests, and edge cases that this can create), and my preference here would be to stay close to the naming conventions made by the official Java protocol buffer generator.
The official Java protocol buffer generator does a similar thing: it wraps the classes generated from each proto file inside a public static class with a name that is derived from the proto file name. So although your messages are technically inside the declared Java package, their fully qualified class name contains the proto file name.
I am not completely sure why this is done this way in the Java generator, perhaps for being able to have messages with the same name in two proto files and in the same Java package (which is not necessarily a good thing, but some projects are probably already be in this situation).
In ScalaPB, I wanted to avoid the outer class approach since it will force us to have one big Scala class for each protocol buffer. Breaking it to smaller files in sub-packages allows the namespace to look similar to Java, but also enjoy better support for incremental compilation in SBT.
It is possible to implement it if really needed, let me know if there's a bug here that makes it hard/impossible to use ScalaPB in certain situations, or it's more of a stylistic preference.
from scalapb.
It has more to do with how protoc
behaves in general.
The protobuf syntax has package declaration that serves 2 purposes: namespace within .proto
files and namespace for generated code.
They support overriding the package name for Java (through option java_package
) because typical proto package names don't "look" like Java package names, as described here.
The outer class in Java is required because extensions generate simple values that can't live at top-level in Java.
Based on this, I would expect ScalaPB to behave similarly, which is to say that the package declaration within the proto files is respected (either through the package
keyword or java_package
option).
ScalaPB can still generate classes in their own file within that package (to get incremental compile goodness). Problems would only happen if someone has created a name collision in 2 separate .proto
files that declare the same package
AND that are compiled separately (because protoc
would choke otherwise).
My situation is that I'd like to move from ScalaBuff to ScalaPB, but it requires that I import n
new packages everywhere in my codebase (n
being the number of .proto
files I have). I could "trick" ScalaPB into generating the package I want, but I would need to merge files together and change their package declaration. I can see this being a much bigger problem for large projects and will definitely hurt ScalaPB's adoption.
One way to support this without breaking the whole ScalaPB world would be to declare an option
for either scala_package
or scala_package_per_file = true/false
.
from scalapb.
Oh - I didn't consider file-level custom options for this (I thought only of setting this through compiler plugin parameters). In this case, overriding the default settings would require the user to add an import for a "scalapb.proto" and adding something that looks like this in all their protos:
option (scala_pb.scala_package_per_file) = false;
Is this something that will be acceptable for your use case? Then maybe the protoc plugin can have a setting to override the settings for projects who do not want to add the custom option to every file.
from scalapb.
Yes, that's what I had in mind.
I think ScalaPB could expose several other options to control how it generates Scala case classes as well. So I'd be for using option
for this. A top-level setting would be nice as well since you probably don't want to do this on a subset of your .proto
files. Finally, I'd suggest scala_package
option which more closely matches the java generator and makes more sense as a per-file setting.
from scalapb.
Cool! I'll give this a try. Thanks for considering and implementing this!
from scalapb.
You're welcome. This feature has been shipped in v0.4.2
from scalapb.
Related Issues (20)
- allow_alias equality semantics differ between generated Scala and Java code HOT 1
- JSON serialization of Any message fails when the message has a special JSON representation HOT 2
- scalapb grpc runtime & InProcessTransport HOT 4
- Unrecognized enum serialized as int HOT 2
- Cannot name a 'oneof' field 'option' if an optional field exists HOT 1
- --jvm_0_out: protoc-gen-jvm_0: Plugin failed with status code 1. WIth Java version 11, change to 17 is fixed HOT 21
- Type Mismatch Error with `asRecognized` in versions 0.11.14 and 0.11.15 HOT 3
- sealed_oneof_companion_extends doesn't work for optional sealed oneof
- Sealed oneof "extend" for Empty case HOT 1
- java.lang.IllegalAccessError: tried to access method 'com.google.protobuf.LazyStringArrayList' HOT 10
- google/protobuf/empty.proto: File not found. HOT 1
- Define trait for GeneratedEnumCompanion’s fromJavaValue/toJavaValue HOT 1
- Support Scala 3.4 type wildcards HOT 2
- `_typemapper` are defined as package private, causing issues when deriving schemas HOT 4
- Protobuf with a field named using generates invalid Scala 3 code HOT 1
- ArrayIndexOutOfBoundsException on getFieldByNumber HOT 5
- UTF-8 Strings are unparseable? HOT 2
- JsonFormat.toJsonString omits authorisation string in the output JSON HOT 2
- Dependency on `scalapb.options.ScalapbProto` in generated code. HOT 3
- New release HOT 1
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 scalapb.