public SqlInt64 WriteSizedBlock(SqlBytes bytes, SqlByte sizing, SqlInt64 offset, SqlBoolean insert) { if (IsNull || bytes.IsNull) { return(SqlInt64.Null); } var sizeEncoding = !sizing.IsNull ? (SizeEncoding)sizing.Value : SizeEncoding.NO; using (var fs = _fi.Open(offset.IsNull ? FileMode.Append : FileMode.OpenOrCreate, FileAccess.Write)) { if (!offset.IsNull) { fs.Position = offset.Value; } Int64 position = fs.Position; if (!offset.IsNull && insert.IsTrue) { long size = bytes.Length + PwrBitConverter.GetSizeEncodingSize(bytes.Length, sizeEncoding); fs.Move(offset.Value, size, SqlRuntime.IoBufferSize); fs.Position = position; } if (sizeEncoding != SizeEncoding.NO) { fs.WriteLongSize(bytes.Length, sizeEncoding); } fs.WriteSqlBytes(bytes); fs.Flush(); return(fs.Position - position); } }
protected override void WriteItem(int index, T value) { int itemSize = FixedItemSize.HasValue ? FixedItemSize.Value : GetItemSize(value); if (!FixedItemSize.HasValue) { long itemOffset = BaseStream.Position; try { int countSize = PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing); long allocOffset = BaseStream.Position = HeaderOffset + countSize + AllocItemSize * index; int allocSize = PwrBitConverter.GetSizeEncodingSize(int.MaxValue, ItemSizing); BaseStream.WriteSize(itemSize, ItemSizing, Endian); int rest = allocSize - (int)(BaseStream.Position - allocOffset); if (rest > 0) { BaseStream.WriteCollection(Enumerable.Repeat((byte)0, rest), (s, t) => s.WriteUByte(t)); } } finally { BaseStream.Position = itemOffset; } } WriteItemData(value, itemSize); }
protected override int GetItemSize(T value) { if (FixedItemSize.HasValue) { return(FixedItemSize.Value); } int itemSize = GetDataSize(value); return(itemSize + PwrBitConverter.GetSizeEncodingSize(itemSize, ItemSizing)); }
protected override int GetItemSize(T value) { F flag = GetItemFlag(value); bool hasValue = HasItemData(flag); int size = FixedDataSize.HasValue && (hasValue || !Compact) ? FixedDataSize.Value : !FixedDataSize.HasValue && hasValue?GetDataSize(value) : 0; if (!FixedDataSize.HasValue && hasValue) { size += PwrBitConverter.GetSizeEncodingSize(size, ItemSizing); } return(size + (FixedFlagSize.HasValue ? FixedFlagSize.Value : GetFlagSize(flag))); }
protected override void WriteCount(int count) { int countSize = PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing); long countOffset = BaseStream.Position = HeaderOffset; BaseStream.WriteSize(count, CountSizing, Endian); int rest = countSize - (int)(BaseStream.Position - countOffset); if (rest > 0) { BaseStream.WriteCollection(Enumerable.Repeat((byte)0, rest), (s, v) => s.WriteUByte(v)); } }
protected override int ReadCount() { int countSize = PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing); long countOffset = BaseStream.Position = HeaderOffset; int count = BaseStream.ReadSize(CountSizing, Endian); int rest = countSize - (int)(BaseStream.Position - countOffset); if (rest > 0) { BaseStream.Position += rest; } return(count); }
protected override T ReadItem(int index) { int itemSize = FixedItemSize.HasValue ? FixedItemSize.Value : 0; if (!FixedItemSize.HasValue) { long itemOffset = BaseStream.Position; try { int countSize = PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing); BaseStream.Position = HeaderOffset + countSize + AllocItemSize * index; itemSize = BaseStream.ReadSize(ItemSizing, Endian); } finally { BaseStream.Position = itemOffset; } } return(ReadItemData(itemSize)); }
protected virtual long GetAllocOffset(int index) { return(HeaderOffset + AllocItemSize * index + PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing)); }