You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.0 KiB
91 lines
2.0 KiB
/*
|
|
Sog 游戏基础库
|
|
2016 by zouwei
|
|
*/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace Sog
|
|
{
|
|
/// <summary>
|
|
/// Request message package
|
|
/// </summary>
|
|
public class RequestPacket
|
|
{
|
|
/// <summary>
|
|
/// init
|
|
/// </summary>
|
|
public RequestPacket(int msgId, long objectId, uint serverId)
|
|
{
|
|
MsgID = msgId;
|
|
ObjectID = objectId;
|
|
ServerID = serverId;
|
|
ReceiveTime = DateTime.Now;
|
|
}
|
|
|
|
public int MsgID { get; protected set; }
|
|
public long ObjectID { get; protected set; }
|
|
public uint ServerID { get; protected set; }
|
|
public object Message { get; set; }
|
|
public DateTime ReceiveTime { get; protected set; }
|
|
}
|
|
|
|
public class StructPacket
|
|
{
|
|
public MessageHeader Header;
|
|
public ProtoCSStruct.IStructMessageParser Parser;
|
|
|
|
public int MsgID
|
|
{
|
|
get
|
|
{
|
|
return Header.Type;
|
|
}
|
|
}
|
|
|
|
public long ObjectID
|
|
{
|
|
get
|
|
{
|
|
return Header.ObjectID;
|
|
}
|
|
}
|
|
|
|
public uint ServerID
|
|
{
|
|
get
|
|
{
|
|
return Header.ServerID;
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return Parser.GetMessageString();
|
|
}
|
|
|
|
public string MessageName()
|
|
{
|
|
return Parser.GetMessageName();
|
|
}
|
|
|
|
//得到结构体的引用,用的时候千万别忘了加ref, 否则 会进行整个结构体拷贝,效率很低
|
|
public ref T GetMessage<T>() where T : struct , ProtoCSStruct.IStructMessage<T>
|
|
{
|
|
return ref ((ProtoCSStruct.StructMessageParser<T>)Parser).GetMessage();
|
|
}
|
|
|
|
public StructPacket Clone()
|
|
{
|
|
var clonePacket = new StructPacket();
|
|
clonePacket.Header = this.Header;
|
|
|
|
clonePacket.Parser = Parser.Clone();
|
|
|
|
return clonePacket;
|
|
}
|
|
}
|
|
}
|