/// <summary>
    /// Unsigned VarInt format
    /// </summary>
    public static void WriteUInt64(CitoStream stream, int val)
    {
        byte[] buffer = new byte[10];
        int    count  = 0;

        while (true)
        {
#if !CITO
            buffer[count] = (byte)(val & 0x7F);
#else
            buffer[count] = (val & 0x7F).LowByte;
#endif
            val = ProtoPlatform.logical_right_shift(val, 7);
            if (val == 0)
            {
                break;
            }

            buffer[count] |= 0x80;

            count += 1;
        }

        stream.Write(buffer, 0, count + 1);
    }
    /// <summary>
    /// Unsigned VarInt format
    /// </summary>
    public static void WriteUInt32_(CitoStream stream, int val)
    {
        byte[] buffer = new byte[5];
        int    count  = 0;

        while (true)
        {
#if !CITO
            buffer[count] = (byte)(val & 0x7F);
#else
            buffer[count] = (val & 0x7F).LowByte;
#endif
            val = val >> 7;
            if (val == 0)
            {
                break;
            }

            buffer[count] |= 0x80;

            count += 1;
        }

        stream.Write(buffer, 0, count + 1);
    }
    /// <summary>
    /// Unsigned VarInt format
    /// </summary>
    public static void WriteUInt64(CitoStream stream, int val)
    {
        byte[] buffer = new byte[10];
        int count = 0;

        while (true)
        {
        #if !CITO
            buffer[count] = (byte)(val & 0x7F);
        #else
            buffer[count] = (val & 0x7F).LowByte;
        #endif
            val = ProtoPlatform.logical_right_shift(val, 7);
            if (val == 0)
                break;

            buffer[count] |= 0x80;

            count += 1;
        }

        stream.Write(buffer, 0, count + 1);
    }
    /// <summary>
    /// Unsigned VarInt format
    /// </summary>
    public static void WriteUInt32_(CitoStream stream, int val)
    {
        byte[] buffer = new byte[5];
        int count = 0;

        while (true)
        {
        #if !CITO
            buffer[count] = (byte)(val & 0x7F);
        #else
            buffer[count] = (val & 0x7F).LowByte;
        #endif
            val = val >> 7;
            if (val == 0)
                break;

            buffer[count] |= 0x80;

            count += 1;
        }

        stream.Write(buffer, 0, count + 1);
    }
 /// <summary>
 /// Writes length delimited byte array
 /// </summary>
 public static void WriteBytes(CitoStream stream, byte[] val)
 {
     WriteUInt32_(stream, ProtoPlatform.ArrayLength(val));
     stream.Write(val, 0, ProtoPlatform.ArrayLength(val));
 }
 /// <summary>
 /// Writes length delimited byte array
 /// </summary>
 public static void WriteBytes(CitoStream stream, byte[] val)
 {
     WriteUInt32_(stream, ProtoPlatform.ArrayLength(val));
     stream.Write(val, 0, ProtoPlatform.ArrayLength(val));
 }