public byte[] ToByteArray() { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(Encoding.ASCII.GetBytes(PacketType)); buffer.WriteInteger(TransferID); return(buffer.ToArray()); }
public byte[] ToByteArray() { PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(Encoding.ASCII.GetBytes(PacketType)); buffer.WriteString(PacketText); return(buffer.ToArray()); }
public byte[] ToByteArray() { byte[] data = new byte[8]; PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(Encoding.ASCII.GetBytes(PacketType)); buffer.WriteBytes(BitConverter.GetBytes(PacketNumber)); buffer.WriteBytes(BitConverter.GetBytes(TransferID)); return(buffer.ToArray()); }
/// <summary> /// Creates a ScoutResponsePacket given a NetworkDevice structure /// </summary> /// <param name="device"></param> public ScoutResponsePacket(NetworkDevice device) { PacketType = "_SCA"; PacketBuffer buffer = new PacketBuffer(); buffer.WriteString(device.Name); buffer.WriteByte((byte)device.Type); PacketData = buffer.ToArray(); }
public TransferRequestPacket(LocalFileStructure fStruct, int localID) { PacketBuffer buffer = new PacketBuffer(); buffer.WriteInteger(localID); buffer.WriteLong(fStruct.FileSize); buffer.WriteString(fStruct.FileName); buffer.WriteString(fStruct.FileExtension); PacketData = buffer.ToArray(); PacketType = "_TFR"; }
/// <summary> /// Serializes the packet into a byte array for sending /// </summary> /// <returns></returns> public byte[] ToByteArray() { if (PacketData == null) { return(null); } PacketBuffer buffer = new PacketBuffer(); buffer.WriteBytes(Encoding.ASCII.GetBytes(PacketType)); buffer.WriteBytes(PacketData); return(buffer.ToArray()); }
private void ProcessFinishedFile() { // Create the byte buffer and include it in the OnTransferFinished event PacketBuffer buffer = new PacketBuffer(); for (int i = 0; i < ReceivedChunks.Count; i++) { buffer.WriteBytes(ReceivedChunks[i].Data); } byte[] fileBuffer = buffer.ToArray(); OnTransferFinished?.Invoke(null, new InboundTransferEventArgs(TransferID, true, fileBuffer, IncomingFileStructure)); fileBuffer = null; ReceivedChunks = null; }