Minsoo Cheong
03/07/2024, 8:54 AMJohann Pardanaud
03/07/2024, 10:40 AMMinsoo Cheong
03/08/2024, 2:02 AMhas~()
functions instead. And when you want to assign null to a Protobuf field, it's not as straightforward as you might hope.
Here's a quick example to illustrate:
// Defining a Protobuf message
message person {
optional string hobby = 1;
}
// Assigning a value
personKt = person {
hobby = "climbing"
}
// Null check
if (person.hasHobby()) {
// Do something
}
// Null assignment
val someHobby: String? = null
newPerson = person {
if (someHobby == null) {
hobby = someHobby
}
}
This can get really cumbersome, especially when you're converting between your domain classes and Protobufs, because you can't directly assign null values to fields. But with krotoDC, this issue is a thing of the past since Protobuf fields are nullable from the get-go.
There are also other perks to using krotoDC, like being able to use Java/Kotlin official types, like LocalDateTime
, instead of Protobuf types like Timestamp
or oneof
sealed types, and so on. It's a bit more flexible and less frustrating to work with.Johann Pardanaud
03/08/2024, 5:11 PM