Serializing an Object List Using Protobuf-net

I was looking to do binary serialization for a file, and protobuf-net seems like a good alternative. I got a little stuck in the beginning though. Since I want to separate the class definition from the actual serialization, I do not use attributes, but prefer to use .proto files, I have a structure for the object (I think)

message Post {

  required uint64 id = 1;

  required int32 userid = 2;

  required string status= 3;

  required datetime created = 4;

  optional string source= 5;

}

(is the date-time valid or should I use ticks as int64?)

but I was fixated on how to use protogen, and then serialize IEnumerable of Post into a file and read it. Any help would be appreciated

Another related question: are there any recommendations for detecting corrupt binary files, for example, if the computer is turned off during serialization

+3
1

Re DateTime... -; BCL.DateTime( ) , , protobuf-net DateTime, , -, . , , ... , "" . ...

- , Getting Started, , protobuf-net , ; IEnumerable<T> - IList<T> , ( List<T> ).

Re - , SerializeWithLengthPrefix - ​​ ( EOF). ( ) , , ( DeserializeWithLengthPrefix). , [n] / . , , / . . .

+2

Source: https://habr.com/ru/post/1724901/


All Articles