/// <summary>Writes an Int32 at the end, and advance the cursor</summary>
		/// <param name="writer">Target buffer</param>
		/// <param name="value">Signed DWORD, 32 bits, High Endian</param>
		public static void WriteInt32(ref SliceWriter writer, int value)
		{
			if (value <= 255)
			{
				if (value == 0)
				{ // zero
					writer.WriteByte(FdbTupleTypes.IntZero);
					return;
				}

				if (value > 0)
				{ // 1..255: frequent for array index
					writer.WriteByte2(FdbTupleTypes.IntPos1, (byte)value);
					return;
				}

				if (value > -256)
				{ // -255..-1
					writer.WriteByte2(FdbTupleTypes.IntNeg1, (byte)(255 + value));
					return;
				}
			}

			WriteInt64Slow(ref writer, (long)value);
		}
		/// <summary>Writes an UInt8 at the end, and advance the cursor</summary>
		/// <param name="writer">Target buffer</param>
		/// <param name="value">Unsigned BYTE, 32 bits</param>
		public static void WriteInt8(ref SliceWriter writer, byte value)
		{
			if (value == 0)
			{ // zero
				writer.WriteByte(FdbTupleTypes.IntZero);
			}
			else
			{ // 1..255: frequent for array index
				writer.WriteByte2(FdbTupleTypes.IntPos1, value);
			}
		}
		/// <summary>Writes a string encoded in UTF-8</summary>
		public static unsafe void WriteString(ref SliceWriter writer, string value)
		{
			if (value == null)
			{ // "00"
				writer.WriteByte(FdbTupleTypes.Nil);
			}
			else if (value.Length == 0)
			{ // "02 00"
				writer.WriteByte2(FdbTupleTypes.Utf8, 0x00);
			}
			else
			{
				fixed(char* chars = value)
				{
					if (!TryWriteUnescapedUtf8String(ref writer, chars, value.Length))
					{ // the string contains \0 chars, we need to do it the hard way
						WriteNulEscapedBytes(ref writer, FdbTupleTypes.Utf8, Encoding.UTF8.GetBytes(value));
					}
				}
			}
		}
		/// <summary>Writes a char array encoded in UTF-8</summary>
		internal static unsafe void WriteChars(ref SliceWriter writer, char[] value, int offset, int count)
		{
			Contract.Requires(offset >= 0 && count >= 0);

			if (count == 0)
			{
				if (value == null)
				{ // "00"
					writer.WriteByte(FdbTupleTypes.Nil);
				}
				else
				{ // "02 00"
					writer.WriteByte2(FdbTupleTypes.Utf8, 0x00);
				}
			}
			else
			{
				fixed (char* chars = value)
				{
					if (TryWriteUnescapedUtf8String(ref writer, chars + offset, count)) return;
				}
				// the string contains \0 chars, we need to do it the hard way
				WriteNulEscapedBytes(ref writer, FdbTupleTypes.Utf8, Encoding.UTF8.GetBytes(value, 0, count));
			}
		}
		/// <summary>Writes an UInt64 at the end, and advance the cursor</summary>
		/// <param name="writer">Target buffer</param>
		/// <param name="value">Signed QWORD, 64 bits, High Endian</param>
		public static void WriteUInt64(ref SliceWriter writer, ulong value)
		{
			if (value <= 255)
			{
				if (value == 0)
				{ // 0
					writer.WriteByte(FdbTupleTypes.IntZero);
				}
				else
				{ // 1..255
					writer.WriteByte2(FdbTupleTypes.IntPos1, (byte)value);
				}
			}
			else
			{ // >= 256
				WriteUInt64Slow(ref writer, value);
			}
		}