For this python program running protobuf encoding when encoded gives following output:
0a 10 08 7f 8a 01 04 08 02 10 03 92 01 04 08 02 10 03 18 01
What I don't understand is why there is a 01 after 8a, and again why 01 after 92. Seems for information element of type oneof, extra 01 is added, but why? Please help me, if any body understands protobuf encoding
import sys
import test2_pb2
def write_to_file(file,value):
with open(file, "wb") as f:
f.write(value)
def cell_test_dct():
msg=test2_pb2.TestPrimM();
msg.textx=1
msg.testmsg.testint=127
msg.testmsg.prbbundlingtype.x =2
msg.testmsg.prbbundlingtype.static=
test2_pb2.BUNDLE_SIZE_N_4_WIDEBAND
msg.testmsg.bundlingtype.x =2
msg.testmsg.bundlingtype.static=
test2_pb2.BUNDLE_SIZE_N_4_WIDEBAND
print (msg)
str = msg.SerializeToString()
#write_to_file("/tmp/protobuf_test_file.bin",str)
def main_test():
cell_test_dct()
main_test()
For the following protobuf file :
package NR_TEST;
enum BundleSizeE {
BUNDLE_SIZE_N_4 = 0;
BUNDLE_SIZE_WIDEBAND = 1;
BUNDLE_SIZE_N_2_WIDEBAND = 2;
BUNDLE_SIZE_N_4_WIDEBAND = 3;
}
message DynamicBundleSizesM {
// bundleSizeSet1
optional BundleSizeE bundleSizeSet1 = 1;
// bundleSizeSet2
optional BundleSizeE bundleSizeSet2 = 2;
}
message PrbBundlingTypeM {
optional uint32 x=1;
oneof BundlingTypeC {
BundleSizeE static = 2;
DynamicBundleSizesM dynamic = 3;
}
}
message Test {
required int32 testint =1;
required PrbBundlingTypeM prbbundlingtype = 17;
required PrbBundlingTypeM bundlingtype = 18;
}
message TestPrimM
{
oneof TestMsgC {
Test testmsg=1;
int32 nomsg=2;
}
required int32 textx=3;
}