class PostgreSQLAuthenticationEngine implements AuthenticationEngine {

    @Override
    public AuthenticationResult auth(final ChannelHandlerContext context, final PacketPayload payload) {
        if (SSL_REQUEST_PAYLOAD_LENGTH == payload.getByteBuf().markReaderIndex().readInt() && SSL_REQUEST_CODE == payload.getByteBuf().readInt()) {
            context.writeAndFlush(new PostgreSQLSSLNegativePacket());
            return AuthenticationResultBuilder.continued();
        }
        payload.getByteBuf().resetReaderIndex();
        if (!startupMessageReceived.get()) {
            return beforeStartupMessage(context, (PostgreSQLPacketPayload) payload);
        } else {
            return afterStartupMessage(context, (PostgreSQLPacketPayload) payload);
        }
    }

}