[protobuf] toBuilder() question and deep trees of messages

2017-07-21 Thread Laird Nelson
If I have a root object of a deep tree of objects (I'm using Java), and I 
call toBuilder() on it, so that I can manipulate it, do its "subobjects" 
"become" builders as well?

That is, if I do:

Top.Builder topBuilder = top.toBuilder();


...and then later I do:

SubObject.Builder subObjectBuilder = topBuilder.getSubObjectBuilder();


...will that subObjectBuilder be populated with the same state as 
top.getSubObject()?  And, if I use the subObjectBuilder and do mutating 
things with it, when I (finally) call topBuilder.build(), will the changes 
made via the subObjectBuilder "persist"?  Or must I manually call 
subObjectBuilder.build(), and 
topBuilder.setSubObject(resultOfSubObjectBuilderBuildCall)?  (I assume the 
build() call from topBuilder will be "propagated" "down" through the 
sub-builders.)

To ask the question in a slightly different way in case this sheds light, 
if I know that I'm going to be passing a tree of these messages around, and 
I know that I might modify certain parts of the tree, would it make sense 
to begin by calling toBuilder() on the top object first, and then writing 
my manipulation methods to accept builders of various kinds, rather than 
the immutable objects they work with?

Thanks for any help and time,
Best,
Laird

-- 
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 protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] How does this .proto file result in this generated code?

2017-07-14 Thread Laird Nelson
On Friday, July 14, 2017 at 12:41:18 PM UTC-7, Josh Humphries wrote:
>
> This code is emitted by the GRPC plugin for Java. For Go, all code gen is 
> a plugin (protoc-gen-go 
> ) and it 
> includes the GRPC functionality. For Java, the core protoc knows how to 
> emit the normal generated code, but you need the right protoc plugin 
>  to generate 
> GRPC-related Java stuff -- like service interfaces and methods for 
> registering a server implementation.
>

Thank you.  As it happens, yes, I'm using the gRPC plugin for Java 
.
 
 So maybe my question is better phrased like this:

I see that when the gRPC plugin for Go is invoked against these .proto 
sources, these methods get emitted.  I do not see evidence of these methods 
in generated Java code when I use the (analogous) gRPC plugin for Java. 
 Why not?


Thanks again for your response.

Best,
Laird

-- 
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 protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] How does this .proto file result in this generated code?

2017-07-14 Thread Laird Nelson
(I *believe* this question is about protocol buffers, and not gRPC, but I 
may be wrong.)

There is a .proto file that exists as part of the Helm project: 
https://github.com/kubernetes/helm/blob/v2.5.0/_proto/hapi/rudder/rudder.proto

As part of Helm's build process, a Go binding is generated here: 
https://github.com/kubernetes/helm/blob/v2.5.0/pkg/proto/hapi/rudder/rudder.pb.go

I had a question about this function: 
https://github.com/kubernetes/helm/blob/v2.5.0/pkg/proto/hapi/rudder/rudder.pb.go#L536

How does that function come into being given the .proto file?

For background, I've done the Java equivalent (generated bindings in Java 

 
instead of Go, off the same .proto files).  Why doesn't the analogous Java 
method show up here, given that I'm generating off the same sources?

Thanks,
Best,
Laird

-- 
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 protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] [Java] Proper way to add an item to a List?

2017-07-11 Thread Laird Nelson
On Tuesday, July 11, 2017 at 5:09:30 PM UTC-7, Feng Xiao wrote:
>
> 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:
>
> https://microbean.github.io/microbean-helm/apidocs/src-html/hapi/chart/ChartOuterClass.Chart.Builder.html#line.1680
>

You're quite right of course; not sure how I missed that.
 

> 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.
>

And I add a sub-builder by...calling...addDependenciesBuilder(), with no 
arguments.  I guess.  This all feels very, very weird.

I wish I could use the actual top-level Chart.Builder to keep track of his 
tree of dependent Chart.Builders, but it looks like without some serious 
gymnastics this will be harder than just maintaining the hierarchy by hand 
out-of-band and then adding the immutable objects in the right places. 
 This feels cumbersome, which was why I was looking for a simpler way to do 
it.  Looks like there is no simpler way to do it.  Many thanks for your 
reply.

Best,
Laird

-- 
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 protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] [Java] Proper way to add an item to a List?

2017-07-11 Thread Laird Nelson
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 
present.

I can do this via the following generated methods:
https://microbean.github.io/microbean-helm/apidocs/hapi/chart/ChartOuterClass.Chart.Builder.html#addDependencies-hapi.chart.ChartOuterClass.Chart.Builder-
 
(Adds a Chart.Builder)
https://microbean.github.io/microbean-helm/apidocs/hapi/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.

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 
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?

Thanks,
Best,
Laird

-- 
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 protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.