2

i'm having problem while trying to set the value of the nested element in Protobuf file with Python. I have the following protobuf:

syntax = "proto3";

option java_multiple_files = true;

message OuterLayer{
    InnerLayer sim_card_data = 1;
    string version_number = 3;

    message InnerLayer{
        string iccid = 1;
        string imei = 2;
    }

In Python, i set the value by using:

raw = OuterLayer()
raw.version_number = "1.0"
raw.InnerLayer.iccid="1"
raw.InnerLayer.imei="2"

By printing the raw class print(raw) i got only:

version_number: "1"

The values of the Innerlayer seems not to be set. What am I doing wrong ? Can anybody help me ?

1 Answer 1

1

InnerLayer is the class name not the parameter name so doing the following should work

raw = OuterLayer()
raw.version_number = "1.0"
raw.sim_card_data = InnerLayer()
raw.sim_card_data.iccid = "1"
raw.sim_card_data.imei = "2"
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.