public void Deserialize(FileTransferProtocolPacket src) { var buffer = src.Payload.Payload; int index = 0; SequenceNumber = BitConverter.ToUInt16(buffer, index); index += 2; Session = buffer[index]; index += 1; OpCodeId = (OpCode)buffer[index]; index += 1; Size = buffer[index]; index += 1; ReqOpCodeId = (OpCode)buffer[index]; index += 1; BurstComplete = buffer[index] != 0; index += 1; Padding = buffer[index]; index += 1; Offset = BitConverter.ToUInt16(buffer, index); index += 4; Data = new byte[239]; Buffer.BlockCopy(src.Payload.Payload, 12, Data, 0, Data.Length); }
public void Serialize(FileTransferProtocolPacket dest) { using (var strm = new MemoryStream()) { using (var wrt = new StreamWriter(strm)) { wrt.Write(SequenceNumber); wrt.Write(Session); wrt.Write((byte)OpCodeId); wrt.Write(Size); wrt.Write((byte)ReqOpCodeId); wrt.Write((byte)(BurstComplete ? 1:0)); wrt.Write(Padding); wrt.Write(Offset); strm.Write(Data, 0, Data.Length); strm.Position = 0; dest.Payload.Payload = strm.ToArray(); } } }
public Task SendListDirectory(string path, ushort index, CancellationToken cancel) { var packet = new FileTransferProtocolPacket { ComponenId = _identity.ComponentId, SystemId = _identity.SystemId, Sequence = _seq.GetNextSequenceNumber(), Payload = { TargetComponent = _identity.TargetComponentId, TargetSystem = _identity.TargetSystemId, TargetNetwork = 0, } }; var ftp = new FtpMessagePayload { Size = (byte)path.Length, Offset = index, Data = Encoding.ASCII.GetBytes(path) }; return(_connection.Send(packet, cancel)); }