Dogacel / kotlinx-protobuf-gen

Generate kotlinx serializable data classes from protobuf
Apache License 2.0
12 stars 3 forks source link

[FEATURE] Prettify enum names #21

Open Dogacel opened 1 year ago

Dogacel commented 1 year ago

Is your feature request related to a problem? Please describe. Enum names are always prefixed by ENUM_NAME_ and this is not very intuitive for kotlin code. This is a limitation to support C++ generated code.

Describe the solution you'd like Add an option to automatically remove ENUM_NAME_ prefix from generated enums.

Describe alternatives you've considered None

Additional context

I think we can include an option to remove the ENUMNAME prefix from the actual enum names in the generated code. Such as

enum State {
  STATE_UNKNOWN = 0
  STATE_KNOWN = 1
}

will be converted to

@Serializable
public enum class State {
    @ProtoNumber(number = 0)
    UNKNOWN,
    @ProtoNumber(number = 1)
    KNOWN,
}

And this can be toggled via an option

    generateProtoTasks {
        all().forEach {
            it.plugins {
                id("kotlinx-protobuf-gen") {
                    option("remove_enum_prefix") // <-- this
                }
            }
        }
    }

Based on conversation with @tamnguyenhuy from #14