Esempio n. 1
0
        /// <summary>
        /// Constructs a saver for a data view.
        /// </summary>
        public BinarySaver(IHostEnvironment env, Arguments args)
        {
            Contracts.CheckValue(env, nameof(env));
            _host = env.Register("BinarySaver");

            _host.CheckUserArg(!args.MaxRowsPerBlock.HasValue || args.MaxRowsPerBlock > 0, nameof(args.MaxRowsPerBlock), "Must be positive.");
            _host.CheckUserArg(!args.MaxBytesPerBlock.HasValue || args.MaxBytesPerBlock > 0, nameof(args.MaxBytesPerBlock), "Must be positive.");

            _host.CheckUserArg(args.MaxRowsPerBlock.HasValue || args.MaxBytesPerBlock.HasValue, nameof(args.MaxBytesPerBlock),
                               "Either " + nameof(args.MaxRowsPerBlock) + " or " + nameof(args.MaxBytesPerBlock) + " must have a value.");

            _memPool     = new MemoryStreamPool();
            _factory     = new CodecFactory(_host, _memPool);
            _compression = args.Compression;

            _maxRowsPerBlock         = args.MaxRowsPerBlock;
            _maxBytesPerBlock        = args.MaxBytesPerBlock;
            _deterministicBlockOrder = args.DeterministicBlockOrder;
            _silent = args.Silent;
        }
Esempio n. 2
0
        public CodecFactory(IHostEnvironment env, MemoryStreamPool memPool = null)
        {
            Contracts.AssertValue(env, "env");
            Contracts.AssertValueOrNull(memPool);

            _host = env.Register("CodecFactory");

            _memPool  = memPool ?? new MemoryStreamPool();
            _encoding = Encoding.UTF8;

            _loadNameToCodecCreator = new Dictionary <string, GetCodecFromStreamDelegate>();
            _simpleCodecTypeMap     = new Dictionary <DataKind, IValueCodec>();
            // Register the current codecs.
            RegisterSimpleCodec(new UnsafeTypeCodec <sbyte>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <byte>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <short>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <ushort>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <int>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <uint>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <long>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <ulong>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <float>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <double>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <TimeSpan>(this));
            RegisterSimpleCodec(new TextCodec(this));
            RegisterSimpleCodec(new BoolCodec(this));
            RegisterSimpleCodec(new DateTimeCodec(this));
            RegisterSimpleCodec(new DateTimeOffsetCodec(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <RowId>(this));

            // Register the old type system reading codec.
            RegisterOtherCodec("DvBool", new OldBoolCodec(this).GetCodec);
            RegisterOtherCodec("DvDateTimeZone", new DateTimeOffsetCodec(this).GetCodec);
            RegisterOtherCodec("DvDateTime", new DateTimeCodec(this).GetCodec);
            RegisterOtherCodec("DvTimeSpan", new UnsafeTypeCodec <TimeSpan>(this).GetCodec);

            RegisterOtherCodec("VBuffer", GetVBufferCodec);
            RegisterOtherCodec("Key", GetKeyCodec);
        }
Esempio n. 3
0
        public CodecFactory(IHostEnvironment env, MemoryStreamPool memPool = null)
        {
            Contracts.AssertValue(env, "env");
            Contracts.AssertValueOrNull(memPool);

            _host = env.Register("CodecFactory");

            _memPool  = memPool ?? new MemoryStreamPool();
            _encoding = Encoding.UTF8;

            _loadNameToCodecCreator = new Dictionary <string, GetCodecFromStreamDelegate>();
            _simpleCodecTypeMap     = new Dictionary <DataKind, IValueCodec>();
            // Register the current codecs.
            RegisterSimpleCodec(new UnsafeTypeCodec <DvInt1>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <byte>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <DvInt2>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <ushort>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <DvInt4>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <uint>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <DvInt8>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <ulong>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <Single>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <Double>(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <DvTimeSpan>(this));
            RegisterSimpleCodec(new DvTextCodec(this));
            RegisterSimpleCodec(new BoolCodec(this));
            RegisterSimpleCodec(new DateTimeCodec(this));
            RegisterSimpleCodec(new DateTimeZoneCodec(this));
            RegisterSimpleCodec(new UnsafeTypeCodec <UInt128>(this));

            // Register the old boolean reading codec.
            var oldBool = new OldBoolCodec(this);

            RegisterOtherCodec(oldBool.LoadName, oldBool.GetCodec);

            RegisterOtherCodec("VBuffer", GetVBufferCodec);
            RegisterOtherCodec("Key", GetKeyCodec);
        }