예제 #1
0
        public override void LoadData(BinaryReader reader, StructInstance instance)
        {
            int size = GetExpressionAttribute("size").EvaluateInt(instance);
            long baseOffset = reader.BaseStream.Position;
            uint baseValue;
            switch(size)
            {
                case 1: baseValue = reader.ReadByte(); break;
                case 2: baseValue = reader.ReadUInt16(); break;
                case 4: baseValue = reader.ReadUInt32(); break;
                default:
                    throw new LoadDataException("Invalid bitfield size " + size);
            }
            BitfieldReader bitFieldReader = new BitfieldReader(baseValue, size, baseOffset);

            foreach(StructField field in ChildFields)
            {
                if (field is IntBasedField)
                {
                    IntBasedField intBasedField = (IntBasedField) field;
                    int? bit = intBasedField.GetIntAttribute("bit");
                    if (bit.HasValue)
                        bitFieldReader.SetBits(bit.Value, bit.Value);
                    else
                    {
                        int? fromBit = intBasedField.GetIntAttribute("frombit");
                        int? toBit = intBasedField.GetIntAttribute("tobit");
                        bitFieldReader.SetBits(fromBit.Value, toBit.Value);
                    }
                }
                field.LoadData(bitFieldReader, instance);
            }
        }
예제 #2
0
        public override void LoadData(BinaryReader reader, StructInstance instance)
        {
            int  size       = GetExpressionAttribute("size").EvaluateInt(instance);
            long baseOffset = reader.BaseStream.Position;
            uint baseValue;

            switch (size)
            {
            case 1: baseValue = reader.ReadByte(); break;

            case 2: baseValue = reader.ReadUInt16(); break;

            case 4: baseValue = reader.ReadUInt32(); break;

            default:
                throw new LoadDataException("Invalid bitfield size " + size);
            }
            BitfieldReader bitFieldReader = new BitfieldReader(baseValue, size, baseOffset);

            foreach (StructField field in ChildFields)
            {
                if (field is IntBasedField)
                {
                    IntBasedField intBasedField = (IntBasedField)field;
                    int?          bit           = intBasedField.GetIntAttribute("bit");
                    if (bit.HasValue)
                    {
                        bitFieldReader.SetBits(bit.Value, bit.Value);
                    }
                    else
                    {
                        int?fromBit = intBasedField.GetIntAttribute("frombit");
                        int?toBit   = intBasedField.GetIntAttribute("tobit");
                        bitFieldReader.SetBits(fromBit.Value, toBit.Value);
                    }
                }
                field.LoadData(bitFieldReader, instance);
            }
        }