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)); }
public static int WriteCompressed <T>(this BitWriter @this, T val, bool unsigned) where T : struct { return(@this.WriteCompressed(val, Marshal.SizeOf <T>() * 8, unsigned)); }
public static int WriteCompressed(this BitWriter @this, Span <byte> buf, int bits, bool unsigned) { return(@this.WriteCompressed((ReadOnlySpan <byte>)buf, bits, unsigned)); }