0

All, Apologies in advance for the novice question, but I cannot figure out how to set the value of a nested, non repeating message. For repeating message types I can define a variable as the nested message with .add() and then being setting parameters in a straight-forward fashion. For non-repeating message types though, I cannot make this work.

I have the following schema:

syntax="proto2";
package pkgName;

message OuterLayer
{
    required string thing = 1;
    message InnerLayer 
    {
        optional string otherthing = 1;

    }

I would have thought I could do something like this:

message = proto_pb2.OuterLayer()
message.InnerLayer.otherthing = "bar"

Now - this doesn't fail, but when I print the message after setting this, I do not see the contents, leading me to believe that it isn't working. For example if I set a parameter at the top level:

message.thing = "foo"

and then print this:

print(message)

I see:

"thing" : "foo"

… but not the next layer down's contents.

Any suggestions would be much appreciated.

1 Answer 1

1

Well I feel rather foolish, but it was non-obvious to me. Hopefully this helps someone else. As best I can tell, the correct way to do this is to modify my schema with an additional field:

syntax="proto2";
package pkgName;

message OuterLayer
{
    required string thing = 1;
    message InnerLayer 
    {
        optional string otherthing = 1;

    }
    optional InnerLayer innerlevel = 2;

Now that that is done, you can do as you would expect:

message.innerlevel.otherthing = "foo"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.