using System.Data.Common;
using System.IO;
using ActorCore;
using MessagePack;
using Server.Core;
namespace NetWorkMessage
{
///
/// 外部消息
///
[Server.Core.Message(MessageOpcode.Client2ServerMessage)]
[MessagePackObject]
public class Client2ServerMessage : RouterMessage
{
// 客户端->Router 包长度 4 5 消息体
///
/// 远端IP地址
///
[Key(0)]
public string RemoteIpAddress { get; set; }
///
/// 包序列化
///
[Key(1)]
public int OpCode { get; set; }
//
[Key(2)]
public byte ver { get; set; }
///
/// 是否压缩
///
[Key(3)]
public byte Compress { get; set; }
///
/// 源数据
///
[Key(4)]
public byte[] SourceData { get; set; }
public static Client2ServerMessage Create(string remoteIpAddress,byte ver,int opcode,byte compress,byte[] bodyData)
{
Client2ServerMessage client2ServerMessage = ReferencePool.Fetch();
client2ServerMessage.RemoteIpAddress = remoteIpAddress;
client2ServerMessage.ver = ver;
client2ServerMessage.OpCode = opcode;
client2ServerMessage.Compress = compress;
client2ServerMessage.SourceData = bodyData;
return client2ServerMessage;
}
protected override void VDispose()
{
this.RemoteIpAddress = null;
}
}
[Server.Core.Message(MessageOpcode.Server2ClientMessage)]
[MessagePackObject]
public class Server2ClientMessage : RouterMessage
{
///
/// 压缩的缓存
///
[IgnoreMember]
public readonly MemoryStream CompressStream = new MemoryStream(2048);
[IgnoreMember] public readonly MemoryStream MemoryStream = new MemoryStream(1024);
///
/// 发送数据
///
[Key(0)]
public byte[] Data;
public static Server2ClientMessage Create()
{
Server2ClientMessage message = ReferencePool.Fetch();
return message;
}
protected override void VDispose()
{
if (IsFromPool)
{
Data = null;
}
base.VDispose();
}
}
///
/// 这个不用对象池,因为执行消息可能需要异步,但是没有等待
///
[Server.Core.Message(MessageOpcode.ClientMessage)]
public class ClientMessage : MessageObject, IMessage
{
///
/// 远端ip地址
///
public string RemoteIpAddress;
///
/// 消息ID
///
public int OpCode;
///
/// 消息包体
///
public byte[] SourceData;
public static ClientMessage Create(string remoteIpAddress,int opCode, byte[] data)
{
ClientMessage message = new ClientMessage();
message.RemoteIpAddress = remoteIpAddress;
message.OpCode = opCode;
message.SourceData = data;
return message;
}
protected override void VDispose()
{
if (IsFromPool)
{
this.RemoteIpAddress = null;
this.SourceData = null;
}
}
}
}