Exemple #1
0
 public StoredFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, SizeEncoding flagSizing, int flagSize,
                                          Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                          Array array, bool leaveOpen, bool boostAccess)
     : this(stream, countSizing, itemSizing, dataSizer, flagSizing, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality,
            array.GetRegularArrayLengths(), array.EnumerateAsRegular <T>().Counted(array.Length), leaveOpen, boostAccess)
 {
 }
Exemple #2
0
        public static Byte[] GetSizeEncodingBytes(long size, SizeEncoding sizeEncoding)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException("size");
            }

            switch (sizeEncoding)
            {
            case SizeEncoding.NO:
                return(null);

            case SizeEncoding.B1:
                return(new[] { Convert.ToByte(size) });

            case SizeEncoding.B2:
                return(BitConverter.GetBytes(Convert.ToUInt16(size)));

            case SizeEncoding.B4:
                return(BitConverter.GetBytes(Convert.ToUInt32(size)));

            case SizeEncoding.B8:
                return(BitConverter.GetBytes(size));

            case SizeEncoding.VB:
                return(GetVarBytes(size));

            default:
                throw new ArgumentOutOfRangeException("sizeEncoding");
            }
        }
Exemple #3
0
 public PwrBinaryWriter(Stream output, Endian endian, SizeEncoding sizeEncoding, Encoding encoding, bool leaveOpen)
     : base(output, encoding, leaveOpen)
 {
     _endian       = endian;
     _sizeEncoding = sizeEncoding;
     _encoding     = encoding;
 }
Exemple #4
0
 public StoredFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, SizeEncoding flagSizing, int flagSize,
                                          Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                          int[] lengths, ICollection <T> coll, bool leaveOpen, bool boostAccess)
     : this(stream, countSizing, itemSizing, dataSizer, flagSizing, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality,
            new RegularArrayInfo(lengths), coll, leaveOpen, boostAccess, true)
 {
 }
        public CustomStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer,
                                        Func <Stream, int, T> dataReader, Action <Stream, int, T> dataWriter, Equality <T> itemEquality, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
            : base(stream, leaveOpen, boostAccess)
        {
            if (dataSizer == null)
            {
                throw new ArgumentNullException("dataSizer");
            }
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (dataWriter == null)
            {
                throw new ArgumentNullException("dataWriter");
            }

            _countSizing  = countSizing;
            _itemSizing   = itemSizing;
            _dataSize     = null;
            _dataSizer    = dataSizer;
            _dataReader   = dataReader;
            _dataWriter   = dataWriter;
            _dataEquality = itemEquality != null ? itemEquality : EqualityComparer <T> .Default.Equals;
            if (initialize)
            {
                BaseStream.Position = 0;
                Initialize(coll ?? default(T).Repeat(0));
            }
        }
Exemple #6
0
 public CustomStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer,
                                   Func <Stream, int, T> dataReader, Action <Stream, int, T> dataWriter, Equality <T> itemEquality,
                                   int[] lengths, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
     : this(stream, countSizing, itemSizing, dataSizer, dataReader, dataWriter, itemEquality,
            lengths != null ? new RegularArrayInfo(lengths) : null, coll, leaveOpen, boostAccess, initialize)
 {
 }
Exemple #7
0
 public CustomStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer,
                                   Func <Stream, int, T> dataReader, Action <Stream, int, T> dataWriter, Equality <T> itemEquality,
                                   Array array, bool leaveOpen, bool boostAccess, bool initialize)
     : this(stream, countSizing, itemSizing, dataSizer, dataReader, dataWriter, itemEquality,
            array.GetRegularArrayLengths(), initialize ? array.EnumerateAsRegular <T>().Counted(array.Length) : null, leaveOpen, boostAccess, initialize)
 {
 }
 public CustomFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int dataSize, bool compact, int flagSize,
                                          Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                          Array array, bool leaveOpen, bool boostAccess, bool initialize)
     : this(stream, countSizing, itemSizing, dataSize, compact, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality,
            array.GetRegularArrayLengths(), initialize ? array.EnumerateAsRegular <T>().Counted(array.Length) : null, leaveOpen, boostAccess, initialize)
 {
 }
        public CustomFlaggedStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int dataSize, bool compact, int flagSize,
                                               Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                               ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
            : base(stream, leaveOpen, boostAccess && !compact)
        {
            if (dataSize < 0)
            {
                throw new ArgumentOutOfRangeException("dataSize");
            }
            if (flagSize < 0)
            {
                throw new ArgumentOutOfRangeException("flagSize");
            }
            if (itemFlag == null)
            {
                throw new ArgumentNullException("itemFlag");
            }
            if (hasData == null)
            {
                throw new ArgumentNullException("hasData");
            }
            if (flagReader == null)
            {
                throw new ArgumentNullException("flagReader");
            }
            if (flagWriter == null)
            {
                throw new ArgumentNullException("flagWriter");
            }
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (dataWriter == null)
            {
                throw new ArgumentNullException("dataWriter");
            }

            _countSizing  = countSizing;
            _itemSizing   = itemSizing;
            _flagSize     = flagSize;
            _flagSizer    = t => flagSize;
            _dataSize     = dataSize;
            _dataSizer    = t => dataSize;
            _compact      = compact;
            _itemFlag     = itemFlag;
            _hasData      = hasData;
            _flagReader   = flagReader;
            _flagWriter   = flagWriter;
            _dataReader   = dataReader;
            _dataWriter   = dataWriter;
            _dataEquality = itemEquality != null ? itemEquality : EqualityComparer <T> .Default.Equals;
            if (initialize)
            {
                BaseStream.Position = 0;
                Initialize(coll ?? default(T).Repeat(0));
            }
        }
Exemple #10
0
 public StringStreamedArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Encoding encoding, Equality <String> equality, ICollection <String> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, itemSizing, v => GetDataSize(encoding, v), SizeEncoding.B1, sizeof(Byte), v => v != null, f => f,
            ReadItemFlag, WriteItemFlag, (s, f, l) => ReadItemData(s, encoding, f, l), (s, f, l, v) => WriteItemData(s, encoding, f, l, v), equality, coll,
            leaveOpen, boostAccess, false)
 {
     Encoding            = encoding;
     BaseStream.Position = 0;
     Initialize(coll ?? default(String).Repeat(0));
 }
        public static String ReadString(this BinaryReader reader, Encoding encoding, SizeEncoding sizeEncoding)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            return(encoding.GetString(reader.ReadBytes(reader.ReadSize(sizeEncoding))));
        }
        public static void Write(this BinaryWriter writer, byte[] value, SizeEncoding sizeEncoding)
        {
            if (writer == null)
            {
                throw new NullReferenceException();
            }
            if (value == null)
            {
                throw new ArgumentNullException("value ");
            }

            writer.WriteSize(value.Length, sizeEncoding);
            writer.Write(value, 0, value.Length);
        }
        public static void WriteLongSize(this BinaryWriter writer, long value, SizeEncoding sizeEncoding, Endian?endian = null)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (value < 0L)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            if (endian.HasValue)
            {
                writer.BaseStream.WriteLongSize(value, sizeEncoding, endian.Value);
            }
            else
            {
                switch (sizeEncoding)
                {
                case SizeEncoding.NO:
                    break;

                case SizeEncoding.B1:
                    writer.Write(Convert.ToSByte(value));
                    break;

                case SizeEncoding.B2:
                    writer.Write(Convert.ToInt16(value));
                    break;

                case SizeEncoding.B4:
                    writer.Write(Convert.ToInt32(value));
                    break;

                case SizeEncoding.B8:
                    writer.Write(value);
                    break;

                case SizeEncoding.VB:
                    writer.WriteMb(value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("sizeEncoding");
                }
            }
        }
Exemple #14
0
        protected StoredFlaggedStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, SizeEncoding flagSizing, int flagSize,
                                                    Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                                    RegularArrayInfo arrayInfo, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
            : base(stream, countSizing, itemSizing, dataSizer, flagSize, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, arrayInfo, coll, leaveOpen, boostAccess, false)
        {
            if (flagSize < 0)
            {
                throw new ArgumentOutOfRangeException("flagSize");
            }

            _flagSizing = flagSizing;
            if (initialize)
            {
                BaseStream.Position = 0;
                Initialize(coll ?? default(T).Repeat(ArrayInfo.Length));
            }
        }
        protected StoredFlaggedStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer, SizeEncoding flagSizing, Func <F, int> flagSizer,
                                                  Func <T, F> itemFlag, Func <F, bool> hasData, Func <Stream, F> flagReader, Action <Stream, F> flagWriter, Func <Stream, F, int, T> dataReader, Action <Stream, F, int, T> dataWriter, Equality <T> itemEquality,
                                                  ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
            : base(stream, countSizing, itemSizing, dataSizer, flagSizer, itemFlag, hasData, flagReader, flagWriter, dataReader, dataWriter, itemEquality, coll, leaveOpen, boostAccess, false)
        {
            if (flagSizer == null)
            {
                throw new ArgumentNullException("flagSizer");
            }

            _flagSizing = flagSizing;
            if (initialize)
            {
                BaseStream.Position = 0;
                Initialize(coll ?? default(T).Repeat(0));
            }
        }
        public static long ReadLongSize(this BinaryReader reader, SizeEncoding sizeEncoding, Endian?endian = null)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (endian.HasValue)
            {
                return(reader.BaseStream.ReadLongSize(sizeEncoding, endian.Value));
            }
            else
            {
                switch (sizeEncoding)
                {
                case SizeEncoding.NO:
                    return(-1L);

                case SizeEncoding.B1:
                    return(reader.ReadSByte());

                case SizeEncoding.B2:
                    return(reader.ReadInt16());

                case SizeEncoding.B4:
                    return(reader.ReadInt32());

                case SizeEncoding.B8:
                    return(reader.ReadInt64());

                case SizeEncoding.VB:
                    return(reader.ReadInt64Mb());

                default:
                    throw new ArgumentOutOfRangeException("sizeEncoding");
                }
            }
        }
Exemple #17
0
        public static int GetSizeEncodingSize(long size, SizeEncoding sizeEncoding)
        {
            switch (sizeEncoding)
            {
            case SizeEncoding.B1:
                return(sizeof(byte));

            case SizeEncoding.B2:
                return(sizeof(ushort));

            case SizeEncoding.B4:
                return(sizeof(uint));

            case SizeEncoding.B8:
                return(sizeof(ulong));

            case SizeEncoding.VB:
                return(GetVbSize(size));

            default:
                throw new InvalidOperationException();
            }
        }
Exemple #18
0
        public static long ToLongSize(Byte[] bytes, int index, SizeEncoding sizeEncoding)
        {
            switch (sizeEncoding)
            {
            case SizeEncoding.B1:
                return((long)bytes[index]);

            case SizeEncoding.B2:
                return((long)BitConverter.ToUInt16(bytes, index));

            case SizeEncoding.B4:
                return((long)BitConverter.ToUInt32(bytes, index));

            case SizeEncoding.B8:
                return(BitConverter.ToInt64(bytes, index));

            case SizeEncoding.VB:
                return(VbToInt64(bytes, index));

            default:
                throw new ArgumentOutOfRangeException("sizeEncoding");
            }
        }
Exemple #19
0
        protected CustomStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int dataSize,
                                             Func <Stream, int, T> dataReader, Action <Stream, int, T> dataWriter, Equality <T> itemEquality,
                                             RegularArrayInfo arrayInfo, ICollection <T> coll, bool leaveOpen, bool boostAccess, bool initialize)
            : base(stream, leaveOpen, boostAccess)
        {
            if (arrayInfo == null)
            {
                throw new ArgumentNullException("arrayInfo");
            }
            if (dataSize < 0)
            {
                throw new ArgumentOutOfRangeException("dataSize");
            }
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (dataWriter == null)
            {
                throw new ArgumentNullException("dataWriter");
            }

            _countSizing  = countSizing;
            _itemSizing   = itemSizing;
            _dataSize     = dataSize;
            _dataSizer    = t => dataSize;
            _dataReader   = dataReader;
            _dataWriter   = dataWriter;
            _dataEquality = itemEquality != null ? itemEquality : EqualityComparer <T> .Default.Equals;
            _arrayInfo    = arrayInfo;
            if (initialize)
            {
                BaseStream.Position = 0;
                Initialize(coll ?? default(T).Repeat(ArrayInfo.Length));
            }
        }
Exemple #20
0
 public NulGuidStreamedRegularArray(Stream stream, SizeEncoding countSizing, bool compact, int[] lengths, ICollection <Guid?> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, 16, compact, SizeEncoding.B1, sizeof(Byte), v => v.HasValue, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, NullableEqualityComparer <Guid> .Default.Equals, lengths, coll, leaveOpen, boostAccess)
 {
 }
Exemple #21
0
 public NulInt64StreamedArray(Stream stream, SizeEncoding countSizing, bool compact, ICollection <Int64?> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, sizeof(Int64), compact, SizeEncoding.B1, sizeof(Byte), v => v.HasValue, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, NullableEqualityComparer <Int64> .Default.Equals, coll, leaveOpen, boostAccess)
 {
 }
Exemple #22
0
 public NulComplexStreamedRegularArray(Stream stream, SizeEncoding countSizing, bool compact, int[] lengths, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, sizeof(Double) * 2, compact, SizeEncoding.B1, sizeof(Byte), v => v.HasValue, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, NullableEqualityComparer <Complex> .Default.Equals, lengths, null, leaveOpen, boostAccess)
 {
 }
 public NulDoubleStreamedCollection(Stream stream, SizeEncoding countSizing, bool compact, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, sizeof(Double), compact, SizeEncoding.B1, sizeof(Byte), v => v.HasValue, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, NullableEqualityComparer <Double> .Default.Equals, leaveOpen, boostAccess)
 {
 }
Exemple #24
0
 public FixedStreamedArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int itemSize, bool compact, ICollection <Byte[]> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, itemSizing, itemSize, compact, SizeEncoding.B1, sizeof(Byte), v => v != null, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, EqualityComparer.Equals, coll, leaveOpen, boostAccess)
 {
 }
 public CustomStreamedCollection(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Func <T, int> dataSizer,
                                 Func <Stream, int, T> dataReader, Action <Stream, int, T> dataWriter, Equality <T> itemEquality, bool leaveOpen, bool boostAccess, bool initialize)
     : this(stream, countSizing, itemSizing, dataSizer, dataReader, dataWriter, itemEquality, null, leaveOpen, boostAccess, initialize)
 {
 }
Exemple #26
0
 public StringStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Encoding encoding, Equality <String> equality, Array array, bool leaveOpen, bool boostAccess)
     : this(stream, countSizing, itemSizing, encoding, equality, array.GetRegularArrayLengths(), array.EnumerateAsRegular <String>().Counted(array.Length), leaveOpen, boostAccess)
 {
 }
 public NulByteStreamedRegularArray(Stream stream, SizeEncoding countSizing, bool compact, Array array, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, sizeof(Byte), compact, SizeEncoding.B1, sizeof(Byte), v => v.HasValue, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, NullableEqualityComparer <Byte> .Default.Equals, array, leaveOpen, boostAccess)
 {
 }
Exemple #28
0
 public BinaryStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, int[] lengths, ICollection <Byte[]> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, itemSizing, v => v != null ? v.Length : 0, SizeEncoding.B1, sizeof(Byte), v => v != null, f => f,
            ReadItemFlag, WriteItemFlag, ReadItemData, WriteItemData, EqualityComparer.Equals, lengths, coll, leaveOpen, boostAccess)
 {
 }
 public NulBooleanStreamedCollection(Stream stream, SizeEncoding countSizing, ICollection <Boolean?> coll, bool leaveOpen, bool boostAccess)
     : base(stream, countSizing, SizeEncoding.B1, sizeof(byte), ReadItemData, WriteItemData, NullableEqualityComparer <Boolean> .Default.Equals, coll, leaveOpen, boostAccess)
 {
 }
Exemple #30
0
 public StringStreamedRegularArray(Stream stream, SizeEncoding countSizing, SizeEncoding itemSizing, Encoding encoding, Equality <String> equality, int[] lengths, bool leaveOpen, bool boostAccess)
     : this(stream, countSizing, itemSizing, encoding, equality, lengths, null, leaveOpen, boostAccess)
 {
 }