protected static void WriteUnified(Stream stream, long value)
{
// note: need to use string version "${len}\r\n{data}\r\n", not intger version ":{data}\r\n"
// when this is part of a multi-block message (which unified *is*)
if (value >= 0 && value <= 99)
{ // low positive integers are very common; special-case them
int i = (int)value;
if (i <= 9)
{
stream.Write(oneByteIntegerPrefix, 0, oneByteIntegerPrefix.Length);
stream.WriteByte((byte)((int)'0' + i));
}
else
{
stream.Write(twoByteIntegerPrefix, 0, twoByteIntegerPrefix.Length);
stream.WriteByte((byte)((int)'0' + (i / 10)));
stream.WriteByte((byte)((int)'0' + (i % 10)));
}
}
else
{
// not *quite* as efficient, but fine
var bytes = Encoding.ASCII.GetBytes(value.ToString());
stream.WriteByte((byte)'$');
WriteRaw(stream, bytes.Length);
stream.Write(bytes, 0, bytes.Length);
}
stream.Write(Crlf, 0, 2);
}