Ejemplo n.º 1
0
        /// <summary>
        /// Tries to read 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 bool TryPeekBits(this IBitBuffer buffer, Span <byte> destination, int bitCount)
        {
            if (!buffer.HasEnoughBits(bitCount))
            {
                return(false);
            }

            NetBitWriter.CopyBits(buffer.GetBuffer(), buffer.BitPosition, bitCount, destination, 0);
            return(true);
        }
        /// <summary>
        /// Writes a certain amount of bits from a span.
        /// </summary>
        /// <param name="bitOffset">The offset in bits into <paramref name="source"/>.</param>
        /// <param name="bitCount">The amount of bits to copy from <paramref name="source"/>.</param>
        public static void Write(this IBitBuffer buffer, ReadOnlySpan <byte> source, int bitOffset, int bitCount)
        {
            if (source.IsEmpty)
            {
                return;
            }

            buffer.EnsureEnoughBitCapacity(bitCount);
            NetBitWriter.CopyBits(source, bitOffset, bitCount, buffer.GetBuffer(), buffer.BitPosition);
            buffer.IncrementBitPosition(bitCount);
        }