コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>
        /// Writes bytes from a span.
        /// </summary>
        public static void Write(this IBitBuffer buffer, ReadOnlySpan <byte> source)
        {
            if (!buffer.IsByteAligned())
            {
                buffer.Write(source, 0, source.Length * 8);
                return;
            }

            buffer.EnsureEnoughBitCapacity(source.Length * 8);
            source.CopyTo(buffer.GetBuffer().AsSpan(buffer.BytePosition));
            buffer.IncrementBitPosition(source.Length * 8);
        }
コード例 #3
0
 /// <summary>
 /// Write a <see cref="byte"/>.
 /// </summary>
 public static void Write(this IBitBuffer buffer, byte value)
 {
     buffer.EnsureEnoughBitCapacity(8);
     NetBitWriter.WriteByte(value, 8, buffer.GetBuffer(), buffer.BitPosition);
     buffer.IncrementBitPosition(8);
 }
コード例 #4
0
 /// <summary>
 /// Writes a <see cref="bool"/> value using 1 bit.
 /// </summary>
 public static void WriteBit(this IBitBuffer buffer, bool value)
 {
     buffer.EnsureEnoughBitCapacity(1);
     NetBitWriter.WriteByte(value ? (byte)1 : (byte)0, 1, buffer.GetBuffer(), buffer.BitPosition);
     buffer.IncrementBitPosition(1);
 }
コード例 #5
0
 /// <summary>
 /// Writes a <see cref="byte"/> using 1 to 8 bits.
 /// </summary>
 public static void Write(this IBitBuffer buffer, byte source, int bitCount)
 {
     buffer.EnsureEnoughBitCapacity(bitCount, maxBitCount: 8);
     NetBitWriter.WriteByte(source, bitCount, buffer.GetBuffer(), buffer.BitPosition);
     buffer.IncrementBitPosition(bitCount);
 }