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 { getset; }
        [ProtoBuf.ProtoMember(2)]        public string Name { getset; }
        [ProtoBuf.ProtoMember(3)]        public Address Address { getset; }
    }
 
    [ProtoBuf.ProtoContract]    public class Address
    {
        [ProtoBuf.ProtoMember(1)]        public string Line1 { getset; }
        [ProtoBuf.ProtoMember(2)]        public string Line2 { getset; }
    }


前加上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的更多相关文章

  1. ServiceStack.Text 更快的序列化

    Json.net 是以前最经常用的序列化组件,后来又注意到ServiceStack号称最快的,所以我做了以下测试 1)Json.net using System; using System.Colle ...

  2. Zookeeper 源码(二)序列化组件 Jute

    Zookeeper 源码(二)序列化组件 Jute 一.序列化组件 Jute 对于一个网络通信,首先需要解决的就是对数据的序列化和反序列化处理,在 ZooKeeper 中,使用了Jute 这一序列化组 ...

  3. DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer

      DjangoRestFramework学习二之序列化组件.视图组件   本节目录 一 序列化组件 二 视图组件 三 xxx 四 xxx 五 xxx 六 xxx 七 xxx 八 xxx 一 序列化组 ...

  4. cvb源码分析,resful规范,drf,drf序列化组件,95

    1 CBV的源码分析 -Class Base View(基于类的视图) -Function Base View(基于函数的视图) -def as_view 类方法 -def view:类方法内部,闭包 ...

  5. rest-framework之APIView 序列化组件

    rest-framework之APIView 一 安装djangorestframework 方式一:pip3 install djangorestframework 方式二:pycharm图形化界面 ...

  6. drf 之序列化组件

    序列化 把Python中对象转换为json格式字符串 反序列化 把json格式转为为Python对象. 用orm查回来的数据都是都是一个一个的对象, 但是前端要的是json格式字符串. 序列化两大功能 ...

  7. DRF 序列化组件

    Serializers 序列化组件 Django的序列化方法 class BooksView(View): def get(self, request): book_list = Book.objec ...

  8. python全栈开发day99-DRF序列化组件

    1.解释器组件源码分析 https://www.processon.com/view/link/5ba0a8e7e4b0534c9be0c968 2.基于CBV的接口设计 1).django循环que ...

  9. Serializers 序列化组件

    Serializers 序列化组件   为什么要用序列化组件 当我们做前后端分离的项目~~我们前后端交互一般都选择JSON数据格式,JSON是一个轻量级的数据交互格式. 那么我们给前端数据的时候都要转 ...

随机推荐

  1. 【SSH】——Hibernate实现简单的自动建表

    [与ORM] Object Relational Mapping,对象关系映射,将对象和关系联系了起来.面向对象是从耦合.聚合.封装等的基础上发展起来的,而关系数据库则是从数学理论发展而来的,两套理论 ...

  2. (转)MongoDB numa系列问题三:overcommit_memory和zone_reclaim_mode

    内核参数overcommit_memory : 它是 内存分配策略 可选值:0.1.2.0:表示内核将检查是否有足够的可用内存供应用进程使用:如果有足够的可用内存,内存申请允许:否则,内存申请失败,并 ...

  3. JQuery排错关于$(document).ready(function(){});

    最近写了好多JQuery.也出了很多问题.不知道怎么回事.程序就不往下执行了.很是郁闷. 查了下资料,这里可能会有以下几种原因:1.js文件的引用路径不正确,特别是使用了命名空间,容易造成路径错误,使 ...

  4. Codeforces Round #391 div1 757F (Dominator Tree)

    首先先膜杜教orz 这里简单说一下支配树的概念 支配树是对一个有向图来讲的 规定一个起点s,如果s到v的路径上必须经过某些点u,那么离s最近的点u就是v的支配点 在树上的关系就是,v的父亲是u. 一般 ...

  5. 利用npm安装/删除/发布/更新/撤销发布包

    利用npm安装/删除/发布/更新/撤销发布包 什么是npm? npm是javascript的包管理工具,是前端模块化下的一个标志性产物 简单地地说,就是通过npm下载模块,复用已有的代码,提高工作效率 ...

  6. [ZOJ3899]State Reversing

    [ZOJ3899]State Reversing 试题描述 Yakumo Yukari is with no doubt one of the most powerful youkai in Gens ...

  7. 【BZOJ 2744 朋友圈】

    Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 1570  Solved: 532[Submit][Status][Discuss] Descripti ...

  8. 创建dll

    在制作dll的时候,如果全局变量不导出,而函数调用中,包含了全局变量,那么会出现全局变量没有值的问题. add.c #pragma once //强制无签名utf-8 #include "a ...

  9. 第116讲 boost::algorithm::string之替换和删除

    http://www.360doc.com/content/16/0523/18/29304643_561672752.shtml

  10. Death Note

    注:本文系作者原创,但可随意转载. ********************************************************************************** ...