https://kotlinlang.org logo
#grpc
Title
# grpc
d

davec

06/27/2022, 9:05 PM
as an example how would I build this?
Copy code
message DateRange {
  // The beginning of the date range
  google.type.Date from = 1 [(validate.rules).message.required = true];

  // The end of the date range
  google.type.Date until = 2 [(validate.rules).message.required = true];
}
The generated class isn't particularly helpful:
message has been deleted
d

Dariusz Kuc

06/27/2022, 9:24 PM
by default, you would use
grpc-java
way of using builders
Copy code
DateRange.newBuilder()
  // set your fields using their builders
  .build()
if you use the
grpc-kotlin
then you should be able to use the generated DSL which should be something among the lines
Copy code
dateRange {
  from = ...
  unti = ...
}
d

davec

06/27/2022, 9:29 PM
Thanks, the second one seems to be the right path, but now I have to figure out how to create a
com.google.type.Date
; doesn't seem to use the DSL syntax and none of the constructors appear to be the right approach, but maybe I'm missing one
Wait I think I have it:
Copy code
val dateRange = dateRange {
            from = newBuilder().setDay(7).setMonth(7).setYear(2022).build()
            until = newBuilder().setDay(12).setMonth(7).setYear(2022).build()
        }
I guess what I don't get it when I'm supposed to be using the DSL syntax like
dateRange { ... }
instead of the other builder syntax
d

Dariusz Kuc

06/27/2022, 9:32 PM
I'd imagine you should also have
Copy code
date {
  day = 7
  month = 7
  year = 2022
}
*unless google protos are treated in some custom special way
d

davec

06/27/2022, 9:33 PM
yeah that doesn't seem to work, unfortunately
m

Marc Plano-Lesay

06/28/2022, 5:40 AM
I suspect this comes down to your build system and how Google's protos are built by it
You'll need to run the Kotlin proto compiler on them to get those DSL "factories"
12 Views