/// <summary> /// Constructs a <see cref="Receiver"/>. /// </summary> /// <param name="bapsNet"> /// A downstream source for BapsNet primitives. /// </param> /// <param name="decoder"> /// A <see cref="ClientCommandDecoder"/> used to decode command /// words. It should be using the same primitive source and /// cancellation token as this receiver. /// </param> /// <param name="token"> /// The cancellation token used to cancel this receiver. /// This is provided up-front as the decoder should also /// be using the same token. /// </param> public Receiver(IPrimitiveSource?bapsNet, CommandDecoder decoder, CancellationToken token) { _bapsNet = bapsNet ?? throw new ArgumentNullException(nameof(bapsNet)); _token = token; _decoder = decoder; }
public static (bool matched, ushort command, string?payload) ReceiveSystemStringCommand( this IPrimitiveSource src, SystemOp expectedOp) { // ArgumentNullException need a parameter name, but `src` isn't technically a parameter, and code analysis // fails if we try to pass `nameof(src)` in. Hmm. if (src is null) { throw new ArgumentException("Source on which this method was invoked is null."); } var cmd = src.ReceiveCommand(); _ = src.ReceiveUint(); // Discard length var isRightGroup = CommandUnpacking.Group(cmd) == CommandGroup.System; var isRightOp = CommandUnpacking.SystemOp(cmd) == expectedOp; var isRightCommand = isRightGroup && isRightOp; return(isRightCommand ? (true, cmd, src.ReceiveString()) : (false, default, null));
protected CommandDecoder(IPrimitiveSource primitiveSource, CancellationToken token) { _primitiveSource = primitiveSource; _token = token; }
public ClientCommandDecoder(IPrimitiveSource primitiveSource, CancellationToken token = default) : base(primitiveSource, token) { }
private Receiver CreateReceiver(IPrimitiveSource source, Func <IPrimitiveSource, CancellationToken, CommandDecoder> commandDecoderFactory) { var decoder = commandDecoderFactory(source, _dead.Token); return(new Receiver(source, decoder, _dead.Token)); }