class StringMatchResultOutput<K, V> extends CommandOutput<K, V, StringMatchResult> {

    private final boolean withIdx;

    private String matchString;

    private int len;

    private List<Long> positions;

    private final List<MatchedPosition> matchedPositions = new ArrayList<>();

    public StringMatchResultOutput(RedisCodec<K, V> codec, boolean withIdx) {
        super(codec, null);
        this.withIdx = withIdx;
    }

    @Override
    public void set(ByteBuffer bytes) {

        if (!withIdx && matchString == null) {
            matchString = (String) codec.decodeKey(bytes);
        }
    }

    @Override
    public void set(long integer) {

        this.len = (int) integer;

        if (positions == null) {
            positions = new ArrayList<>();
        }
        positions.add(integer);
    }

    @Override
    public void complete(int depth) {

        if (depth == 2) {
            matchedPositions.add(buildMatchedString(positions));
            positions = null;
        }

        if (depth == 0) {
            output = new StringMatchResult(matchString, matchedPositions, len);
        }
    }

    private static MatchedPosition buildMatchedString(List<Long> positions) {<FILL_FUNCTION_BODY>}

}


        if (positions == null) {
            throw new IllegalStateException("No matched positions");
        }

        int size = positions.size();
        // not WITHMATCHLEN
        long matchLen = size % 2 == 0 ? 0L : positions.get(size - 1);
        return new MatchedPosition(new Position(positions.get(0), positions.get(1)),
                new Position(positions.get(2), positions.get(3)), matchLen);
    
<methods>public void <init>(RedisCodec<K,V>, io.lettuce.core.StringMatchResult) ,public void complete(int) ,public io.lettuce.core.StringMatchResult get() ,public java.lang.String getError() ,public boolean hasError() ,public void multi(int) ,public void multiArray(int) ,public void multiMap(int) ,public void multiPush(int) ,public void multiSet(int) ,public void set(java.nio.ByteBuffer) ,public void set(long) ,public void set(double) ,public void set(boolean) ,public void setBigNumber(java.nio.ByteBuffer) ,public void setError(java.nio.ByteBuffer) ,public void setError(java.lang.String) ,public void setSingle(java.nio.ByteBuffer) ,public java.lang.String toString() <variables>protected final non-sealed RedisCodec<K,V> codec,protected java.lang.String error,protected io.lettuce.core.StringMatchResult output