Esempio n. 1
0
		private void CloseFrame()
		{
			if (_encoder == null)
				return;

			try
			{
				EncoderAction action = _encoder.FlushAndEncode(_buffer, 0, _buffer.Length, true, out int encoded);
				WriteBlock(encoded, action);

				Write32(0);
				Flush16();

				if (_descriptor.ContentChecksum)
                    throw new NotImplementedException(string.Format(RS.FeatureNotImplementedInType, "Content Checksum", GetType().Name));

				_buffer = null;

				_encoder.Dispose();
			}
			finally
			{
				_encoder = null;
			}
		}
 public BlockInfo(byte[] buffer, EncoderAction action, int length)
 {
     _buffer = buffer;
     _length = action switch {
         EncoderAction.Encoded => length,
         EncoderAction.Copied => - length,
         _ => 0,
     };
 }
Esempio n. 3
0
        private void WriteBlock(int length, EncoderAction action)
		{
			switch (action)
			{
				case EncoderAction.Copied:
					WriteBlock(length, false);
					break;
				case EncoderAction.Encoded:
					WriteBlock(length, true);
					break;
			}
		}
Esempio n. 4
0
        private ValueTask WriteBlockAsync(int length, EncoderAction action, CancellationToken cancellationToken)
        {
            switch (action)
            {
            case EncoderAction.Copied:
                return(WriteBlockAsync(length, false, cancellationToken));

            case EncoderAction.Encoded:
                return(WriteBlockAsync(length, true, cancellationToken));
            }

            return(new ValueTask());
        }
Esempio n. 5
0
		/// <see cref="Stream.Write(byte[], int, int)"/>
		public override void Write(byte[] buffer, int offset, int count)
		{
			if (_encoder == null)
				WriteFrame();

			while (count > 0)
			{
				EncoderAction action = _encoder.TopupAndEncode(
					buffer, offset, count,
					_buffer, 0, _buffer.Length,
					false, true,
					out int loaded,
					out int encoded);

				WriteBlock(encoded, action);

				offset += loaded;
				count -= loaded;
			}
		}