Exemplo n.º 1
0
        protected TFields assign(TFields fields, byte[] data)
        {
            var ret = new TFields();

            if (fields == null || fields.Count < 1)
            {
                return(fields);
            }

            BReader br = new BReader(data, 0);

            foreach (var f in fields)
            {
                var val = new Field(f);
                val.value = br.next(val.type, val.tsize);
                ret.Add(val);
            }

            return(ret);
        }
Exemplo n.º 2
0
 public FMap(TFields map, string defVal)
 {
     defaultValue = defVal;
     this.map     = map;
 }
Exemplo n.º 3
0
 public BType(byte[] data, TFields fields)
 {
     this.data = data;
     Fields    = assign(fields, data);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs fields.
        /// </summary>
        /// <param name="left">The part of left definition of field.</param>
        /// <param name="right">The part of right definition of field</param>
        /// <param name="indent">Initial indent for all fields.</param>
        /// <returns>Map of used fields and definitions for user script.</returns>
        protected TFieldsMap fields(TFieldLeft left, TFieldRight right, string indent)
        {
            TFields fmap = new TFields();
            List <KeyValuePair <string, string> > items = new List <KeyValuePair <string, string> >();

            int maxlen = 0;

            foreach (var f in req.StepFields.items)
            {
                if (f.disabled)
                {
                    continue;
                }

                string name = f.newname;
                if (String.IsNullOrWhiteSpace(name))
                {
                    if (req.StepGen.gtype == GenType.CppDefinitions)
                    {
                        name = f.originConst;
                    }
                    else
                    {
                        name = (req.StepStruct.upperCase)? f.originUpperCase : f.origin;
                    }
                }

                if (!req.StepFields.isAllow(f.type, req.StepCfgData.scm) ||
                    !req.StepFields.isAllow(f.type, req.StepCfgData.revType) ||
                    !req.StepFields.isAllow(f.type, req.StepGen.gtype))
                {
                    continue;
                }
                fmap[f.type] = String.Format(PAT_FIELD_VALUE, name);

                string fleft  = left(indent, name, f.type == Fields.Type.Number);
                string fright = right(name, f.type == Fields.Type.Number);

                if (!String.IsNullOrEmpty(fright) && fleft.Length > maxlen)
                {
                    maxlen = fleft.Length;
                }

                items.Add(new KeyValuePair <string, string>(fleft, fright));
            }

            // formatting for user script

            int           spaces = INDENT_SIZE - (maxlen % INDENT_SIZE);
            StringBuilder sb     = new StringBuilder();

            foreach (var item in items)
            {
                if (String.IsNullOrEmpty(item.Value))
                {
                    sb.Append(item.Key + LINE_BREAK);
                    continue;
                }
                sb.Append(String.Format("{0}{1}{2}{3}", item.Key, new String(' ', (maxlen - item.Key.Length) + spaces), item.Value, LINE_BREAK));
            }

            if (sb.Length > LINE_BREAK.Length)
            {
                sb.Remove(sb.Length - LINE_BREAK.Length, LINE_BREAK.Length); //to remove the last line break
            }
            return(new TFieldsMap(fmap, sb.ToString()));
        }