protobuf-net序列化反序列化
2016-04-20 11:44
375 查看
下载:https://code.google.com/archive/p/protobuf-net/downloadsprotobuf-net
解压引入protobuf-net.dll
解压引入protobuf-net.dll
namespace ProtobufProjectTest { class Program { static void Main(string[] args) { Person person = new Person(); person.Id = 90001; person.Name = "胡汉三"; person.Addr = new Address { Line1 = "北大路", Line2 = "清华街" }; // ProtoBuf序列化 using (var file = System.IO.File.Create("Person")) { ProtoBuf.Serializer.Serialize(file, person); } // ProtoBuf反序列化 Person binPerson = null; using (var file = System.IO.File.OpenRead("Person")) { binPerson = ProtoBuf.Serializer.Deserialize<Person>(file); } Console.WriteLine(binPerson.Id); Console.WriteLine(binPerson.Name); Console.WriteLine(binPerson.Addr.Line1); Console.WriteLine(binPerson.Addr.Line2); } } } [ProtoContract] public class Address { [ProtoMember(1)] public string Line1; [ProtoMember(2)] public string Line2; } [ProtoContract] public class Person { [ProtoMember(1)] public int Id; [ProtoMember(2)] public string Name; [ProtoMember(3)] public Address Addr; }
相关文章推荐
- 关于dp转px
- 在eclipse下查看android 源码和修改查看源码的路径查看不同版本的android源码
- 湖南集训 & HNOI2016 总结
- leetcode 343. Integer Break
- iOS 禁止手势滑动翻页
- [AIR] 打包生成APK的命令行
- Xms Xmx PermSize MaxPermSize 区别
- Linux makefile 教程
- 资料整理
- 详解C语言的结构体中成员变量偏移问题
- opencv2.4.8参考手册(一) 简介
- [置顶] 2年Java web开发知识点储备
- apache mesos 入门(1)——overview
- 27. Remove Element
- SwipeRefreshLayout上拉加载
- python urllib urllib2
- 【资源汇总】Android应用解决方案全攻略
- retrofit2.0 使用笔记-文件上传功能
- 修改数据库mysql字符编码为UTF8
- Git使用教程