Přeskočit obsah

PQ0006 — Frame parser must implement Parse

The adapter's IFrameParser<TFrame> class declares TryParse(ref ReadOnlySequence<byte>, out TFrame). The framework never calls it.

// reported — the earlier contract, never called
public sealed class AcmeFrameParser : IFrameParser<AcmeFrame>
{
    public bool TryParse(ref ReadOnlySequence<byte> buffer, out AcmeFrame frame) { ... }
}

Why it is reported

The adapter receives no frames. The connection reads frames through Parse(ReadOnlySpan<byte> data, out TFrame? frame). A parser that has only TryParse also fails with CS0535; that error does not say where the migration steps are, so this one does.

A leftover is dead code. A parser that already has Parse and still keeps TryParse carries a second, unused implementation of the same framing.

How to fix it

Implement Parse and delete TryParse. The steps, with a before/after table, are in 0004 — Frame parser: Parse over a span.

public sealed class AcmeFrameParser : IFrameParser<AcmeFrame>
{
    public ParseResult Parse(ReadOnlySpan<byte> data, out AcmeFrame? frame)
    {
        frame = null;
        if (data[0] != 0xAB)
            return ParseResult.Skip(1);

        if (data.Length < 2 || data.Length < data[1] + 4)
            return ParseResult.NeedMore;

        frame = AcmeFrame.Decode(data[..(data[1] + 4)]);
        return ParseResult.Frame(data[1] + 4);
    }
}