Esempio n. 1
0
        internal object Read(IReader reader, Header header, AbstractCodec codec, Resolver resolver)
        {
            var remainingBlocks = reader.ReadLong();
            var blockSize       = reader.ReadLong();
            var syncBuffer      = new byte[DataFileConstants.SyncSize];

            var dataBlock = new byte[blockSize];

            reader.ReadFixed(dataBlock, 0, (int)blockSize);
            reader.ReadFixed(syncBuffer);

            if (!syncBuffer.SequenceEqual(header.SyncData))
            {
                throw new AvroRuntimeException("Invalid sync!");
            }

            dataBlock = codec.Decompress(dataBlock);
            reader    = new Reader(new MemoryStream(dataBlock));

            if (remainingBlocks > 1)
            {
                var result = new List <object>();

                for (int i = 0; i < remainingBlocks; i++)
                {
                    result.Add(resolver.Resolve(reader));
                }

                return(result);
            }
            else
            {
                return(resolver.Resolve(reader));
            }
        }
        internal byte[] ReadDataBlock(byte[] syncData, AbstractCodec codec)
        {
            var dataBlock = ReadRawBlock();

            ReadAndValidateSync(syncData);
            dataBlock = codec.Decompress(dataBlock);

            return(dataBlock);
        }
Esempio n. 3
0
        internal long GetRemainingBlocksCount()
        {
            if (_blockRemaining == 0)
            {
                if (HasNextBlock())
                {
                    _currentBlock = NextRawBlock();
                    _currentBlock = _codec.Decompress(_currentBlock);
                    _datumReader  = new Reader(new MemoryStream(_currentBlock));
                }
            }

            return(_blockRemaining);
        }
Esempio n. 4
0
        internal T Read <T>(IReader reader, Header header, AbstractCodec codec, Resolver resolver)
        {
            var remainingBlocks = reader.ReadLong();
            var blockSize       = reader.ReadLong();
            var syncBuffer      = new byte[DataFileConstants.SyncSize];

            var dataBlock = new byte[blockSize];

            reader.ReadFixed(dataBlock, 0, (int)blockSize);
            reader.ReadFixed(syncBuffer);

            if (!syncBuffer.SequenceEqual(header.SyncData))
            {
                throw new AvroRuntimeException("Invalid sync!");
            }

            dataBlock = codec.Decompress(dataBlock);
            reader    = new Reader(new MemoryStream(dataBlock));

            return(resolver.Resolve <T>(reader, remainingBlocks));
        }