> I wish I could pass a builder object to a method and have the method
> modify either a value of the builder or a value of a sub-message in
> the builder!
>
> I came across this thread, which described exactly the problem I have.
> The Car/Engine example in the thread is perfectly illustrative of my
> scenario.
>
> http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0
>
> Has anyone else been in this same situation? What have you done to
> ameliorate the problem?
Generally speaking, I use non-PB model objects as my primary in-memory
representation, and then I serialize them on demand to get the PB
representation when I need it. For instance, something like:
public class Engine {
private String make;
private double volumeLiters;
public EnginePb serialize() {
return
EnginePb.newBuilder().setMake(make).setVolumeLiters(volumeLiters).build();
}
}
public class Car {
private Engine engine;
private String make;
private String name;
public CarPb serialize() {
return
CarPb.newBuilder().setMake(make).setName(name).setEngine(engine.serialize()).build();
}
}
- Adam
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.