/// <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)); } }
public static BEncodedDictionary DecodeMetadata(Stream s) { using (RawReader reader = new RawReader(s)) return(DecodeMetadata(reader)); }
protected override void DecodeInternal(RawReader reader) { DecodeInternal(reader, reader.StrictDecoding); }
protected abstract void DecodeInternal(RawReader reader);
public static T Decode <T>(RawReader reader) where T : BEncodedValue { return((T)Decode(reader)); }