Home / Companies / StackHawk / Blog / Post Details
Content Deep Dive

Kotlin & Protobuf Tips & Tricks

Blog post from StackHawk

Post Details
Company
Date Published
Author
Topher Lamey
Word Count
706
Language
English
Hacker News Points
-
Summary

StackHawk has successfully utilized Kotlin with Protobuf, leveraging Java classes in its Kotlin code, but with Kotlin now a first-class language for the protoc compiler, the company is transitioning to Kotlin-generated classes. The Protobuf Gradle Plugin supports Kotlin, though not by default, and can be configured to do so for non-GRPC Kotlin. Adding Kotlin extension functions to proto messages allows for consistent and efficient field construction, exemplified by creating URL fields for alerts using extension functions or custom builder classes. Additionally, converting Protobuf objects to and from JSON is facilitated through extension functions, which simplify JSON handling and allow for easy serialization and deserialization of proto messages' collections. This approach avoids unnecessary proto message creation and enhances data manipulation capabilities within Kotlin projects. The complete code and configuration are available on GitHub.