using System.IO;

public static class BinaryWriterExtensions
{
	public static void WriteSIntVar(this BinaryWriter writer, long value)  
	{  
		var sign = value < 0 ? -1 : 0;
		ulong num = (ulong)(value * sign);
		
		writer.Write((byte)(num & 0x3fu) | (sign < 0 ? 0x40u : 0u) | (num >= 0x40u ? 0x80u : 0));
		num >>= 6;
		
		while (num >= 128U)  
		{  
			writer.Write((byte) (num | 128U));  
			num >>= 7;  
		}  
	}
	
	public static void WriteUIntVar(this BinaryWriter writer, ulong value)  
	{  
		ulong num = value;
		
		while (num >= 128U)  
		{  
			writer.Write((byte) (num | 128U));  
			num >>= 7;  
		}  
		
		writer.Write((byte) num);  
	}
	
	public static void Write7BitEncodedInt(this BinaryWriter writer, int value)
	{
		var workValue = value;
		
		do
		{
			byte writeByte = (byte)(workValue & 0x7f);
			workValue >>= 7;
			if(workValue != 0)
			{
				writeByte |= 0x80;
			}
			writer.Write(writeByte);
		} while(workValue != 0);
	}}