public void Handle(ref SocketPipelineContext context, ref ReadOnlySequence <byte> data) { SequencePosition?position = data.PositionOf(SplitMessageHandler.BREAK_CHAR); if (position != null) { ReadOnlySequence <byte> withoutTerminator = data.Slice(start: 0, end: position.Value); context.ProgressReadHandler(ref withoutTerminator); data = data.Slice(start: data.GetPosition(1, position.Value)); } }
public void Handle(ref SocketPipelineContext context, ref ReadOnlySequence <byte> data) { Span <byte> checksum = stackalloc byte[3]; CryptoUtils.CreateChecksumHash(++this.IncomingCount, ref checksum); Span <byte> checkAgainst = stackalloc byte[3]; data.Slice(start: 0, length: 3).CopyTo(checkAgainst); if (checkAgainst.SequenceEqual(checksum)) { data = data.Slice(start: 3); context.ProgressReadHandler(ref data); } else { context.Disconnect("Incoming checksum error"); } }