Reputation: 345
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 ?
Upvotes: 2
Views: 1582
Reputation: 878
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"
Upvotes: 1