Exemplo n.º 1
0
        /// <summary>
        /// Odczytuje wiersz ArrayRow macierzy HAL z tokenem-kluczem
        /// 
        /// Odcztytuje parę uint => ArrayRow&lt;uint&gt;
        /// </summary>
        /// <param name="reader">Strumień binarny do odczytu</param>
        /// <returns>Wiersz macierzy HAL z tokenem-kluczem</returns>
        public static KeyValuePair<uint, ArrayRow<uint>> readArrayRow(BinaryReader reader)
        {
            uint rowId;
            ArrayRow<uint> row = new ArrayRow<uint>();

            /* Odczyt ID i count dla wiersza */
            rowId = reader.ReadUInt32();
            row.count = reader.ReadInt32();

            int cellsCount = reader.ReadInt32();
            row.cells = new KeyValuePair<uint, Cell>[cellsCount];

            /* ID tokenu ostatnio odczytanej komórki */
            uint id = 0;

            for (int i = 0; i < cellsCount; i++)
            {
                Cell cell = new Cell();

                /* Odczytaj bajt informacyjny */
                byte infoByte = reader.ReadByte();

                /* Odczytaj różnicę ID od poprzedniej komórki, dodaj do ID, odczytaj count i sum (patrz Cell) */
                id += loadUint(reader, ref infoByte);
                cell.count = (int)loadUint(reader, ref infoByte);
                cell.sum = (int)loadUint(reader, ref infoByte);

                /* Wstaw odczytaną komórkę do wiersza */
                row.cells[i] = new KeyValuePair<uint, Cell>(id, cell);
            }

            /* TODO: to powinno być zbędne, komórki powinny być sortowane przy zapisie */
            Array.Sort<KeyValuePair<uint, Cell>>(row.cells,
                delegate(KeyValuePair<uint, Cell> firstPair, KeyValuePair<uint, Cell> nextPair)
                { return firstPair.Key.CompareTo(nextPair.Key); }
            );

            return new KeyValuePair<uint, ArrayRow<uint>>(rowId, row);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Odczytuje wiersz Row macierzy HAL z tokenem-kluczem
        /// 
        /// Odcztytuje parę uint => Row&lt;uint&gt;
        /// </summary>
        /// <param name="reader">Strumień binarny do odczytu</param>
        /// <returns>Wiersz macierzy HAL z tokenem-kluczem</returns>
        public static KeyValuePair<uint, Row<uint>> readRow(BinaryReader reader)
        {
            uint rowId;
            Row<uint> row = new Row<uint>();

            /* Odczyt ID i count dla wiersza */
            rowId = reader.ReadUInt32();
            row.count = reader.ReadInt32();

            int cellsCount = reader.ReadInt32();

            /* ID tokenu ostatnio odczytanej komórki */
            uint id = 0;

            for (int i = 0; i < cellsCount; i++)
            {
                Cell cell = new Cell();

                /* Odczytaj bajt informacyjny */
                byte infoByte = reader.ReadByte();

                /* Odczytaj różnicę ID od poprzedniej komórki, dodaj do ID, odczytaj count i sum (patrz Cell) */
                id += loadUint(reader, ref infoByte);
                cell.count = (int)loadUint(reader, ref infoByte);
                cell.sum = (int)loadUint(reader, ref infoByte);

                /* Wstaw odczytaną komórkę do wiersza */
                row.cells.Add(id, cell);
            }

            return new KeyValuePair<uint, Row<uint>>(rowId, row);
        }