You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Socks5UserPasswordResponseMessage.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace Shadowsocks.Protocol.Socks5
  3. {
  4. public class Socks5UserPasswordResponseMessage : Socks5Message
  5. {
  6. // 1 success
  7. public bool Success;
  8. public override int Serialize(Memory<byte> buffer)
  9. {
  10. if (buffer.Length < 2) throw Util.BufferTooSmall(2, buffer.Length, nameof(buffer));
  11. buffer.Span[0] = 1;
  12. buffer.Span[1] = (byte) (Success ? 0 : 1);
  13. return 2;
  14. }
  15. public override (bool success, int length) TryLoad(ReadOnlyMemory<byte> buffer)
  16. {
  17. if (buffer.Length < 2) return (false, 2);
  18. if (buffer.Span[0] != 1) return (false, 0);
  19. Success = buffer.Span[1] == 0;
  20. return (true, 2);
  21. }
  22. public override bool Equals(IProtocolMessage other)
  23. {
  24. if (other is null) return false;
  25. if (ReferenceEquals(this, other)) return true;
  26. if (other.GetType() != GetType()) return false;
  27. return Success == ((Socks5UserPasswordResponseMessage)other).Success;
  28. }
  29. }
  30. }