generate classes with non-null Message types with custom options / extensions - #243
Open
Dogacel wants to merge 1 commit into
Open
Conversation
fluxxion82
reviewed
Dec 15, 2022
Comment on lines
+511
to
+516
| protected val File.Field.Numbered.allowNulls: Boolean | ||
| get() = requiredFieldNumber?.let { | ||
| // 1 means `required = true` so we can't allow nulls | ||
| this.options.unknownFields[it]?.values?.get(0)?.rawBytes?.array?.get(0)?.toInt() != 1 | ||
| } ?: true | ||
| protected fun File.Field.Numbered.kotlinValueType(allowNulls: Boolean = this.allowNulls): String = when (this) { |
Contributor
There was a problem hiding this comment.
what do you think about putting something like
val isRequired: Boolean
get() = rawBytes.array.first().toInt() != 1
in the UnknownField.Value class and then having
options.unknownFields[it]?.values?.firstOrNull()?.isRequired == true
here?
Contributor
Author
There was a problem hiding this comment.
Maybe not isRequired because it is just a boolean. We need to smart cast those bytes to a boolean, maybe something like asBoolean() is a better candidate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refers to
Overview
Allow not nullable
Messagetypes to be generated by using custom protobuf options or extensions.How
required_field_extension_number.CodeGeneratorto allow nullableMESSAGEtype and set the default value to be the constructor invocation (default instance)Risks