Simplify code for ProtoAdapters of types with no fields
Open
Nobody has claimed this yet.
enhancement
lang/kotlin
- Dominant language
- Kotlin
- Stars
- 4.4k
- Forks
- 627
- Avg merge
- 3d 15m
- Merged PRs (30d)
- 20
Description
Example:
companion object {
@JvmField
val ADAPTER: ProtoAdapter<NodeEvent> = object : ProtoAdapter<NodeEvent>(
FieldEncoding.LENGTH_DELIMITED,
NodeEvent::class.java
) {
override fun decode(reader: ProtoReader): NodeEvent {
val unknownFields = reader.forEachTag { tag ->
when (tag) {
else -> TagHandler.UNKNOWN_TAG
}
}
...
}
The when block is unnecessary, since NodeEvent doesn't have any fields. This can be simplified to:
val unknownFields = reader.forEachTag { TagHandler.UNKNOWN_TAG }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the ProtoAdapter generation for types with no fields and compare it with the NodeEvent example in the issue. Check existing generated-code tests or fixtures for empty types, then verify that the generated adapter uses the simplified tag handler and that the relevant tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100