private static bool CheckHead(BinaryAPIReader reader, bool endOfHead) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } byte[] data = reader.ReadBytes(3); return(Enumerable.SequenceEqual(data, endOfHead ? _HEAD_END : _HEAD_START)); }
public static byte[] ReadHeader(BinaryAPIReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (!CheckHead(reader, false)) { return(Array.Empty <byte>()); } int headerDataLength = reader.ReadInt(); byte[] headerData = reader.ReadBytes(headerDataLength); if (!CheckHead(reader, true)) { return(Array.Empty <byte>()); } return(headerData); }