2

Is it possible to have protogen output multiple files (one per class) based on a single .proto file?

I'm working with a very large .proto file that outputs approx 200 classes, currently all in a single file. One of the places where I need to use the generated classes is in a highly memory constrained environment (a Windows Phone background agent).

I'd like to be able to only include the necessary classes in the assembly loaded in the constrained environment but can't easily do this when the generated classes are all in a single file. If I could have them outputted to multiple files I could only link in the ones I need in the assembly for the constrained environment.

Is there a way to have protogen output the classes in separate files? I can't see an option for this and am currently only using the umbrella-classname option.

Manually editing the generated file is not an option so if protogen can't do it, is there another commandline tool available which can split up a file containing multiple classes? (To save reinventing the wheel.)

Update
I'm using Google.ProtocolBuffers.dll an inherited decision and not easily changable.
Editing/splitting the .proto file is also not a posibility. (Unless as a custom step.)

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143

1 Answers1

0

We have an option for this in csharp_options, but it's not implemented:

// Whether to generate a single file for everything within the
// .proto file (false), or one file per message (true).
// This option is not currently honored; please log a feature
// request if you really want it.
optional bool multiple_files = 4;

Given that you'd have to remove relevant files and make sure you got all the dependencies right it sounds like it wouldn't actually save you much work over the solution I'd suggest, which is to split your proto file into separate ones You say this is "also not a possibility" but basically that's all I can suggest at the moment - why is it not a possibility?

EDIT: I've just had another idea. You could potentially run the protoc step of protogen (which is now done automatically if you don't specify otherwise) to parse the .proto file into its descriptor. Then load the descriptor in another program, mutate it as you would any other protobuf message (create a builder from it, edit the message, build) and then save the descriptor. You can then use protogen on the remaining descriptor, and generate only the classes you want...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks for the feedback Jon. The .proto file is generated externally and so can't be split at the point of creation. I'll experiment with scripting the splitting of the files prior to calling protogen. – Matt Lacey Apr 12 '12 at 13:15
  • @MattLacey: If you have a set of messages you're interested in "keeping", I'd expect it to be *reasonably* straightforward to find and keep those. – Jon Skeet Apr 12 '12 at 13:30
  • @MattLacey: Just had a less text-based idea - see my edit. That *should* be feasible... – Jon Skeet Apr 12 '12 at 13:31