Generate kotlin data classes from protobuf
files that supports Kotlin Native that can be serialized and
deserialized to protobuf using kotlinx.serialization.
[!NOTE]
Setup instructions and detailed documentation can be found at Setup and Documentation.
proto2
and proto3
.kotlinx.serialization
annotations for proto field numbers and serialization format.int32
, string
, bytes
.message
, enum
, repeated
, map
, oneof
types.Timestamp
, StringValue
and serializes them to kotlin
primitives or standards.The goal is to eventually support all features of Protobuf in Kotlin without depending on the Java library. Here is a list of features we are working on that are required to release first stable version:
And here is a list of features that we are planning to work on after the first stable release.
google.protobuf.Duration
to kotlin.time.Duration
and google.protobuf.Timestamp
to kotlinx.datetime.Instant
.
deprecated
, default
, json_name
..proto
files in the generated code.An issue to track kotlinx.serialization
: https://github.com/Kotlin/kotlinx.serialization/issues/2401
Focusing on core functionality, here is a list of known major issues:
oneof
fields are flattened and not serialized correctly.
init
block to make sure at most one
field is set. One caveat is overlapping names which we can consider later.repeated
fields with fixedXX
, sfixedXX
and uintXX
types can't be serialized.repeated
fields with sintXX
deserializes incorrectly.map
fields with fixedXX
and sfixedXX
keys can't be serialized.enum
fields with negative values can't be serialized / deserialized.ByteArray
implement equals and hashcode correctly.[!NOTE] This section is applicable to official maintainers only.
version
under root build.gradle.kts
.SONATYPE_USERNAME
, SONATYPE_PASSWORD
, GPG_SIGNING_KEY
and GPG_SIGNING_PASSPHRASE
../gradlew publishToSonatype
./gradlew findSonatypeStagingRepository closeSonatypeStagingRepository
./gradlew findSonatypeStagingRepository releaseSonatypeStagingRepository
For any errors, visit https://s01.oss.sonatype.org/#stagingRepositories.
After you release a -SNAPSHOT
version, you need the following block to import it.
repositories {
maven {
this.url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
}
For starters, start by checking issues.
There are two main components to this project. One is the code generator and the other is the generated code tests.
App.kt
. Start reading the code by inspecting the entry point, it should be fairly
straight-forward to understand../gradlew build
after you modify the code to generate the newest files. If newest files are
not committed, the CI check will fail.Linting can be done via
./gradlew ktlintFormat
Building the whole project,
./gradlew build
Check coverage of the code,
./gradlew koverHtmlReport
Please feel free to open issues and PRs.