码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-03-10 07:53:53      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

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 V3 序列化器之Protobuf.net和 JSONSerializer

标签:

原文地址:http://www.cnblogs.com/networkcomms/p/4324983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!