Exemple #1
0
        public static DTLSRecord Deserialise(Stream stream)
        {
            DTLSRecord result = new DTLSRecord
            {
                _RecordType = (TRecordType)stream.ReadByte(),
                // could check here for a valid type, and bail out if invalid
                _Version        = new Version(255 - stream.ReadByte(), 255 - stream.ReadByte()),
                _Epoch          = NetworkByteOrderConverter.ToUInt16(stream),
                _SequenceNumber = NetworkByteOrderConverter.ToInt48(stream),
                _Length         = NetworkByteOrderConverter.ToUInt16(stream)
            };

            if (result._Length > 0)
            {
                result._Fragment = new byte[result._Length];
                int length = stream.Read(result._Fragment, 0, result._Length);
                while (length < result._Length)
                {
                    int bytesRead = stream.Read(result._Fragment, length, result._Length - length);
                    if (bytesRead > 0)
                    {
                        length += bytesRead;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public static DTLSRecord Deserialise(Stream stream)
        {
            DTLSRecord result = new DTLSRecord();

            result._RecordType     = (TRecordType)stream.ReadByte();
            result._Version        = new Version(255 - stream.ReadByte(), 255 - stream.ReadByte());
            result._Epoch          = NetworkByteOrderConverter.ToUInt16(stream);
            result._SequenceNumber = NetworkByteOrderConverter.ToInt48(stream);
            result._Length         = NetworkByteOrderConverter.ToUInt16(stream);
            if (result._Length > 0)
            {
                result._Fragment = new byte[result._Length];
                int length = stream.Read(result._Fragment, 0, result._Length);
                while (length < result._Length)
                {
                    length += stream.Read(result._Fragment, length, result._Length - length);
                }
            }
            return(result);
        }