Example #1
0
        public BinaryStruct GetSchemeData(string schemeName, Encoding coding, TypeStorage currentStorage)
        {
            var s = new BinaryStruct(Type, schemeName, PropertyList, coding, currentStorage);

            s.Compile();
            return(s);
        }
Example #2
0
 public static void CompileWriter(BinaryStruct bs, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local buffer, GroboIL.Local offset, GroboIL.Local typeSize)
 {
     if (bs.PropertyList.Count > 0)
     {
         foreach (var item in bs.PropertyList)
         {
             ProcessWrite(item, bs, il, binaryStruct, value, buffer, offset, typeSize);
         }
         return;
     }
 }
Example #3
0
        private List <PropertyData> FillPropertyes(BinaryStruct old, List <PropertyData> propertyList)
        {
            List <PropertyData> result = old.PropertyList.ToList();

            PropertyData tempPropData = null;

            foreach (var item in propertyList)
            {
                if ((tempPropData = result.FirstOrDefault(x => x.PropertyInfo.Name == item.PropertyInfo.Name)) == null)
                {
                    result.Add(item);
                }
                else
                {
                    if (tempPropData.BinaryAttr.Type != item.BinaryAttr.Type)
                    {
                        throw new Exception($"Cannot fill property \"{tempPropData.PropertyInfo.Name}\" in struct {Type} because of old binary type ({tempPropData.BinaryAttr.Type}) not compared new type ({item.BinaryAttr.Type})");
                    }

                    if (tempPropData.BinaryAttr.ArraySize != item.BinaryAttr.ArraySize)
                    {
                        throw new Exception($"Cannot fill property \"{tempPropData.PropertyInfo.Name}\" in struct {Type} because of old array size ({tempPropData.BinaryAttr.ArraySize}) not compared new array size ({item.BinaryAttr.ArraySize})");
                    }

                    if (tempPropData.BinaryAttr.ArraySizeName != item.BinaryAttr.ArraySizeName)
                    {
                        throw new Exception($"Cannot fill property \"{tempPropData.PropertyInfo.Name}\" in struct {Type} because of old array size name ({tempPropData.BinaryAttr.ArraySizeName}) not compared new array size name ({item.BinaryAttr.ArraySizeName})");
                    }


                    if (tempPropData.BinaryAttr.TypeSize != item.BinaryAttr.TypeSize)
                    {
                        throw new Exception($"Cannot fill property \"{tempPropData.PropertyInfo.Name}\" in struct {Type} because of old type size ({tempPropData.BinaryAttr.TypeSize}) not compared new type size ({item.BinaryAttr.TypeSize})");
                    }

                    if (tempPropData.BinaryAttr.TypeSizeName != item.BinaryAttr.TypeSizeName)
                    {
                        throw new Exception($"Cannot fill property \"{tempPropData.PropertyInfo.Name}\" in struct {Type} because of old type size name ({tempPropData.BinaryAttr.TypeSizeName}) not compared new type size name ({item.BinaryAttr.TypeSizeName})");
                    }

                    foreach (var scheme in item.BinarySchemeAttrList)
                    {
                        if (tempPropData.BinarySchemeAttrList.Exists(x => x.SchemeName == scheme.SchemeName))
                        {
                            continue;
                        }
                        tempPropData.BinarySchemeAttrList.Add(scheme);
                    }
                }
            }

            return(result);
        }
Example #4
0
        private void LoadType(Type type, int initialSize)
        {
            List <PropertyData> t = GetProperties(type);
            var s = new BinaryStruct(type, "", t.ToList(), Coding, this);

            TypeCacheMap[type].TryAdd("", s);
            s.InitLen = initialSize;

            foreach (var item in t)
            {
                if (!item.IsBaseType)
                {
                    item.BinaryStruct = CheckExist(item.BinaryAttr.Type);
                }
            }
            //s.Compile();
        }
Example #5
0
        public static void ProcessWrite(PropertyData item, BinaryStruct bs, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local value, GroboIL.Local buffer, GroboIL.Local offset, GroboIL.Local typeSize)
        {
            if (!string.IsNullOrEmpty(item.BinaryAttr?.ArraySizeName))
            {
                item.ArraySizeProperty = bs.PropertyList.Find(x => x.PropertyInfo.Name == item.BinaryAttr.ArraySizeName);
                if (item.ArraySizeProperty == null)
                {
                    throw new Exception($"ArraySizeProperty \"{item.BinaryAttr.ArraySizeName}\" for {item.PropertyInfo.Name} in Struct {bs.Type}:{item.PropertyInfo.DeclaringType} not found(Scheme: {bs.Scheme})");
                }
            }
            if (!string.IsNullOrEmpty(item.BinaryAttr?.TypeSizeName))
            {
                item.TypeSizeProperty = bs.PropertyList.Find(x => x.PropertyInfo.Name == item.BinaryAttr.TypeSizeName);
                if (item.TypeSizeProperty == null)
                {
                    throw new Exception($"TypeSizeProperty \"{item.BinaryAttr.TypeSizeName}\" for {item.PropertyInfo.Name} in Struct {bs.Type}:{item.PropertyInfo.DeclaringType} not found(Scheme: {bs.Scheme})");
                }
            }

            if (item.IsBaseType)
            {
                item.BinaryType.GetWriteILCode(item, bs, il, binaryStruct, value, typeSize, buffer, offset, false);
                return;
            }

            var methodBreak = il.DefineLabel("breakWriteMethod");

            var in_value = il.DeclareLocal(item.PropertyInfo.PropertyType);

            //значение вложенного класса
            il.Ldloc(value);
            il.Call(item.PropertyInfo.GetGetMethod());
            il.Stloc(in_value);

            WriteSizeChecker(il, buffer, offset, 2);

            WriteObjectNull(il, methodBreak, in_value, buffer, offset, typeSize);

            CompileWriter(item.BinaryStruct, il, binaryStruct, in_value, buffer, offset, typeSize);

            il.MarkLabel(methodBreak);
            //il.Pop();
        }
Example #6
0
        public static void CompileReader(BinaryStruct bs, GroboIL il, GroboIL.Local binaryStruct, GroboIL.Local buffer, GroboIL.Local offset, GroboIL.Local result, GroboIL.Local typeSize)
        {
            if (bs.PropertyList.Count > 0)
            {
                foreach (var item in bs.PropertyList)
                {
                    if (item.IsBaseType)
                    {
                        item.BinaryType.GetReadILCode(item, bs, il, binaryStruct, buffer, result, typeSize, offset, false);
                        continue;
                    }
                    var methodBreak = il.DefineLabel("breakReadMethod");

                    ReadObjectNull(il, methodBreak, buffer, offset, typeSize);

                    var in_value = il.DeclareLocal(item.PropertyInfo.PropertyType);

                    var constr = BinaryStruct.GetConstructor(item.PropertyInfo.PropertyType, null);

                    if (constr == null)
                    {
                        throw new Exception($"Type {item.PropertyInfo.PropertyType} not have constructor with not parameters");
                    }

                    il.Newobj(constr);
                    il.Stloc(in_value);


                    CompileReader(item.BinaryStruct, il, binaryStruct, buffer, offset, in_value, typeSize);

                    il.Ldloc(result);
                    il.Ldloc(in_value);
                    il.Call(item.Setter, isVirtual: true);

                    il.MarkLabel(methodBreak);
                    //il.Pop();
                }
            }
        }