示例#1
0
        /// <summary>
        /// Reads the specified number of bits,
        /// between one and <paramref name="maxBitCount"/>,
        /// without advancing the read position.
        /// </summary>
        /// <param name="destination">The destination span.</param>
        /// <param name="bitCount">The number of bits to read.</param>
        /// <param name="maxBitCount">The maximum amount of bits to read.</param>
        public static void PeekBits(this IBitBuffer buffer, Span <byte> destination, int bitCount, int maxBitCount)
        {
            Debug.Assert(bitCount >= 1);
            Debug.Assert(bitCount <= maxBitCount);

            buffer.TryPeekBits(destination, bitCount);
        }
示例#2
0
 /// <summary>
 /// Reads the specified number of bits without advancing the read position.
 /// </summary>
 /// <param name="destination">The destination span.</param>
 /// <param name="bitCount">The number of bits to read.</param>
 public static void Peek(this IBitBuffer buffer, Span <byte> destination, int bitCount)
 {
     if (!buffer.TryPeekBits(destination, bitCount))
     {
         throw new EndOfMessageException();
     }
 }
示例#3
0
        /// <summary>
        /// Tries to read the specified number of bytes without advancing the read position.
        /// </summary>
        /// <param name="destination">The destination span.</param>
        public static bool TryPeek(this IBitBuffer buffer, Span <byte> destination)
        {
            if (!buffer.IsByteAligned())
            {
                return(buffer.TryPeekBits(destination, destination.Length * 8));
            }

            if (!buffer.HasEnoughBits(destination.Length))
            {
                return(false);
            }

            buffer.GetBuffer().AsSpan(buffer.BytePosition, destination.Length).CopyTo(destination);
            return(true);
        }