mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update Network
Update Network
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameProto;
|
||||
using Google.Protobuf;
|
||||
|
||||
|
||||
@@ -9,6 +11,8 @@ using Google.Protobuf;
|
||||
/// </summary>
|
||||
public partial class ProtobufUtility
|
||||
{
|
||||
private const int BufferHead = 4;
|
||||
|
||||
/// <summary>
|
||||
/// 消息压入内存流。
|
||||
/// </summary>
|
||||
@@ -28,6 +32,20 @@ public partial class ProtobufUtility
|
||||
{
|
||||
((IMessage)message).WriteTo(stream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消息压入内存流。
|
||||
/// </summary>
|
||||
/// <param name="packet"></param>
|
||||
/// <param name="stream"></param>
|
||||
public static void ToStreamWithHead(CSPkg packet, MemoryStream stream)
|
||||
{
|
||||
byte[] data = packet.ToByteArray();
|
||||
byte[] head = BitConverter.GetBytes(data.Length);
|
||||
byte[] ret = head.Concat(data).ToArray();
|
||||
stream.Write(ret);
|
||||
((MemoryStream)stream).SetLength(BufferHead + data.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 比特流解析。
|
||||
|
Reference in New Issue
Block a user