No official runtimes provide a way to do this. Messages do not have
backlinks to containers if they are nested inside another message.
To do what you are trying to do would require a recursive traversal that
starts at the top (a) and then accumulates the names into a path with each
recursive call. Something like so:
func handle(msg b, path []string) {
currentPath := append(path, msg.name)
// ... do something with msg and currentPath ...
if msg.b != nil {
handle(msg.b, currentPath)
}
}
----
*Josh Humphries*
[email protected]
On Tue, Nov 22, 2022 at 8:46 AM Fred Eisele <[email protected]>
wrote:
> Given a message (b of type B), nested in another (a of type A); how does
> one get ‘a’?
> I was hoping for something like ‘b.getParent()’.
>
> message B { optional string name = 1; repeated B b = 2; }
> message A { optional string name = 1; repeated B b = 1; }
>
> Here is an example instance of an ‘a’ with textual serialization.
>
> name: "a"
> b { name: “foo”
> b { name: “fred”
> b { name: “flintstone” }}}
> b { name: “bar” }
> b { name: “baz” }
>
> The issue is that I am navigating the collection 'a' with a visitor and I
> need to be able to reconstruct a full name composed of names of all the
> ancestors.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/9ba69d16-218b-4cde-b0c9-faa651a46167n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/9ba69d16-218b-4cde-b0c9-faa651a46167n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/CAFGBEr19p2S7G1_CO0uTL5UNiGK-B29xkZqdHvLagzLA%3DvLc-Q%40mail.gmail.com.