Ejemplo n.º 1
0
        public void Store(BinaryWriter writer, Func <int, byte[]> values, int count)
        {
            int[] lengths = new int[count];

            for (int i = 0; i < count; i++)
            {
                byte[] value = values(i);

                if (value == null)
                {
                    lengths[i] = -1;
                }
                else
                {
                    lengths[i] = value.Length;
                }
            }

            Int32IndexerPersist lengthsPersist = new Int32IndexerPersist();

            lengthsPersist.Store(writer, (idx) => { return(lengths[idx]); }, count);

            for (int i = 0; i < count; i++)
            {
                byte[] value = values(i);

                if (value == null)
                {
                    continue;
                }

                writer.Write(value);
            }
        }
Ejemplo n.º 2
0
        public void Load(BinaryReader reader, Action <int, byte[]> values, int count)
        {
            int[] lengths = new int[count];

            Int32IndexerPersist lengthsPersist = new Int32IndexerPersist();

            lengthsPersist.Load(reader, (idx, value) => { lengths[idx] = value; }, count);

            for (int i = 0; i < count; i++)
            {
                if (lengths[i] == -1)
                {
                    values(i, null);
                }
                else
                {
                    values(i, reader.ReadBytes(lengths[i]));
                }
            }
        }