These are chat archives for trueaccord/ScalaPB

8th
Jun 2018
Andrea Peruffo
@andreaTP
Jun 08 11:36
GrpcRuntime generator gets configured with a Boolean, and it has to become an instance of a class
Mateusz Górski
@goral09
Jun 08 12:39
Hello :) if oneof is used then Empty case object is being generated, but this introduces a pain in the form of non-exhaustive pattern matches. In my case the Empty message can never be produced (send/received). Is it possible to tell scalapb to not generate it?
Alexander Shniperson
@AlexanderShniperson
Jun 08 13:11
@thesamet i'm somehow missed source file https://github.com/thesamet/sbt-protoc/blob/master/examples/custom-gen/project/MyGenerator.scala now generator works as i want, thanks
Nadav Samet
@thesamet
Jun 08 14:11
@goral09 no, there's no concept of required one-of in the protobuf semantics. That type of change would be more than not generating the empty case - it would require forcing a value in the constructor, and making it required by the parser.
@andreaTP try to see if it makes sense to introduce another generator? This way the original one won't break
Mateusz Górski
@goral09
Jun 08 14:48
@thesamet if I understand it correctly, there are at least 3 strategies for missing value: default, None and Empty object. Is that right?
Nadav Samet
@thesamet
Jun 08 16:13
@goral09 for one-ofs? there's just Empty for a missing value.
Mateusz Górski
@goral09
Jun 08 16:14
Yes, for oneof that's just Empty. I was referring to overall approach. Is this something that's being enforced by protobuf itself?
Nadav Samet
@thesamet
Jun 08 16:16
For proto2, a primitive field x can be either empty or set to an explicit value, which we model by using an Option[T]. If it is empty, and you call getX you will get its default value.
For proto3, a primitive field x is modeled with the bare type T. If its value is not specified in a binary message, it will get an appropriate zero value for the type. There are no default values in proto3.
Mateusz Górski
@goral09
Jun 08 16:19
Thanks for clarifying that @thesamet . much appreciated
Mateusz Górski
@goral09
Jun 08 17:54

@thesamet one last question. Why this piece of *.proto:

message Send {
    Channel chan = 1;
    …
}

generates this scala code

final case class Send(
    chan: scala.Option[Channel] = None,
   …
I want to get rid of Option
Mateusz Górski
@goral09
Jun 08 18:05
basically, everything that is not a repeated Sth becomes Option
and that's for proto3
is it intrinsic to protobuf ?
Nadav Samet
@thesamet
Jun 08 19:27
Yes, for message types in both proto2 and proto3 messages are optional and there's a distinction between a message that is unset (None), to the default instance of the message. (This is unlike primitive fields in proto3)
@goral09 , the good news are that you can get get rid of the Option by using the no_box option: https://github.com/scalapb/ScalaPB/blob/master/e2e/src/main/protobuf/no_box.proto