Пример #1
0
        public static T ReadValue <T>(ByteBuffer buffer, ValueParseBase <T> parse)
        {
            T t = default(T);

            parse.ReadValue(buffer, ref t);
            return(t);
        }
Пример #2
0
 public static void WriteArrayValue <T>(ByteBuffer buffer, T[] t, ValueParseBase <T> parse)
 {
     if (t == null || t.Length == 0)
     {
         buffer.WriteByte(0);
     }
     else
     {
         buffer.WriteByte((byte)t.Length);
         foreach (T t1 in t)
         {
             parse.WriteValue(buffer, t1);
         }
     }
 }
Пример #3
0
        public static T[] ReadArrayValue <T>(ByteBuffer buffer, ValueParseBase <T> parse)
        {
            byte length = buffer.ReadByte();

            if (length > 0)
            {
                T[] t = new T[length];
                for (int i = 0; i < length; i++)
                {
                    parse.ReadValue(buffer, ref t[i]);
                }
                return(t);
            }
            return(null);
        }
Пример #4
0
        public static Dictionary <TK, TV> ReadDictionary <TK, TV>(ByteBuffer buffer, ValueParseBase <TK> kparse,
                                                                  ValueParseBase <TV> vparse)
        {
            byte length = buffer.ReadByte();

            if (length > 0)
            {
                Dictionary <TK, TV> t = new Dictionary <TK, TV>();
                for (int i = 0; i < length; i++)
                {
                    TK k = ReadValue(buffer, kparse);
                    TV v = ReadValue(buffer, vparse);
                    t.Add(k, v);
                }
                return(t);
            }
            return(null);
        }
Пример #5
0
 public static void WriteDictionaryValue <TK, TV>(ByteBuffer buffer, Dictionary <TK, TV> t, ValueParseBase <TK> kparse, ValueParseBase <TV> vparse)
 {
     if (t == null || t.Count == 0)
     {
         buffer.WriteByte(0);
     }
     else
     {
         buffer.WriteByte((byte)t.Count);
         foreach (KeyValuePair <TK, TV> keyValuePair in t)
         {
             WriteValue(buffer, keyValuePair.Key, kparse);
             WriteValue(buffer, keyValuePair.Value, vparse);
         }
     }
 }
Пример #6
0
 public static void WriteValue <T>(ByteBuffer buffer, T t, ValueParseBase <T> parse)
 {
     parse.WriteValue(buffer, t);
 }