Skip to content

Simplify code for ProtoAdapters of types with no fields #757

Open
@Egorand

Description

@Egorand

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 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions