/// <summary>
        /// Returns a NetworkDevice object containing the information included in the packet.
        /// </summary>
        /// <returns></returns>
        public NetworkDevice GetNetworkDevice()
        {
            // The packet data needs to be at least 6 bytes long. Strings in the packetbuffer class are saved with a
            // 4-bytes integer for the lenght, and then the string itself
            if (PacketData == null || PacketData.Length < 6)
            {
                return(null);
            }

            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(PacketData);

            NetworkDevice device = new NetworkDevice();

            device.Name     = buffer.ReadString();
            device.Type     = (NetworkDeviceType)buffer.ReadByte();
            device.EndPoint = PacketEndPoint;
            buffer.Dispose();

            return(device);
        }
예제 #2
0
        /// <summary>
        /// Returns a FileStructure object containing the information
        /// </summary>
        /// <returns></returns>
        public LocalFileStructure GetFileStructure()
        {
            if (PacketData == null || PacketData.Length < 12)
            {
                return(null);
            }

            PacketBuffer buffer = new PacketBuffer();

            buffer.WriteBytes(PacketData);

            LocalFileStructure fStruct = new LocalFileStructure();

            buffer.ReadInteger(); // Ignore the local ID
            fStruct.FileSize      = buffer.ReadLong();
            fStruct.FileName      = buffer.ReadString();
            fStruct.FileExtension = buffer.ReadString();
            fStruct.FullName      = fStruct.FileName + fStruct.FileExtension;

            buffer.Dispose();

            return(fStruct);
        }