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.

45 lines
1.2 KiB

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
2 years ago
using System.Text;
using System.Threading.Tasks;
2 years ago
using STcpHelper.Packet;
2 years ago
2 years ago
namespace STcpHelper.Utility
2 years ago
{
2 years ago
internal class SBufferHelper
2 years ago
{
public static byte[] GetBuffer(int size, params byte[][] args)
{
byte[] bytes = new byte[size];
int cursor = 0;
for (int i = 0; i < args.Length; i++)
{
byte[] data = args[i];
Array.Copy(data, 0, bytes, cursor, data.Length);
cursor += data.Length;
}
return bytes;
}
public static byte[] ConvertPacketTypeToBuffer(PacketType packetType)
{
2 years ago
return BitConverter.GetBytes(IPAddress.HostToNetworkOrder((int)packetType));
}
public static byte[] ConvertDataLengthToBuffer(int dataLength)
{
return BitConverter.GetBytes(IPAddress.HostToNetworkOrder(dataLength));
}
public static int ConvertBufferToDataLength(byte[] dataBuffer, int cursor)
{
return IPAddress.NetworkToHostOrder(BitConverter.ToInt32(dataBuffer, cursor));
}
2 years ago
}
}