Update Network

Update Network
This commit is contained in:
ALEXTANG
2023-05-19 17:01:04 +08:00
parent 4bc63fafc8
commit ec409c7e15
5 changed files with 64 additions and 11 deletions

View File

@@ -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>
/// 比特流解析。