On Tue, Jul 11, 2017 at 4:53 PM, Laird Nelson <ljnel...@gmail.com> wrote:
> I hope this is the right group.
> I've generated a Java API for Helm's Tiller using gRPC and protocol
> buffers. You can see the javadocs here: https://microbean.
> github.io/microbean-helm/apidocs/index.html Look at the hapi.* packages.
> As I'm working with the generated API, I need to add one kind of thing to
> another thing's list of such things.
> Specifically (and arbitrarily) I need to add a (sub-) Chart.Builder to a
> (top-level) Chart.Builder's "dependencies", only if it isn't already
> I can do this via the following generated methods:
> hapi.chart.ChartOuterClass.Chart.Builder- (Adds a Chart.Builder)
> chart/ChartOuterClass.Chart.Builder.html#addDependenciesBuilder-- (I
> don't know what this does.)
> It seems from looking at the generated source code that if I call build()
> on the "top level" Chart.Builder, it will cascade to the Chart.Builders
> present in the return value of getDependenciesBuilderList() and call
> build() on them too.
Actually you can't add a sub-builder to another builder. If you look at the
implementation of addDependencies(Builder), it just calls builder.build()
right away and add the resulted Chart object:
You can instead get a sub-builder out from an existing builder, by calling
the getFieldBuilder() method, e.g., getDependenciesBuilder(int). This
sub-builder you get is "owned" by the parent builder and they are
cross-referenced: if you call build() on the parent builder, it will
recursively call build() on all its sub-builders; if you change the
sub-builder, its parent builder will get notified for the change.
> I also need to add a Chart.Builder only if it isn't present already.
> When I tried to implement this logic, I found that no Chart.Builder added
> is equal to any other Chart.Builder. That is, there doesn't seem to be the
> ability to check for a Chart.Builder "in" another Chart.Builder's list of
I think you can have some kind of id field in your Chart message and use
that to check whether a Chart is already added in dependencies?
> Finally at the end of all this, I call build() on the top-level
> Chart.Builder and expect it to produce a Chart with some subcharts in its
> dependencies. Should I in fact expect this?
> Now I feel like I have the semantics about these generated methods all
> wrong. Is there a better walkthrough than https://developers.
> google.com/protocol-buffers/docs/javatutorial? Is there a standard way
> for assembling an object graph out of connected builders?
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to email@example.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.