Exemplo n.º 1
0
        public static int WriteCompressed(this BitWriter @this, ReadOnlySpan <byte> buf, int bits, bool unsigned)
        {
            for (var i = (bits >> 3) - 1; i > 0; i--)
            {
                var flag = buf[i] == (unsigned ? 0x00 : 0xFF);

                @this.WriteBit(flag);

                if (flag)
                {
                    continue;
                }

                return(@this.Write(buf, (i + 1) << 3));
            }

            var flag2 = (buf[0] & 0xF0) == (unsigned ? 0x00 : 0xF0);

            @this.WriteBit(flag2);

            return(@this.Write(buf.Slice(0, 1), flag2 ? 4 : 8));
        }
Exemplo n.º 2
0
 public static int WriteCompressed <T>(this BitWriter @this, T val, bool unsigned) where T : struct
 {
     return(@this.WriteCompressed(val, Marshal.SizeOf <T>() * 8, unsigned));
 }
Exemplo n.º 3
0
 public static int WriteCompressed(this BitWriter @this, Span <byte> buf, int bits, bool unsigned)
 {
     return(@this.WriteCompressed((ReadOnlySpan <byte>)buf, bits, unsigned));
 }