/// <summary> /// Attempts to parse raw data into a structured packet /// </summary> /// <param name="buffer">Raw data to parse</param> /// <param name="tag">Parsed packet</param> /// <param name="count">The length of the packet in bytes</param> /// <param name="index">The index into the buffer at which the packet begins</param> /// <returns>True if parsing was successful, false if it is not.</returns> internal static bool TryParse(byte[] buffer, int index, int count, out UnsupportedTag tag) { try { if (count < MinimumParseableBytes) { tag = null; return(false); } using (var ms = new MemoryStream(buffer, index, count, false)) { using (var br = new BinaryReader(ms)) { tag = new UnsupportedTag(); tag.TagType = br.ReadByte(); tag.TagLength = br.ReadByte(); tag.TagData = br.ReadBytes(Math.Min(tag.TagLength, count - 2)); return(true); } } } catch (Exception) { tag = null; return(false); } }
/// <summary> /// Attempts to parse raw data into a structured packet /// </summary> /// <param name="buffer">Raw data to parse</param> /// <param name="tag">Parsed packet</param> /// <param name="count">The length of the packet in bytes</param> /// <param name="index">The index into the buffer at which the packet begins</param> /// <returns>True if parsing was successful, false if it is not.</returns> internal static bool TryParse(byte[] buffer, int index, int count, out UnsupportedTag tag) { try { if (count < MinimumParseableBytes) { tag = null; return false; } using (var ms = new MemoryStream(buffer, index, count, false)) { using (var br = new BinaryReader(ms)) { tag = new UnsupportedTag(); tag.TagType = br.ReadByte(); tag.TagLength = br.ReadByte(); tag.TagData = br.ReadBytes(Math.Min(tag.TagLength, count - 2)); return true; } } } catch (Exception) { tag = null; return false; } }