Ejemplo n.º 1
0
 private static object ReadAndCheckNull(SimpleTypeReader simpleTypeReader)
 {
     var isNull = simpleTypeReader.Read<bool>();
     return isNull ? null : simpleTypeReader.ReadWithMark();
 }
Ejemplo n.º 2
0
        private static SimpleList<ComplexTypeDef> ReadComplexTypeDefs(SimpleTypeReader simpleTypeReader)
        {
            var complextTypeDefs = new SimpleList<ComplexTypeDef>();

            var serializedObjDefCount = simpleTypeReader.Read<int>();
            for (var i = 0; i < serializedObjDefCount; i++)
            {
                var complexTypeMark = simpleTypeReader.Read<ComplexTypeMark>();

                if (complexTypeMark == ComplexTypeMark.Array)
                {
                    #region Array

                    var id = simpleTypeReader.Read<int>();
                    var typeInfoId = simpleTypeReader.Read<int>();

                    var itemsCount = simpleTypeReader.Read<int>();
                    var items = new SimpleList<object>(itemsCount);
                    for (var j = 0; j < itemsCount; j++)
                        items.Add(ReadAndCheckNull(simpleTypeReader));

                    var indiciesCount = simpleTypeReader.Read<byte>();
                    var indicies = new SimpleList<int>(indiciesCount);
                    for (var j = 0; j < indiciesCount; j++)
                        indicies.Add(simpleTypeReader.Read<int>());

                    complextTypeDefs.Add(new ArrayDef
                    {
                        Id = id,
                        TypeInfoId = typeInfoId,
                        Items = items,
                        Indicies = indicies
                    });

                    #endregion
                }
                else if (complexTypeMark == ComplexTypeMark.List)
                {
                    #region List

                    var id = simpleTypeReader.Read<int>();
                    var typeInfoId = simpleTypeReader.Read<int>();

                    var itemsCount = simpleTypeReader.Read<int>();
                    var items = new SimpleList<object>(itemsCount);
                    for (var j = 0; j < itemsCount; j++)
                        items.Add(ReadAndCheckNull(simpleTypeReader));

                    complextTypeDefs.Add(new ListDef
                    {
                        Id = id,
                        TypeInfoId = typeInfoId,
                        Items = items
                    });

                    #endregion
                }
                else if (complexTypeMark == ComplexTypeMark.Dictionary)
                {
                    #region Dictionary

                    var id = simpleTypeReader.Read<int>();
                    var typeInfoId = simpleTypeReader.Read<int>();

                    var keysCount = simpleTypeReader.Read<int>();
                    var keys = new SimpleList<object>(keysCount);
                    for (var j = 0; j < keysCount; j++)
                        keys.Add(ReadAndCheckNull(simpleTypeReader));

                    var valuesCount = simpleTypeReader.Read<int>();
                    var values = new SimpleList<object>(valuesCount);
                    for (var j = 0; j < keysCount; j++)
                        values.Add(ReadAndCheckNull(simpleTypeReader));

                    complextTypeDefs.Add(new DictionaryDef
                    {
                        Id = id,
                        TypeInfoId = typeInfoId,
                        Keys = keys,
                        Values = values
                    });

                    #endregion
                }
                else if (complexTypeMark == ComplexTypeMark.UserDefined)
                {
                    #region UserDefined

                    var id = simpleTypeReader.Read<int>();
                    var typeInfoId = simpleTypeReader.Read<int>();

                    var namesCount = simpleTypeReader.Read<byte>();
                    var names = new SimpleList<byte>(namesCount);
                    for (var j = 0; j < namesCount; j++)
                        names.Add(simpleTypeReader.Read<byte>());

                    var valuesCount = simpleTypeReader.Read<byte>();
                    var values = new SimpleList<object>(valuesCount);
                    for (var j = 0; j < namesCount; j++)
                        values.Add(ReadAndCheckNull(simpleTypeReader));

                    complextTypeDefs.Add(new UserDefinedDef
                    {
                        Id = id,
                        TypeInfoId = typeInfoId,
                        Names = names,
                        Values = values
                    });

                    #endregion
                }
                else throw new Exception(string.Format("Unknown ComplexTypeMark {0}", complexTypeMark));
            }

            return complextTypeDefs;
        }
Ejemplo n.º 3
0
        private static SimpleList<TypeInfo> ReadTypeInfos(SimpleTypeReader simpleTypeReader)
        {
            var typeInfos = new SimpleList<TypeInfo>();
            var serializedTypeInfoCount = simpleTypeReader.Read<int>();
            for (var i = 0; i < serializedTypeInfoCount; i++)
            {
                var id = simpleTypeReader.Read<int>();
                var typeName = simpleTypeReader.Read<string>();
                var isEnumerable = simpleTypeReader.Read<bool>();
                var typeInfo = new TypeInfo
                    {
                        Id = id,
                        TypeName = typeName,
                        IsEnumerable = isEnumerable
                    };

                if (!isEnumerable)
                {
                    var propertyNamesCount = simpleTypeReader.Read<byte>();
                    var propertyNames = new SimpleList<string>(propertyNamesCount);
                    for (var j = 0; j < propertyNamesCount; j++)
                        propertyNames.Add(simpleTypeReader.Read<string>());
                    typeInfo.PropertyNames = propertyNames;
                }
                typeInfos.Add(typeInfo);
            }
            return typeInfos;
        }