示例#1
0
 /// <summary>
 /// Decode BEncoded data in the given stream
 /// </summary>
 /// <param name="stream">The stream containing the BEncoded data</param>
 /// <returns>BEncodedValue containing the data that was in the stream</returns>
 public static T Decode <T>(Stream stream) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(stream));
 }
示例#2
0
 public static T Decode <T>(RawReader reader) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(reader));
 }
示例#3
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>
 /// <returns>BEncodedValue containing the data that was in the byte[]</returns>
 public static T Decode <T>(byte[] buffer, int offset, int length) where T : BEncodedValue
 {
     return(BEncodedValue.Decode <T>(buffer, offset, length, true));
 }
示例#4
0
 public static T Decode <T>(byte[] buffer, int offset, int length, bool strictDecoding) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(buffer, offset, length, strictDecoding));
 }
示例#5
0
 public static T Clone <T> (T value)
     where T : BEncodedValue
 {
     Check.Value(value);
     return((T)BEncodedValue.Decode(value.Encode()));
 }
示例#6
0
 /// <summary>
 /// Interface for all BEncoded values
 /// </summary>
 /// <param name="data">The byte array containing the BEncoded data</param>
 /// <returns></returns>
 public static T Decode <T>(byte[] data) where T : BEncodedValue
 {
     return((T)BEncodedValue.Decode(data));
 }
示例#7
0
        public void DecodeDictionary_MissingTrailingE()
        {
            string benString = "d1:a1:b";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
示例#8
0
        public void DecodeString_TooShort()
        {
            string benString = "5:test";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
示例#9
0
        public void DecodeString_NoColon()
        {
            string benString = "12";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
示例#10
0
        public void DecodeNumber_InvalidDigit()
        {
            string benString = "i123$21e";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString)));
        }
示例#11
0
        public void DecodeDictionary_OutOfOrder_Strict()
        {
            string benString = "d1:b1:b1:a1:ae";

            Assert.Throws <BEncodingException> (() => BEncodedValue.Decode(Encoding.UTF8.GetBytes(benString), true));
        }