/// <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; }
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 <Type, 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("Key2", GetKeyCodec); RegisterOtherCodec("Key", GetKeyCodecOld); }