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); } } }
internal abstract void DecodeInternal(RawReader reader);
/// <summary> /// </summary> /// <param name="reader"></param> internal override void DecodeInternal(RawReader reader) { DecodeInternal(reader, reader.StrictDecoding); }
public static T Decode <T>(RawReader reader) where T : BEncodedValue { return((T)Decode(reader)); }