-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the new proto3 field presence feature #34
Comments
Fields marked with the `optional` keyword in `proto3` files will now result in nullable Kotlin types in the generated code. Fixes #34.
Hi, I'm experiencing a problem with nullability generation. My scenario is a bit different in that I use Given this input
I get this kotlin class @pbandk.Export
data class User(
val name: String = "", I need I'm using pbandk 0.14.3. This is the protoc command
Would you expect this to generate null types, or do .proto files produce something different than text format? Technical details, in case it's relevant I parse pbtxt to a file.inputStream()
.use { inputStream: FileInputStream ->
FileDescriptorSet.parseFrom(inputStream.readAllBytes()).also {
it.getFile(0).messageTypeList.forEach { message ->
println("Message ${message.name}")
message.fieldList.forEach { field: FieldDescriptorProto ->
println("\t${field.name}, label ${field.label}")
}
}
}
} prints
|
See protocolbuffers/protobuf#1606 (comment) and https://github.com/protocolbuffers/protobuf/blob/master/docs/implementing_proto3_presence.md for details.
When this feature is in use, pbandk should generate code for primitive fields using a nullable type that defaults to
null
, rather than a non-null type that defaults to empty string, zero, false, etc.E.g., current code for this protobuf definition:
will look like:
Using the new optional presence feature, this protobuf definition:
should look like:
The text was updated successfully, but these errors were encountered: