<commit_before>/*
 * Copyright 2016-2017 deepstreamHub GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <cstring>

#include <algorithm>
#include <limits>
#include <ostream>

#include <buffer.hpp>
#include <message.hpp>

#include <cassert>


namespace deepstream
{

std::ostream& operator<<(std::ostream& os, Topic topic)
{
	os << static_cast<int>(topic);
	return os;
}


std::ostream& operator<<(std::ostream& os, Action action)
{
	os << static_cast<int>(action);
	return os;
}


std::ostream& operator<<(std::ostream& os, Sender sender)
{
	os << static_cast<int>(sender);
	return os;
}



// The list order follows from lexicographical ordering of its tokens, i.e.,
// A|A <= A|E|INVALID_AUTH_DATA <= A|REQ <= C|A ...
//
// The information about all headers is spread over the three arrays below so
// that `Message::Header::all()` can return a pair of iterators to the
// beginning and the one past the end of the list of headers.  The information
// could be kept in one array (of a struct or a tuple) but the accessing the
// information would be more involved for users of `message.hpp`.
const Message::Header HEADERS[] = {
	Message::Header( Topic::AUTH, Action::REQUEST, true ),
	Message::Header( Topic::AUTH, Action::ERROR_INVALID_AUTH_DATA ),
	Message::Header( Topic::AUTH, Action::ERROR_INVALID_AUTH_MSG ),
	Message::Header( Topic::AUTH, Action::ERROR_TOO_MANY_AUTH_ATTEMPTS ),
	Message::Header( Topic::AUTH, Action::REQUEST ),

	Message::Header( Topic::CONNECTION, Action::CHALLENGE_RESPONSE, true ),
	Message::Header( Topic::CONNECTION, Action::CHALLENGE ),
	Message::Header( Topic::CONNECTION, Action::CHALLENGE_RESPONSE ),
	Message::Header( Topic::CONNECTION, Action::REDIRECT ),
	Message::Header( Topic::CONNECTION, Action::REJECT ),

	Message::Header( Topic::EVENT, Action::LISTEN, true ),
	Message::Header( Topic::EVENT, Action::SUBSCRIBE, true ),
	Message::Header( Topic::EVENT, Action::UNSUBSCRIBE, true ),
	Message::Header( Topic::EVENT, Action::LISTEN ),
	Message::Header( Topic::EVENT, Action::SUBSCRIBE ),
	Message::Header( Topic::EVENT, Action::UNSUBSCRIBE )
};

const std::size_t NUM_HEADERS = sizeof(HEADERS) / sizeof(HEADERS[0]);

const char* HEADER_TO_STRING[] = {
	"A|A",
	"A|E|INVALID_AUTH_DATA",
	"A|E|INVALID_AUTH_MSG",
	"A|E|TOO_MANY_AUTH_ATTEMPTS",
	"A|REQ",

	"C|A",
	"C|CH",
	"C|CHR",
	"C|RED",
	"C|REJ",

	"E|A|L",
	"E|A|S",
	"E|A|US",
	"E|L",
	"E|S",
	"E|US"
};

const std::pair<std::size_t, std::size_t> HEADER_NUM_PAYLOAD[] = {
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(1, 1),

	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(0, 1),

	std::pair<std::size_t, std::size_t>(2, 2),
	std::pair<std::size_t, std::size_t>(2, 2),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(2, 2)
};


#define DS_COUNT(XS) (sizeof(XS)/sizeof(XS[0]))
static_assert( DS_COUNT(HEADERS) == DS_COUNT(HEADER_TO_STRING), "" );
static_assert( DS_COUNT(HEADERS) == DS_COUNT(HEADER_NUM_PAYLOAD), "" );


std::pair<const Message::Header*, const Message::Header*> Message::Header::all()
{
	return std::make_pair( HEADERS, HEADERS+NUM_HEADERS );
}


const char* Message::Header::to_string(Topic topic, Action action, bool is_ack)<commit_msg>Src: fix expected number of arguments in messages<commit_after>/*
 * Copyright 2016-2017 deepstreamHub GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <cstring>

#include <algorithm>
#include <limits>
#include <ostream>

#include <buffer.hpp>
#include <message.hpp>

#include <cassert>


namespace deepstream
{

std::ostream& operator<<(std::ostream& os, Topic topic)
{
	os << static_cast<int>(topic);
	return os;
}


std::ostream& operator<<(std::ostream& os, Action action)
{
	os << static_cast<int>(action);
	return os;
}


std::ostream& operator<<(std::ostream& os, Sender sender)
{
	os << static_cast<int>(sender);
	return os;
}



// The list order follows from lexicographical ordering of its tokens, i.e.,
// A|A <= A|E|INVALID_AUTH_DATA <= A|REQ <= C|A ...
//
// The information about all headers is spread over the three arrays below so
// that `Message::Header::all()` can return a pair of iterators to the
// beginning and the one past the end of the list of headers.  The information
// could be kept in one array (of a struct or a tuple) but the accessing the
// information would be more involved for users of `message.hpp`.
const Message::Header HEADERS[] = {
	Message::Header( Topic::AUTH, Action::REQUEST, true ),
	Message::Header( Topic::AUTH, Action::ERROR_INVALID_AUTH_DATA ),
	Message::Header( Topic::AUTH, Action::ERROR_INVALID_AUTH_MSG ),
	Message::Header( Topic::AUTH, Action::ERROR_TOO_MANY_AUTH_ATTEMPTS ),
	Message::Header( Topic::AUTH, Action::REQUEST ),

	Message::Header( Topic::CONNECTION, Action::CHALLENGE_RESPONSE, true ),
	Message::Header( Topic::CONNECTION, Action::CHALLENGE ),
	Message::Header( Topic::CONNECTION, Action::CHALLENGE_RESPONSE ),
	Message::Header( Topic::CONNECTION, Action::REDIRECT ),
	Message::Header( Topic::CONNECTION, Action::REJECT ),

	Message::Header( Topic::EVENT, Action::LISTEN, true ),
	Message::Header( Topic::EVENT, Action::SUBSCRIBE, true ),
	Message::Header( Topic::EVENT, Action::UNSUBSCRIBE, true ),
	Message::Header( Topic::EVENT, Action::LISTEN ),
	Message::Header( Topic::EVENT, Action::SUBSCRIBE ),
	Message::Header( Topic::EVENT, Action::UNSUBSCRIBE )
};

const std::size_t NUM_HEADERS = sizeof(HEADERS) / sizeof(HEADERS[0]);

const char* HEADER_TO_STRING[] = {
	"A|A",
	"A|E|INVALID_AUTH_DATA",
	"A|E|INVALID_AUTH_MSG",
	"A|E|TOO_MANY_AUTH_ATTEMPTS",
	"A|REQ",

	"C|A",
	"C|CH",
	"C|CHR",
	"C|RED",
	"C|REJ",

	"E|A|L",
	"E|A|S",
	"E|A|US",
	"E|L",
	"E|S",
	"E|US"
};

const std::pair<std::size_t, std::size_t> HEADER_NUM_PAYLOAD[] = {
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),

	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(0, 0),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(0, 1),

	std::pair<std::size_t, std::size_t>(2, 2),
	std::pair<std::size_t, std::size_t>(2, 2),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(1, 1),
	std::pair<std::size_t, std::size_t>(2, 2)
};


#define DS_COUNT(XS) (sizeof(XS)/sizeof(XS[0]))
static_assert( DS_COUNT(HEADERS) == DS_COUNT(HEADER_TO_STRING), "" );
static_assert( DS_COUNT(HEADERS) == DS_COUNT(HEADER_NUM_PAYLOAD), "" );


std::pair<const Message::Header*, const Message::Header*> Message::Header::all()
{
	return std::make_pair( HEADERS, HEADERS+NUM_HEADERS );
}


const char* Message::Header::to_string(Topic topic, Action action, bool is_ack)
{'fraction_non_alphanumeric': 0.17683220829315333, 'fraction_numerical': 0.011089681774349084, 'mean_word_length': 6.140275387263339, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3691788', 'n_tokens_mistral': 3121, 'n_tokens_neox': 3023, 'n_words': 728}