<commit_before>//
//
// Copyright (c) 2017 <NAME> (basiliscos) (the dot dmol at gmail dot com)
//
// Distributed under the MIT Software License
//

#pragma once

#include <atomic>
#include <initializer_list>
#include <mutex>
#include <queue>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>

#include <boost/asio.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/handler_type.hpp>
#include <boost/utility/string_ref.hpp>

#include "Command.hpp"
#include "Error.hpp"
#include "Protocol.hpp"
#include "Result.hpp"

namespace bredis {

#define BREDIS_PARSE_RESULT(B)                                                 \
    positive_parse_result_t<typename to_iterator<B>::iterator_t>

template <typename NextLayer> class Connection {

  private:
    NextLayer stream_;

  public:
    template <typename... Args>
    Connection(Args &&... args) : stream_(std::forward<Args>(args)...) {}

    inline NextLayer &next_layer() { return stream_; }
    inline const NextLayer &next_layer() const { return stream_; }

    /* asynchronous interface */
    template <typename WriteCallback, typename DynamicBuffer>
    BOOST_ASIO_INITFN_RESULT_TYPE(WriteCallback,
                                  void(boost::system::error_code, std::size_t))
    async_write(DynamicBuffer &tx_buff, const command_wrapper_t &command,
                WriteCallback write_callback);

    template <typename ReadCallback, typename DynamicBuffer>
    BOOST_ASIO_INITFN_RESULT_TYPE(ReadCallback,
                                  void(boost::system::error_code,
                                       BREDIS_PARSE_RESULT(DynamicBuffer)))
    async_read(DynamicBuffer &rx_buff, ReadCallback read_callback,
               std::size_t replies_count = 1);

    /* synchronous interface */
    void write(const command_wrapper_t &command);
    void write(const command_wrapper_t &command, boost::system::error_code &ec);

    template <typename DynamicBuffer>
    positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
    read(DynamicBuffer &rx_buff);

    template <typename DynamicBuffer>
    positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
    read(DynamicBuffer &rx_buff, boost::system::error_code &ec);<commit_msg>Vinnie's feedback: add `explicit`<commit_after>//
//
// Copyright (c) 2017 <NAME> (basiliscos) (the dot dmol at gmail dot com)
//
// Distributed under the MIT Software License
//

#pragma once

#include <atomic>
#include <initializer_list>
#include <mutex>
#include <queue>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>

#include <boost/asio.hpp>
#include <boost/asio/async_result.hpp>
#include <boost/asio/handler_type.hpp>
#include <boost/utility/string_ref.hpp>

#include "Command.hpp"
#include "Error.hpp"
#include "Protocol.hpp"
#include "Result.hpp"

namespace bredis {

#define BREDIS_PARSE_RESULT(B)                                                 \
    positive_parse_result_t<typename to_iterator<B>::iterator_t>

template <typename NextLayer> class Connection {

  private:
    NextLayer stream_;

  public:
    template <typename... Args>
    explicit Connection(Args &&... args)
        : stream_(std::forward<Args>(args)...) {}

    inline NextLayer &next_layer() { return stream_; }
    inline const NextLayer &next_layer() const { return stream_; }

    /* asynchronous interface */
    template <typename WriteCallback, typename DynamicBuffer>
    BOOST_ASIO_INITFN_RESULT_TYPE(WriteCallback,
                                  void(boost::system::error_code, std::size_t))
    async_write(DynamicBuffer &tx_buff, const command_wrapper_t &command,
                WriteCallback write_callback);

    template <typename ReadCallback, typename DynamicBuffer>
    BOOST_ASIO_INITFN_RESULT_TYPE(ReadCallback,
                                  void(boost::system::error_code,
                                       BREDIS_PARSE_RESULT(DynamicBuffer)))
    async_read(DynamicBuffer &rx_buff, ReadCallback read_callback,
               std::size_t replies_count = 1);

    /* synchronous interface */
    void write(const command_wrapper_t &command);
    void write(const command_wrapper_t &command, boost::system::error_code &ec);

    template <typename DynamicBuffer>
    positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
    read(DynamicBuffer &rx_buff);

    template <typename DynamicBuffer>
    positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
    read(DynamicBuffer &rx_buff, boost::system::error_code &ec);
{'fraction_non_alphanumeric': 0.10616363237552094, 'fraction_numerical': 0.0021934634788330775, 'mean_word_length': 3.5103857566765577, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1658254', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1285, 'n_words': 295}