I am new to Google ProtoBuf file. I have below message in a ProtoBuf file.
message AvailabilityOfLockersResp{
uint32 NumberOfAvailableLockers;
repeated uint32 lockerIds = 1;
}
I have generated the corresponding ProtoBuf C# class using protoc.exe
and added that generated C# class file inside my .NET project file.
When I assign a value to the generated LockerIds
field I get the error "Property or indexer 'AvailabilityOfLockersResp.LockerIds' cannot be assigned to -- it is read only":
It is showing me that it's a read-only field. But, I want to assign a value to this field. How can I add things to this field?
I found an answer to my own question I asked above.
List<uint> lockerIds = new List<uint>();
ProtoPacket protoPacketResponse = new ProtoPacket
{
AvailabilityOfLockersResp = new AvailabilityOfLockersResp { NumberOfAvailableLockers = (uint)lockerIds.Count() }//LockerIds = lockerIds,
};
Outside of new instance, I have assigned the value to the LockerIds like below,
protoPacketResponse.AvailabilityOfLockersResp.LockerIds.AddRange(lockerIds);
AvailabilityOfLockersResp avail = new AvailabilityOfLockersResp();
avail.LockerIds.AddRange(new List<int>{1,2,3});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With