Пример #1
0
        private void WriteBlock()
        {
            _serializeStream.Flush();
            var data = Compress(_serializeStream.GetBuffer(), (int)_serializeStream.Position, _header.Codec);

            using (var encoding = new BinaryEncoder(_fileStream))
            {
                encoding.WriteLong(_count);
                encoding.WriteLong(data.Length);
                _fileStream.Write(data);
                encoding.WriteFixed(_header.Sync);
            }
            _count = 0;
            _serializeStream.Seek(0, SeekOrigin.Begin);
        }
Пример #2
0
        public void WriteArrayBlock <T>(IList <T> items, Action <IAvroEncoder, T> itemsWriter)
        {
            if (items.Count == 0)
            {
                WriteLong(0);
                return;
            }

            var localEncoder = new BinaryEncoder(new MemoryStream());

            localEncoder.WriteLong(items.Count);
            foreach (var item in items)
            {
                itemsWriter.Invoke(localEncoder, item);
            }
            WriteLong(-1 * localEncoder._stream.Length);
            localEncoder._stream.Seek(0, SeekOrigin.Begin);
            localEncoder._stream.CopyTo(_stream);
        }
Пример #3
0
        public void WriteMapBlock <T>(IDictionary <string, T> keyValues, Action <IAvroEncoder, T> valuesWriter)
        {
            if (keyValues.Count == 0)
            {
                WriteLong(0);
                return;
            }

            var localEncoder = new BinaryEncoder(new MemoryStream());

            localEncoder.WriteLong(keyValues.Count);
            foreach (var keyValue in keyValues)
            {
                localEncoder.WriteString(keyValue.Key);
                valuesWriter.Invoke(localEncoder, keyValue.Value);
            }
            WriteLong(-1 * localEncoder._stream.Length);
            localEncoder._stream.Seek(0, SeekOrigin.Begin);
            localEncoder._stream.CopyTo(_stream);
        }