Ejemplo n.º 1
0
        public void benNumberLengthInBytes()
        {
            int            number = 1635;
            BEncodedNumber num    = number;

            Assert.AreEqual(number.ToString().Length + 2, num.LengthInBytes());
        }
Ejemplo n.º 2
0
        public void benNumberEncoding()
        {
            byte[]         data   = Encoding.UTF8.GetBytes("i12345e");
            BEncodedNumber number = 12345;

            Assert.IsTrue(data.AsSpan().SequenceEqual(number.Encode()));
        }
Ejemplo n.º 3
0
        public void benNumberEncoding5()
        {
            byte[]         data   = Encoding.UTF8.GetBytes("i-123e");
            BEncodedNumber number = -123;

            Assert.AreEqual(6, number.LengthInBytes());
            Assert.IsTrue(data.AsSpan().SequenceEqual(number.Encode()));
        }
Ejemplo n.º 4
0
        public void benNumberEncodingBuffered()
        {
            byte[]         data   = Encoding.UTF8.GetBytes("i12345e");
            BEncodedNumber number = 12345;

            byte[] result = new byte[number.LengthInBytes()];
            number.Encode(result);
            Assert.IsTrue(data.AsSpan().SequenceEqual(result));
        }
Ejemplo n.º 5
0
        public void benNumber_MaxMin([Values(long.MinValue, long.MaxValue)] long value)
        {
            var number = new BEncodedNumber(value);

            foreach (var result in BEncodedValue.DecodingVariants <BEncodedNumber> (number.Encode()))
            {
                Assert.AreEqual(result.Number, value);
            }
        }
Ejemplo n.º 6
0
        public void benNumberEncoding6()
        {
            BEncodedNumber a = -123;

            foreach (var b in BEncodedValue.DecodingVariants <BEncodedNumber> (a.Encode()))
            {
                Assert.AreEqual(a.Number, b.Number, "#1");
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Decode BEncoded data in the given RawReader
        /// </summary>
        /// <param name="reader">The RawReader containing the BEncoded data</param>
        /// <returns>BEncodedValue containing the data that was in the stream</returns>
        public static BEncodedValue Decode(RawReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            BEncodedValue data;

            switch (reader.PeekByte())
            {
            case ('i'):                             // Integer
                data = new BEncodedNumber();
                break;

            case ('d'):                             // Dictionary
                data = new BEncodedDictionary();
                break;

            case ('l'):                             // List
                data = new BEncodedList();
                break;

            case ('1'):                             // String
            case ('2'):
            case ('3'):
            case ('4'):
            case ('5'):
            case ('6'):
            case ('7'):
            case ('8'):
            case ('9'):
            case ('0'):
                data = new BEncodedString();
                break;

            default:
                throw new BEncodingException("Could not find what value to decode");
            }

            data.DecodeInternal(reader);
            return(data);
        }
Ejemplo n.º 8
0
 public void Add(BEncodedNumber item)
 {
     this.list.Add(item);
 }
Ejemplo n.º 9
0
 public void Add(BEncodedString key, BEncodedNumber value)
 {
     this.dictionary.Add(key, value);
 }