最快的序列化组件protobuf的.net版本protobuf.net
Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法。它比xml格式要少的多,甚至比二进制数据格式也小的多。
     Protobuf格式协议和xml一样具有平台独立性,可以在不同平台间通信,通信所需资源很少,并可以扩展,可以旧的协议上添加新数据
    
 Protobuf是在java和c++运行的,Protobuf-net当然就是Protobuf在.net环境下的移植。
通过一些网友测试发现,protobuf是目前最快的序列化组件,并且序列化之后内容的体积也是最小的,比ServiceStack.Text、
NewtonSoft.Json都快,秒杀.net自带的XML,Binary的序列化。
Get Start
[ProtoBuf.ProtoContract] public class Person
{
[ProtoBuf.ProtoMember()] public int Id { get; set; }
[ProtoBuf.ProtoMember()] public string Name { get; set; }
[ProtoBuf.ProtoMember()] public Address Address { get; set; }
} [ProtoBuf.ProtoContract] public class Address
{
[ProtoBuf.ProtoMember()] public string Line1 { get; set; }
[ProtoBuf.ProtoMember()] public string Line2 { get; set; }
}
最快的序列化组件protobuf的.net版本protobuf.net
Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法。它比xml格式要少的多,甚至比二进制数据格式也小的多。
     Protobuf格式协议和xml一样具有平台独立性,可以在不同平台间通信,通信所需资源很少,并可以扩展,可以旧的协议上添加新数据
    
 Protobuf是在java和c++运行的,Protobuf-net当然就是Protobuf在.net环境下的移植。
通过一些网友测试发现,protobuf是目前最快的序列化组件,并且序列化之后内容的体积也是最小的,比ServiceStack.Text、
NewtonSoft.Json都快,秒杀.net自带的XML,Binary的序列化。
Get Start
[ProtoBuf.ProtoContract]    public class Person    {        [ProtoBuf.ProtoMember(1)]        public int Id { get; set; }        [ProtoBuf.ProtoMember(2)]        public string Name { get; set; }        [ProtoBuf.ProtoMember(3)]        public Address Address { get; set; }    }    [ProtoBuf.ProtoContract]    public class Address    {        [ProtoBuf.ProtoMember(1)]        public string Line1 { get; set; }        [ProtoBuf.ProtoMember(2)]        public string Line2 { get; set; }    } | 
类
前加上ProtoContract Attrbuit,成员加上ProtoMember
Attribute即可,其中ProtoMember需要一个大于0的int类型的值,原则上这个int类型没有大小限制,但建议从1开始,这是一个良好
的习惯,另外这个参数必需是这个类成员的唯一标识,不可重复
序列化
var person = new Person
{
Id = ,
Name = "First",
Address = new Address { Line1 = "Line1", Line2 = "Line2" }
}; using (var file = System.IO.File.Create("Person.bin"))
{
ProtoBuf.Serializer.Serialize(file, person);
}
相关资料请参考开源地址:https://github.com/mgravell/protobuf-net
最快的序列化组件protobuf的.net版本protobuf.net的更多相关文章
- ServiceStack.Text 更快的序列化
		
Json.net 是以前最经常用的序列化组件,后来又注意到ServiceStack号称最快的,所以我做了以下测试 1)Json.net using System; using System.Colle ...
 - Zookeeper 源码(二)序列化组件 Jute
		
Zookeeper 源码(二)序列化组件 Jute 一.序列化组件 Jute 对于一个网络通信,首先需要解决的就是对数据的序列化和反序列化处理,在 ZooKeeper 中,使用了Jute 这一序列化组 ...
 - DjangoRestFramework学习二之序列化组件、视图组件 serializer  modelserializer
		
DjangoRestFramework学习二之序列化组件.视图组件 本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...
 - cvb源码分析,resful规范,drf,drf序列化组件,95
		
1 CBV的源码分析 -Class Base View(基于类的视图) -Function Base View(基于函数的视图) -def as_view 类方法 -def view:类方法内部,闭包 ...
 - rest-framework之APIView 序列化组件
		
rest-framework之APIView 一 安装djangorestframework 方式一:pip3 install djangorestframework 方式二:pycharm图形化界面 ...
 - drf 之序列化组件
		
序列化 把Python中对象转换为json格式字符串 反序列化 把json格式转为为Python对象. 用orm查回来的数据都是都是一个一个的对象, 但是前端要的是json格式字符串. 序列化两大功能 ...
 - DRF 序列化组件
		
Serializers 序列化组件 Django的序列化方法 class BooksView(View): def get(self, request): book_list = Book.objec ...
 - python全栈开发day99-DRF序列化组件
		
1.解释器组件源码分析 https://www.processon.com/view/link/5ba0a8e7e4b0534c9be0c968 2.基于CBV的接口设计 1).django循环que ...
 - Serializers 序列化组件
		
Serializers 序列化组件 为什么要用序列化组件 当我们做前后端分离的项目~~我们前后端交互一般都选择JSON数据格式,JSON是一个轻量级的数据交互格式. 那么我们给前端数据的时候都要转 ...
 
随机推荐
- oracle约束条件
			
约束条件有5种 非空约束(not null):约束该列一定要输入值 主关键字约束(primary key):用来唯一标示表中的一个列,一个表中的主键约束只能有一个 外关键字约束(foreign key ...
 - IIS 发布后无法连接数据库(应用池问题)
			
查找网站对应的 应用池,修改为 .net4.0 然后设置启动32位应用程序为 True
 - 在C/C++函数中使用可变参数
			
原文链接地址:http://blog.csdn.net/djinglan/article/details/8425768 下面介绍在C/C++里面使用的可变参数函数. 先说明可变参数是什么,先回顾一下 ...
 - [Leetcode] Reorder list 重排链表
			
Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You ...
 - [Leetcode] search a 2d matrix 搜索二维矩阵
			
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
 - JavaScript的大括号的语义
			
Javascript中大括号"{}"有四种语义作用: 语义1. 组织复合语句,这是最常见的: view source print? 1 if( condition ) { 2 ...
 - POJ3169:Layout(差分约束)
			
Layout Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15705 Accepted: 7551 题目链接:http ...
 - ionic改tab文字和icon图片的颜色
			
The official way would be: Change in your theme/variables.scss Active icon for tabs on android is: $ ...
 - Django请求原理
			
总结一下: 1. 进来的请求转入/hello/. 2. Django通过在ROOT_URLCONF配置来决定根URLconf. 3. Django在URLconf中的所有URL模式中,查找第一个匹配/ ...
 - Android 实现对图片 Exif 的修改(Android 自带的方法)
			
很多时候我们都要对我们的图片信息进行一些处理,比如向图片中写入经纬度,拍摄时间,设备信息,作者等等. 这个时候我们就要对我们的图片Exif进行写入信息的操作,当然,我们想知道图片的Exif信息,也可以 ...