Exemplo n.º 1
0
        async ValueTask ReadChunks(long chunkTableOffset, int chunkCount)
        {
            if (ChunkReader is null)
            {
                throw new InvalidOperationException();
            }

            var chunkTable = new byte[(chunkCount + 1) * (4 + sizeof(long))];

            if (await ChunkReader.ReadAtAsync(chunkTableOffset, chunkTable).ConfigureAwait(false) != chunkTable.Length)
            {
                return;
            }

            _chunks = Enumerable.Range(0, chunkCount + 1).Select(i => new Chunk
            {
                Name     = (i < chunkCount) ? Encoding.ASCII.GetString(chunkTable, 12 * i, 4) : null,
                Position = NetBitConverter.ToInt64(chunkTable, 12 * i + 4)
            }).ToArray();

            for (int i = 0; i < chunkCount; i++)
            {
                _chunks[i].Length = _chunks[i + 1].Position - _chunks[i].Position;
            }

            FanOut = await ReadFanOutAsync().ConfigureAwait(false);
        }
Exemplo n.º 2
0
        private async ValueTask <long> ReadCommitTimeOffset(uint index)
        {
            var offsetData = new byte[sizeof(int)];

            if (offsetData.Length != await ReadFromChunkAsync("GDA2", index * sizeof(int), offsetData).ConfigureAwait(false))
            {
                return(long.MinValue);
            }

            int v = NetBitConverter.ToInt32(offsetData, 0);

            if (v >= 0)
            {
                return(v);
            }

            offsetData = new byte[sizeof(long)];
            if (offsetData.Length != await ReadFromChunkAsync("GDO2", (~v) * sizeof(long), offsetData).ConfigureAwait(false))
            {
                return(long.MinValue);
            }

            return(NetBitConverter.ToInt64(offsetData, 0));
        }
        private static DateTime ToDateTime(byte[] bytes, int startIndex)
        {
            var l = NetBitConverter.ToInt64(bytes, startIndex);

            return(DateTimeUtil.UnixTimestampToDateTime(l));
        }
        private static DateTime ToDateTime(byte[] bytes, int startIndex)
        {
            var l = NetBitConverter.ToInt64(bytes, startIndex);

            return(DateTime.FromBinary(l));
        }