<commit_before>/*
  Copyright (c) 2012 <NAME>

  This file is part of libcql.

  libcql is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  libcql is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iomanip>
#include <sstream>

#include "serialization.hpp"
#include "util.hpp"
#include "cql_message_query.hpp"


cql::cql_message_query_t::cql_message_query_t() :
    _consistency(0),
    _query()
{}

cql::cql_message_query_t::cql_message_query_t(const std::string& query,
                                              cql_short_t consistency) :
    _consistency(consistency),
    _query(query)
{}

const std::string&
cql::cql_message_query_t::query() const
{
    return _query;
}

cql_short_t
cql::cql_message_query_t::consistency() const
{
    return _consistency;
}

void
cql::cql_message_query_t::query(const std::string& q)
{
    _query = q;
}

void
cql::cql_message_query_t::consistency(cql_short_t consistency)
{
    _consistency = consistency;
}

cql_byte_t
cql::cql_message_query_t::opcode() const
{
    return CQL_OPCODE_QUERY;
}

cql_int_t
cql::cql_message_query_t::size() const
{
    std::stringstream ss(std::stringstream::out);
    write(ss);
    return ss.str().size();
}

std::string
cql::cql_message_query_t::str() const
{
    std::stringstream output;
    output << _query;
    output << " " << std::setfill('0') << std::string("0x") << std::setw(2);
    output << cql::internal::hex(_consistency);
    return output.str();
}

std::istream&
cql::cql_message_query_t::read(std::istream& input)
{
    cql::internal::decode_long_string(input, _query);
    input.read(reinterpret_cast<char*>(&_consistency), sizeof(_consistency));
    _consistency = ntohs(_consistency);
    return input;
}

std::ostream&
cql::cql_message_query_t::write(std::ostream& output) const
{
    cql::internal::encode_long_string(output, _query);
    cql_short_t consistency = htons(_consistency);
    output.write(reinterpret_cast<char*>(&consistency), sizeof(consistency));
    return output;
}
<commit_msg>use the central serialization methods for encoding the consistency of a query message<commit_after>/*
  Copyright (c) 2012 <NAME>

  This file is part of libcql.

  libcql is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
  (at your option) any later version.

  libcql is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <iomanip>
#include <sstream>

#include "serialization.hpp"
#include "util.hpp"
#include "cql_message_query.hpp"


cql::cql_message_query_t::cql_message_query_t() :
    _consistency(0),
    _query()
{}

cql::cql_message_query_t::cql_message_query_t(const std::string& query,
                                              cql_short_t consistency) :
    _consistency(consistency),
    _query(query)
{}

const std::string&
cql::cql_message_query_t::query() const
{
    return _query;
}

cql_short_t
cql::cql_message_query_t::consistency() const
{
    return _consistency;
}

void
cql::cql_message_query_t::query(const std::string& q)
{
    _query = q;
}

void
cql::cql_message_query_t::consistency(cql_short_t consistency)
{
    _consistency = consistency;
}

cql_byte_t
cql::cql_message_query_t::opcode() const
{
    return CQL_OPCODE_QUERY;
}

cql_int_t
cql::cql_message_query_t::size() const
{
    std::stringstream ss(std::stringstream::out);
    write(ss);
    return ss.str().size();
}

std::string
cql::cql_message_query_t::str() const
{
    std::stringstream output;
    output << _query;
    output << " " << std::setfill('0') << std::string("0x") << std::setw(2);
    output << cql::internal::hex(_consistency);
    return output.str();
}

std::istream&
cql::cql_message_query_t::read(std::istream& input)
{
    cql::internal::decode_long_string(input, _query);
    input.read(reinterpret_cast<char*>(&_consistency), sizeof(_consistency));
    _consistency = ntohs(_consistency);
    return input;
}

std::ostream&
cql::cql_message_query_t::write(std::ostream& output) const
{
    cql::internal::encode_long_string(output, _query);
    cql::internal::encode_short(output, _consistency);
    return output;
}

{'fraction_non_alphanumeric': 0.11710110584518167, 'fraction_numerical': 0.0035545023696682463, 'mean_word_length': 4.565934065934066, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6927949', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1680, 'n_words': 419}