Пример #1
0
        public override void Decode(byte[] buffer, int offset, int length)
        {
            using (var reader = new RawReader(new MemoryStream(buffer, offset, length, false), false))
            {
                var d = BEncodedValue.Decode<BEncodedDictionary>(reader);

                BEncodedValue val;
                if (d.TryGetValue(MessageTypeKey, out val))
                    MetadataMessageType = (eMessageType) ((BEncodedNumber) val).Number;
                if (d.TryGetValue(PieceKey, out val))
                    Piece = (int) ((BEncodedNumber) val).Number;
                if (d.TryGetValue(TotalSizeKey, out val))
                {
                    var totalSize = (int) ((BEncodedNumber) val).Number;
                    MetadataPiece = new byte[Math.Min(totalSize - Piece*BlockSize, BlockSize)];
                    reader.Read(MetadataPiece, 0, MetadataPiece.Length);
                }
            }
        }
Пример #2
0
 internal abstract void DecodeInternal(RawReader reader);
Пример #3
0
 /// <summary>
 /// </summary>
 /// <param name="reader"></param>
 internal override void DecodeInternal(RawReader reader)
 {
     DecodeInternal(reader, reader.StrictDecoding);
 }
Пример #4
0
 public static T Decode <T>(RawReader reader) where T : BEncodedValue
 {
     return((T)Decode(reader));
 }