streem / pbandk

Kotlin Code Generator and Runtime for Protocol Buffers
MIT License
270 stars 37 forks source link

Custom Well-Known-Type support #247

Open Dogacel opened 1 year ago

Dogacel commented 1 year ago

Add plugin support to write custom well-known types.

I think this feature would make pbandk much more convenient for some use-cases. For example we would like to use java.time.Instant instead of wkt.Timestamp.

We have some custom types such as UUID we would like to convert it to java.util.UUID.

I am trying to understand how this works: https://github.com/streem/pbandk/blob/120f51ba6ec7eeecc85d29242841d7011670005c/protoc-gen-pbandk/lib/src/commonMain/kotlin/pbandk/gen/Main.kt#L36-L44

How can we modify this bit to inject custom WKTs?

garyp commented 1 year ago

I've actually got a huge rewrite of pbandk internals in progress that would make this much simpler to implement (the rewrite is for #217). It's been slow going, but hopefully I can get that up for review sometime soon. With the rewrite in place, we'll have a foundation for defining custom adapters per-type (e.g. use kotlin.time.Duration instead of pbandk.wkt.Duration for all google.protobuf.Duration messages) and per-field (e.g. use java.util.UUID instead of kotlin.String for a specific string field that is used to hold a UUID). Supporting this use case is an explicit goal of the rewrite (along with its primary purpose of adding support for builders) as it's something we'd like to have at Streem too.

Dogacel commented 1 year ago

I've actually got a huge rewrite of pbandk internals in progress that would make this much simpler to implement (the rewrite is for #217). It's been slow going, but hopefully I can get that up for review sometime soon. With the rewrite in place, we'll have a foundation for defining custom adapters per-type (e.g. use kotlin.time.Duration instead of pbandk.wkt.Duration for all google.protobuf.Duration messages) and per-field (e.g. use java.util.UUID instead of kotlin.String for a specific string field that is used to hold a UUID). Supporting this use case is an explicit goal of the rewrite (along with its primary purpose of adding support for builders) as it's something we'd like to have at Streem too.

That sounds amazing, it is exactly what we need.

Dogacel commented 1 year ago

Hi @garyp. I don't see any releases since last year November. Are there any updates on the progress of Pb and K?