ByteQueueOutputStream.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Tls
  6. {
  7. /// <summary>OutputStream based on a ByteQueue implementation.</summary>
  8. public sealed class ByteQueueOutputStream
  9. : BaseOutputStream
  10. {
  11. private readonly ByteQueue m_buffer;
  12. public ByteQueueOutputStream()
  13. {
  14. this.m_buffer = new ByteQueue();
  15. }
  16. public ByteQueue Buffer
  17. {
  18. get { return m_buffer; }
  19. }
  20. public override void Write(byte[] buffer, int offset, int count)
  21. {
  22. Streams.ValidateBufferArguments(buffer, offset, count);
  23. m_buffer.AddData(buffer, offset, count);
  24. }
  25. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  26. public override void Write(ReadOnlySpan<byte> buffer)
  27. {
  28. m_buffer.AddData(buffer);
  29. }
  30. #endif
  31. public override void WriteByte(byte value)
  32. {
  33. m_buffer.AddData(new byte[]{ value }, 0, 1);
  34. }
  35. }
  36. }
  37. #pragma warning restore
  38. #endif