I am using scalapb in a project that needs to have access to the FileDescriptorSet. Is there a way to have scalapb generate the .desc file in addition to all other class files? Or is there some programatic way of obtaining a FileDescriptorSet from what is already generated?
Generate file descriptor set (.desc) with scalapb
720 views Asked by James Matlik At
1
Yes, to both questions.
If you are using
sbt-protoc
, you can have the following definition in your SBT file:One caveat is that you would have to create
src/main/resources
yourself, otherwise you would get an error. It would probably be better to generate intoresourceManaged
(that would also require creating a directory ahead of time, sinceprotoc
doesn't do that)You can also build a FileDescriptorSet at run time. For each proto file, ScalaPB generates a Scala object with
scalaDescriptor
(and alsojavaDescriptor
if that's more convenient). The descriptors contains a list of their dependencies which are alsoFileDesciptor
s - you can traverse that tree structure and build a list ofFileDescriptor
s which is essentially aFileDescriptorSet
.