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.

41 lines
1.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace STcpHelper.Packet
{
public class STcpFileReqPacket : ISTcpPacket
{
public string Path { get; private set; }
public STcpFileReqPacket(string path)
{
this.Path = path;
}
public STcpFileReqPacket(byte[] dataBuffer)
{
int cursor = 0;
int length = SBufferHelper.ConvertBufferToDataLength(dataBuffer, cursor);
cursor += sizeof(int);
this.Path = SEncoding.GetString(dataBuffer, cursor, length);
}
public byte[] Serialize()
{
byte[] data = SEncoding.GetBytes(this.Path);
byte[] dataLength = SBufferHelper.ConvertDataLengthToBuffer(data.Length);
int dataSize = STcpPacketHeader.GetDataSize(data, dataLength);
STcpPacketHeader header = new STcpPacketHeader(PacketType.REQ_FILE, dataSize);
return SBufferHelper.GetBuffer(STcpPacketHeader.HEADER_LENGTH + dataSize, header.Serialize(), dataLength, data);
}
}
}