Example #1
0
        public static DataTable DeserializeDataTable(BinaryTypesReader br)
        {
            DataTable table = new DataTable();

            table.TableName = br.ReadString();

            int columnCount = br.Read7BitInt();

            Type[] columnTypes = new Type[columnCount];

            for (int i = 0; i < columnCount; i++)
            {
                string columnName = br.ReadString();
                string typeName   = br.ReadString();
                Type   columnType = Type.GetType(typeName);

                DataColumn col = new DataColumn(columnName, columnType);
                table.Columns.Add(col);

                columnTypes[i] = columnType;
            }

            int rowsCount = br.Read7BitInt();

            for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++)
            {
                DataRow row = table.NewRow();
                table.Rows.Add(row);

                for (int i = 0; i < columnCount; i++)
                {
                    if (columnTypes[i] == typeof(System.String))
                    {
                        row[i] = br.ReadString();
                    }
                    else if (columnTypes[i] == typeof(System.Int32))
                    {
                        row[i] = br.Read7BitInt();
                    }
                    else if (columnTypes[i] == typeof(System.Int64))
                    {
                        row[i] = br.Read7BitLong();
                    }
                    else if (columnTypes[i] == typeof(System.Decimal))
                    {
                        row[i] = br.ReadCompactDecimal();
                    }
                    else if (columnTypes[i] == typeof(System.DateTime))
                    {
                        row[i] = br.ReadCompactDateTime(TimeSpan.TicksPerMillisecond * 100);
                    }
                    else if (columnTypes[i] == typeof(bool))
                    {
                        row[i] = br.ReadBoolean();
                    }
                }
            }

            return(table);
        }
Example #2
0
        ///////////////////////////////////////////////////////////////////////

        public static long ReadLong(BinaryTypesReader br, object objParam)
        {
            return(br.Read7BitLong());
        }
Example #3
0
        ///////////////////////////////////////////////////////////////////////

        // Uses reflection - relatively slow!!!
        public static T ReadEnum <T>(BinaryTypesReader br, object objParam) where T : IConvertible
        {
            long val = br.Read7BitLong();

            return((T)Enum.ToObject(typeof(T), val));
        }
        private static object DeserializeObject(BinaryTypesReader br, Type type)
        {
            if (type.IsPrimitive)
            {
                switch (type.FullName)
                {
                case SystemTypeDefs.FullNameBoolean:
                case SystemTypeDefs.FullNameByte:
                case SystemTypeDefs.FullNameSByte:
                case SystemTypeDefs.FullNameInt16:
                case SystemTypeDefs.FullNameUInt16:
                case SystemTypeDefs.FullNameInt32:
                case SystemTypeDefs.FullNameUInt32:
                case SystemTypeDefs.FullNameInt64:
                case SystemTypeDefs.FullNameUInt64:
                case SystemTypeDefs.FullNameChar:
                {
                    var val = br.Read7BitLong();
                    return(Convert.ChangeType(val, type));
                }

                case SystemTypeDefs.FullNameSingle:     // todo: compact
                    return(br.ReadSingle());

                case SystemTypeDefs.FullNameDouble:     // todo: compact
                    return(br.ReadDouble());
                }
            }

            if (type.FullName == typeof(decimal).FullName)
            {
                return(br.ReadCompactDecimal());
            }

            if (type.IsEnum)
            {
                int val = (int)br.Read7BitLong();
                return(Enum.ToObject(type, val));
            }

            if (type.IsValueType)
            {
                switch (type.FullName)
                {
                case SystemTypeDefs.FullNameDateTime:
                    return(new DateTime(br.Read7BitLong()));
                }
            }

            if (type.IsClass)
            {
                switch (type.FullName)
                {
                case SystemTypeDefs.FullNameString:
                    return(br.ReadString());

                default:
                    return(DeserializeClass(br, type));
                }
            }

            return(null);
        }