Exemple #1
0
        /// <summary>
        /// Decode BEncoded data in the given byte array
        /// </summary>
        /// <param name="buffer">The byte array containing the BEncoded data</param>
        /// <param name="offset">The offset at which the data starts at</param>
        /// <param name="length">The number of bytes to be decoded</param>
        /// <param name="strictDecoding">Use strict decoding</param>
        /// <returns>BEncodedValue containing the data that was in the byte[]</returns>
        public static BEncodedValue Decode(byte[] buffer, int offset, int length, bool strictDecoding = true)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if ((offset < 0) || (length < 0))
            {
                throw new IndexOutOfRangeException("Neither offset or length can be less than zero");
            }

            if (offset > buffer.Length - length)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            using (MemoryStream ms = new MemoryStream(buffer, offset, length))
                using (RawReader reader = new RawReader(ms, strictDecoding))
                {
                    return(Decode(reader));
                }
        }
Exemple #2
0
 public static BEncodedDictionary DecodeMetadata(Stream s)
 {
     using (RawReader reader = new RawReader(s))
         return(DecodeMetadata(reader));
 }
Exemple #3
0
 protected override void DecodeInternal(RawReader reader)
 {
     DecodeInternal(reader, reader.StrictDecoding);
 }
Exemple #4
0
 protected abstract void DecodeInternal(RawReader reader);
Exemple #5
0
 public static T Decode <T>(RawReader reader) where T : BEncodedValue
 {
     return((T)Decode(reader));
 }