Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

67 строки
1.7 KiB

  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using Microsoft.Extensions.Logging;
  5. namespace MQTTnet.Server.Scripting
  6. {
  7. public class PythonIOStream : Stream
  8. {
  9. private readonly ILogger _logger;
  10. private readonly Encoding _encoder = Encoding.UTF8;
  11. public PythonIOStream(ILogger<PythonIOStream> logger)
  12. {
  13. _logger = logger ?? throw new ArgumentNullException(nameof(logger));
  14. }
  15. public override void Flush()
  16. {
  17. }
  18. public override int Read(byte[] buffer, int offset, int count)
  19. {
  20. throw new NotSupportedException();
  21. }
  22. public override long Seek(long offset, SeekOrigin origin)
  23. {
  24. throw new NotSupportedException();
  25. }
  26. public override void SetLength(long value)
  27. {
  28. throw new NotSupportedException();
  29. }
  30. public override void Write(byte[] buffer, int offset, int count)
  31. {
  32. if (buffer == null) throw new ArgumentNullException(nameof(buffer));
  33. if (count == 0)
  34. {
  35. return;
  36. }
  37. var text = _encoder.GetString(buffer, offset, count);
  38. if (text.Equals(Environment.NewLine))
  39. {
  40. return;
  41. }
  42. _logger.LogDebug(text);
  43. }
  44. public override bool CanRead { get; } = false;
  45. public override bool CanSeek { get; } = false;
  46. public override bool CanWrite { get; } = true;
  47. public override long Length { get; } = 0L;
  48. public override long Position
  49. {
  50. get => throw new NotSupportedException();
  51. set => throw new NotSupportedException();
  52. }
  53. }
  54. }