NetworkComms V3 序列化器之Protobuf.net和 JSONSerializer

NetworkComms v3版本中,默认使用的是protobuf.net序列化器。

即当您没有指定序列化的时候,系统自动使用默认的protobuf.net序列化器。

当然我们也可以自己指定序列化器

语法如下:

SendReceiveOptions aboveOptions = new SendReceiveOptions(DPSManager.GetDataSerializer<ProtobufSerializer>(), null, null);
使用protobuf.net 传送的类,需要添加protobuf相关的attribute,大致如下.

如果传送的类,是sql数据表相对应的实体类,可以通过模板生成  NetworkComms网络通信框架配套CodeSmith模板使用简介


using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ProtoBuf;
using EEDocManage.Data;

namespace EEDocManage.Business
{
[ProtoContract]
public class Dep
{

#region Constructors

public Dep()
{ }


#endregion

#region Private Properties

private int iD = -1;
private string title = string.Empty;

#endregion

#region Public Properties

[ProtoMember(1)]
public int ID
{
get { return iD; }
set { iD = value; }
}
[ProtoMember(2)]
public string Title
{
get { return title; }
set { title = value; }
}

#endregion

 


}

}

 

NeworkComms V3框架还自定了 JSONSerializer 序列化器(支持.net Framework 4.0版本)

使用的话只要指定一下序列化器即可

SendReceiveOptions aboveOptions = new SendReceiveOptions(DPSManager.GetDataSerializer<JSONSerializer>(), null, null);
具体的其他设置,由于我对json还不是太了解,正在探索中

www.networkComms.cn整理
---------------------
作者:networkcomms
来源:CSDN
原文:https://blog.csdn.net/networkcomms/article/details/44218197
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-06-04 10:50  DarJeely  阅读(271)  评论(0编辑  收藏  举报