@Override
    public Result detect(ChannelBuffer in) {
        int prefaceLen = clientPrefaceString.readableBytes();
        int bytesRead = min(in.readableBytes(), prefaceLen);

        // If the input so far doesn't match the preface, break the connection.
        if (bytesRead == 0 || !ChannelBuffers.prefixEquals(in, clientPrefaceString, bytesRead)) {
            return Result.UNRECOGNIZED;
        }
        if (bytesRead == prefaceLen) {
            return Result.RECOGNIZED;
        }
        return Result.NEED_MORE_DATA;
    }
@Test
    void testDetect() {
        ProtocolDetector detector = new Http2ProtocolDetector();
        ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);

        ByteBuf connectionPrefaceBuf = Http2CodecUtil.connectionPrefaceBuf();
        ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer();
        ChannelBuffer in = new ByteBufferBackedChannelBuffer(byteBuf.nioBuffer());
        ProtocolDetector.Result result = detector.detect(in);
        Assertions.assertEquals(result, ProtocolDetector.Result.UNRECOGNIZED);

        byteBuf.writeBytes(connectionPrefaceBuf);
        result = detector.detect(new ByteBufferBackedChannelBuffer(byteBuf.nioBuffer()));
        Assertions.assertEquals(result, ProtocolDetector.Result.RECOGNIZED);

        byteBuf.clear();
        byteBuf.writeBytes(connectionPrefaceBuf, 0, 1);
        result = detector.detect(new ByteBufferBackedChannelBuffer(byteBuf.nioBuffer()));
        Assertions.assertEquals(result, ProtocolDetector.Result.NEED_MORE_DATA);
    }