private static void EncodeNumber(MemoryStream buffer, long input)
 {
     buffer.Append(NumberStart);
     buffer.Append(Encoding.UTF8.GetBytes(Convert.ToString(input)));
     buffer.Append(NumberEnd);
 }
        private static void EncodeDictionary(MemoryStream buffer, Dictionary<string,object> input)
        {
            buffer.Append(DictionaryStart);

            // we need to sort the keys by their raw bytes, not the string
            var sortedKeys = input.Keys.ToList().OrderBy(x => BitConverter.ToString(Encoding.UTF8.GetBytes(x)));

            foreach (var key in sortedKeys)
            {
                EncodeString(buffer, key);
                EncodeNextObject(buffer, input[key]);
            }
            buffer.Append(DictionaryEnd);
        }
 private static void EncodeList(MemoryStream buffer, List<object> input)
 {
     buffer.Append(ListStart);
     foreach (var item in input)
         EncodeNextObject(buffer, item);
     buffer.Append(ListEnd);
 }
 private static void EncodeByteArray(MemoryStream buffer, byte[] body)
 {
     buffer.Append(Encoding.UTF8.GetBytes(Convert.ToString(body.Length)));
     buffer.Append(ByteArrayDivider);
     buffer.Append(body);
 }