コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        protected override int GetItemSize(T value)
        {
            if (FixedItemSize.HasValue)
            {
                return(FixedItemSize.Value);
            }
            int itemSize = GetDataSize(value);

            return(itemSize + PwrBitConverter.GetSizeEncodingSize(itemSize, ItemSizing));
        }
コード例 #4
0
        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)));
        }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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));
        }
コード例 #8
0
 protected virtual long GetAllocOffset(int index)
 {
     return(HeaderOffset + AllocItemSize * index + PwrBitConverter.GetSizeEncodingSize(int.MaxValue, CountSizing));
 }