using System;
using System.Collections.Generic;
using System.Text;
namespace Madpet.Network.ProtoBuff
{
enum ProtoBufDataType
{
INT = 0,
STRING,
}
[AttributeUsage(AttributeTargets.Field)]
class ProtoBuffFieldAttribute : System.Attribute
{
public int mId;
public ProtoBufDataType mFieldType;
public ProtoBuffFieldAttribute(int id, ProtoBufDataType field_type)
{
mId = id;
mFieldType = field_type;
}
}
using System.Collections.Generic;
using System.Text;
namespace Madpet.Network.ProtoBuff
{
enum ProtoBufDataType
{
INT = 0,
STRING,
}
[AttributeUsage(AttributeTargets.Field)]
class ProtoBuffFieldAttribute : System.Attribute
{
public int mId;
public ProtoBufDataType mFieldType;
public ProtoBuffFieldAttribute(int id, ProtoBufDataType field_type)
{
mId = id;
mFieldType = field_type;
}
}
}
using System;
namespace Madpet.Network.ProtoBuff
{
public class LoginRequest
{
[ProtoBuffFieldAttribute(1, ProtoBufDataType.STRING)]
public string userName;
[ProtoBuffFieldAttribute(2, ProtoBufDataType.STRING)]
public string passWordMd5;
}
}

本文介绍了一种基于ProtoBuf的数据序列化方式在网络通信中的应用。通过定义枚举类型ProtoBufDataType和属性ProtoBuffFieldAttribute来指定字段类型及ID,实现了LoginRequest类中用户名和密码MD5值的标记。
732

被折叠的 条评论
为什么被折叠?



