Exemple #1
0
 public override object ReadObject(GaeaStream inStream, Type defType)
 {
     byte[] head = new byte[5];
     inStream.SafeRead(head, 0, 5);
     int isRef = head.ToByte(0);
     int hashcode = head.ToInt32(1);
     if (isRef > 0)
     {
         object o = inStream.GetRef(hashcode);
         if (o == null)
             return string.Empty;
         if (!(o is string))
             throw new Exception("Type error!");
         return o;
     }
     int len = inStream.ReadInt32();
     if (len == 0)
     {
         inStream.SetRef(hashcode, string.Empty);
         return string.Empty;
     }
     byte[] buffer = new byte[len];
     inStream.SafeRead(buffer, 0, len);
     string str = inStream.Encoder.GetString(buffer);
     inStream.SetRef(hashcode, str);
     return str;
 }
Exemple #2
0
 public override object ReadObject(GaeaStream inStream,Type defType)
 {
     byte[] buffer = new byte[BYTE_LEN];
     inStream.SafeRead(buffer, 0, BYTE_LEN);
     if (defType == typeof(UInt64))
         return buffer.ToInt64(0);
     else
         return buffer.ToInt64(0);
 }
Exemple #3
0
 public override object ReadObject(GaeaStream inStream, Type defType)
 {
     byte[] buffer = new byte[BYTE_LEN];
     inStream.SafeRead(buffer, 0, BYTE_LEN);
     return GetDateTime(buffer);
 }
Exemple #4
0
 public override object ReadObject(GaeaStream inStream,Type defType)
 {
     byte[] buffer = new byte[BYTE_LEN];
     inStream.SafeRead(buffer, 0, BYTE_LEN);
     return buffer.ToChar(0);
 }
Exemple #5
0
 public override object ReadObject(GaeaStream inStream,Type defType)
 {
     uint typeId = inStream.ReadUInt32();
     if (typeId == 0)
         return null;
     byte isRef = (byte)inStream.ReadByte();
     int hashCode = inStream.ReadInt32();
     if (isRef > 0)
     {
         return inStream.GetRef(hashCode);
     }
     int len = inStream.ReadInt32();
     Type type = typeId.ToType();
     if (type == typeof(byte))
     {
         byte[] buffer = new byte[len];
         inStream.SafeRead(buffer, 0, len);
         return buffer;
     }
     if (type.IsGenericType)
     {
         type = GenericHelper.GetRealGenType(type, defType.GetElementType());
     }
     var array = Array.CreateInstance(type, len);
     if (!type.IsPrimitive)
     {
         for (int i = 0; i < len; i++)
         {
             var itemTypeId = inStream.ReadUInt32();
             if (itemTypeId == 0)
             {
                 array.SetValue(null, i);
             }
             else
             {
                 Type itemType = itemTypeId.ToType();
                 var value = SerializerFactory.GetSerializer(itemType).ReadObject(inStream, defType.GetElementType());
                 array.SetValue(value, i);
             }
         }
     }
     else
     {
         for (int i = 0; i < len; i++)
         {
             var value = SerializerFactory.GetSerializer(type).ReadObject(inStream,defType.GetElementType());
             array.SetValue(value, i);
         }
     }
     inStream.SetRef(hashCode, array);
     return array;
 }
Exemple #6
0
 public override object ReadObject(GaeaStream inStream,Type defType)
 {
     var typeId = inStream.ReadUInt32();
     if (typeId == 0)
         return null;
     byte isRef = (byte)inStream.ReadByte();
     int hashcode = inStream.ReadInt32();
     if (isRef > 0)
     {
         return inStream.GetRef(hashcode);
     }
     var type = typeId.ToType();
     if (type == null)
     {
         throw new NotFindTypeException("Type id can't convert to type !typeId:" + typeId);
     }
     if (type != typeof(IDictionary))
     {
         throw new TypeNoMatchException("Type must be IDictionary!type:" + type.FullName);
     }
     if (!defType.IsAbstract && !defType.IsInterface && typeof(IDictionary).IsAssignableFrom(defType))
     {
         type = defType;
     }
     else
     {
         if (defType.IsGenericType)
         {
             type = typeof(Dictionary<,>).MakeGenericType(defType.GetGenericArguments());
         }
         else
         {
             type = typeof(Hashtable);
         }
         if (!defType.IsAssignableFrom(type))
         {
             throw new TypeNoMatchException("Defind type and value type not match !defind type:" + defType.FullName + ",value type:" + type.FullName);
         }
     }
     var len = inStream.ReadInt32();
     IDictionary obj = (IDictionary)Activator.CreateInstance(type, true);
     Type[] gtypes = null;
     if (type.IsGenericType)
     {
         gtypes = type.GetGenericArguments();
     }
     for (int i = 0; i < len; i++)
     {
         var keyTypeId = inStream.ReadUInt32();
         var keyType = keyTypeId.ToType();
         var dkeyType = keyType;
         if (type.IsGenericType)
         {
             dkeyType = gtypes[0];
         }
         object key = SerializerFactory.GetSerializer(keyTypeId.ToType()).ReadObject(inStream, dkeyType);
         byte[] valueTypeBuffer = new byte[4];
         inStream.SafeRead(valueTypeBuffer, 0, 4);
         var valueTypeId = valueTypeBuffer.ToUInt32(0);
         if (valueTypeId == 0)
         {
             obj[key] = null;
         }
         else
         {
             var valueType = valueTypeId.ToType();
             var dvalueType = valueType;
             if (type.IsGenericType)
                 dvalueType = gtypes[1];
             object value = SerializerFactory.GetSerializer(valueTypeId.ToType()).ReadObject(inStream, dvalueType);
             obj[key] = value;
         }
     }
     inStream.SetRef(hashcode, obj);
     return obj;
 }