public JfpClient([NotNull] Stream stream, JfpProtocol protocol = JfpProtocol.JfpOrLjfp) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } if (stream.CanRead) { _streamReader = new StreamReader(stream); } if (stream.CanWrite) { _streamWriter = new StreamWriter(stream); } SupportedProtocol = protocol; if (stream.CanRead && stream.CanWrite) { CurrentProtocol = GetProtocol(this); } else { CurrentProtocol = JfpProtocol.Jfp; } }
internal static JfpProtocol?GetProtocol(JfpProtocol local, JfpProtocol remote) { // Client | Remote | Result // _______|________|________ // 0 | 0 | 0 // 1 | 0 | X // 1 | 1 | 1 // 2 | 0 | 0 // 2 | 1 | 1 // 2 | 2 | 1 switch (local) { case JfpProtocol.Jfp: switch (remote) { case JfpProtocol.Jfp: return(JfpProtocol.Jfp); case JfpProtocol.Ljfp: return(null); case JfpProtocol.JfpOrLjfp: return(JfpProtocol.Jfp); default: throw new ArgumentOutOfRangeException(nameof(remote), remote, null); } case JfpProtocol.Ljfp: switch (remote) { case JfpProtocol.Jfp: return(null); case JfpProtocol.Ljfp: return(JfpProtocol.Ljfp); case JfpProtocol.JfpOrLjfp: return(JfpProtocol.Ljfp); default: throw new ArgumentOutOfRangeException(nameof(remote), remote, null); } case JfpProtocol.JfpOrLjfp: switch (remote) { case JfpProtocol.Jfp: return(JfpProtocol.Jfp); case JfpProtocol.Ljfp: return(JfpProtocol.Ljfp); case JfpProtocol.JfpOrLjfp: return(JfpProtocol.Ljfp); default: throw new ArgumentOutOfRangeException(nameof(remote), remote, null); } default: throw new ArgumentOutOfRangeException(nameof(local), local, null); } }