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.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace STcpHelper.Packet
|
|
|
|
|
{
|
|
|
|
|
internal class SBufferHelper
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|