Search code examples
c#.netprotocol-buffersgrpcprotobuf-net

How to go from RepeatedField to a list or array?


I have a RepeatedField, which i need to Convert to a .NET List or Array.

How can this be done? Is there a better way than taking each element and putting into a new list using a forEach? This seems to be quite a performance hit when dealing with huge data sets.

Example, I want this to become a

List<string>
message keysList {
    repeated string keys = 1;
}

Solution

  • Would using protobuf-net be an option? Since it is code-first, you can do what you want:

    [ProtoContract]
    class Whatever {
        [ProtoMember(1)]
        public List<string> TheData {get;set;}
    }