public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_ByteArray);
            var bytes  = (byte[])obj;
            var length = bytes.Length;

            serializerInputStream.Write(BitConverter.GetBytes(length), 0, 4);
            serializerInputStream.Write(bytes, 0, length);
        }
        public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_DataSet);
            var startLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//当前流长度占位
            var dataSet = (DataSet)obj;

            serializerInputStream.Write(dataSet.Tables.Count);
            for (int i = 0; i < dataSet.Tables.Count; i++)
            {
                SerializerFactory.Serializer(dataSet.Tables[i], serializerInputStream);
            }
            serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength);//填补流长度
        }
Beispiel #3
0
        public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_Array);
            var startLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//当前流长度占位
            serializerInputStream.Write(_type.GetElementType().FullName);
            var array = (Array)obj;

            serializerInputStream.Write(array.Length);
            foreach (var item in array)
            {
                SerializerFactory.Serializer(item, serializerInputStream);
            }
            serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength);//填补流长度
        }
        public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_DataTable);
            var startLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//当前流长度占位
            var data = (DataTable)obj;

            serializerInputStream.Write(data.TableName);
            serializerInputStream.Write(data.Columns.Count);
            for (int i = 0; i < data.Columns.Count; i++)
            {
                serializerInputStream.Write(data.Columns[i].ColumnName);
                serializerInputStream.Write(data.Columns[i].DataType.FullName);
            }
            serializerInputStream.Write(data.Rows.Count);
            for (int i = 0; i < data.Rows.Count; i++)
            {
                for (int j = 0; j < data.Columns.Count; j++)
                {
                    SerializerFactory.Serializer(data.Rows[i][j], serializerInputStream);
                }
            }
            serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength);//填补流长度
        }
        public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_Dictionary);
            var startLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//当前流长度占位
            var dic = (IDictionary)obj;

            serializerInputStream.Write(_type.FullName);
            serializerInputStream.Write(dic.Count);
            var enumerator = dic.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializerFactory.Serializer(enumerator.Key, serializerInputStream);
                SerializerFactory.Serializer(enumerator.Value, serializerInputStream);
            }
            serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength);//填补流长度
        }
Beispiel #6
0
        public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
        {
            serializerInputStream.Write(SerializerUtil.Byte_Enumerable);
            var startLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//当前流长度占位
            serializerInputStream.Write(_type.FullName);
            var count         = 0;
            var enumerable    = (IEnumerable)obj;
            var enumerator    = enumerable.GetEnumerator();
            var currentLength = serializerInputStream.Length;

            serializerInputStream.Write(0);//总个数占位
            while (enumerator.MoveNext())
            {
                count++;
                SerializerFactory.Serializer(enumerator.Current, serializerInputStream);
            }
            serializerInputStream.UpdateCurrentLength(count, currentLength);                                        //填补数量
            serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength); //填补流长度
        }
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_Object);
     if (obj == null)
     {
         serializerInputStream.Write(ByteUtil.ZeroLengthBytes);
         serializerInputStream.Write(ByteUtil.EmptyBytes);
     }
     else
     {
         var startLength = serializerInputStream.Length;
         serializerInputStream.Write(0);//当前流长度占位
         serializerInputStream.Write(_type.FullName);
         var fieldList = _type.GetRpcFieldList();
         if (fieldList != null && fieldList.Any())
         {
             foreach (var fieldInfo in fieldList)
             {
                 var fieldValue = fieldInfo.GetValue(obj);
                 if (fieldValue != null)
                 {
                     serializerInputStream.Write(fieldInfo.Name);
                     SerializerFactory.Serializer(fieldValue, serializerInputStream);
                 }
             }
         }
         serializerInputStream.UpdateCurrentLength(serializerInputStream.Length - startLength - 4, startLength);//填补流长度
     }
 }
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_TimeSpan);
     serializerInputStream.Write(ByteUtil.EncodeTimeSpan((TimeSpan)obj));
 }
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_Float);
     serializerInputStream.Write(BitConverter.GetBytes((float)obj));
 }
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_String);
     serializerInputStream.Write((String)obj);
 }
Beispiel #11
0
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_DateTime);
     serializerInputStream.Write(ByteUtil.EncodeDateTime((DateTime)obj));
 }
Beispiel #12
0
 public override void WriteBytes(object obj, SerializerInputStream serializerInputStream)
 {
     serializerInputStream.Write(SerializerUtil.Byte_Enum);
     serializerInputStream.Write(_type.FullName);
     serializerInputStream.Write(Convert.ToInt32(((Enum)obj).ToString("d")));
 }