Protobuf C#

// ProtoBuf序列化
            using(var file = System.IO.File.Create("Person.bin"))
            {
                ProtoBuf.Serializer.Serialize(file, person);
            }

            // ProtoBuf反序列化
            Person binPerson = null;
            using(var file = System.IO.File.OpenRead("Person.bin"))
            {
                binPerson = ProtoBuf.Serializer.Deserialize<Person>(file);
            }

  1.  //将数据序列化后存入本地文件  
  2.         using(Stream file = File.Create(PATH))  
  3.         {  
  4.             Serializer.Serialize<List<Test>>(file, testData);  
  5.             file.Close();  
  6.         }  
  7.         //将数据从文件中读取出来,反序列化  
  8.         List<Test> fileData;  
  9.         using (Stream file = File.OpenRead(PATH))  
  10.         {  
  11.             fileData = Serializer.Deserialize<List<Test>>(file);  
  12.         }
  13. //Serializing Data
                using (var file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    Serializer.Serialize<Person>(file, person);
                }
                //Deserializing Data
                Person newPerson;
                using (var file = File.OpenRead(fileName))
                {
                    newPerson = Serializer.Deserialize<Person>(file);
                }
posted on 2015-05-05 17:33  武胜-阿伟  阅读(427)  评论(0编辑  收藏  举报