using SObject; using STcpHelper.Utility; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace STcpHelper.Packet { public class STcpZooResPacket : ISTcpPacket { private ISSerializer _serializer = new SJsonSerializerHelper(); public Zoo Zoo { get; private set; } public STcpZooResPacket(Zoo zoo) { this.Zoo = zoo; } public STcpZooResPacket(byte[] dataBuffer) { int cursor = 0; int length = SBufferHelper.ConvertBufferToDataLength(dataBuffer, cursor); cursor += sizeof(int); string serialized = SEncoding.GetString(dataBuffer, cursor, length); this.Zoo = _serializer.Deserialize(serialized); } public byte[] Serialize() { string serialized = _serializer.Serialize(this.Zoo); byte[] data = SEncoding.GetBytes(serialized); byte[] dataLength = SBufferHelper.ConvertDataLengthToBuffer(data.Length); int dataSize = STcpPacketHeader.GetDataSize(data, dataLength); STcpPacketHeader header = new STcpPacketHeader(PacketType.RES_ZOO, dataSize); return SBufferHelper.GetBuffer(STcpPacketHeader.HEADER_LENGTH + dataSize, header.Serialize(), dataLength, data); } } }