TextEncodingBinaryDataConverter.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace SuperWebSocket
  6. {
  7. /// <summary>
  8. /// Text encoding binary data converter
  9. /// </summary>
  10. public class TextEncodingBinaryDataConverter : IBinaryDataConverter
  11. {
  12. /// <summary>
  13. /// Gets the encoding.
  14. /// </summary>
  15. /// <value>
  16. /// The encoding.
  17. /// </value>
  18. public Encoding Encoding { get; private set; }
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="TextEncodingBinaryDataConverter" /> class.
  21. /// </summary>
  22. /// <param name="encoding">The encoding.</param>
  23. public TextEncodingBinaryDataConverter(Encoding encoding)
  24. {
  25. Encoding = encoding;
  26. }
  27. /// <summary>
  28. /// Returns a <see cref="System.String" /> that represents this instance.
  29. /// </summary>
  30. /// <param name="data">The data.</param>
  31. /// <param name="offset">The offset.</param>
  32. /// <param name="length">The length.</param>
  33. /// <returns>
  34. /// A <see cref="System.String" /> that represents this instance.
  35. /// </returns>
  36. public string ToString(byte[] data, int offset, int length)
  37. {
  38. return Encoding.GetString(data, offset, length);
  39. }
  40. }
  41. }