<commit_before>//
// Aspia Project
// Copyright (C) 2020 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef BASE__MEMORY__BYTE_ARRAY_H
#define BASE__MEMORY__BYTE_ARRAY_H

#include "build/build_config.h"

#include <google/protobuf/message_lite.h>

#if defined(USE_TBB)
#include <tbb/scalable_allocator.h>
#endif // defined(USE_TBB)

#include <cstdint>
#include <string>
#include <vector>

namespace base {

#if defined(USE_TBB)
using ByteArrayAllocator = tbb::scalable_allocator<uint8_t>;
#else // defined(USE_TBB)
using ByteArrayAllocator = std::allocator<uint8_t>;
#endif // defined(USE_*)

using ByteArray = std::vector<uint8_t, ByteArrayAllocator>;

ByteArray fromData(const void* data, size_t size);

ByteArray fromStdString(std::string_view in);
std::string toStdString(const ByteArray& in);

ByteArray fromHex(std::string_view in);
std::string toHex(const ByteArray& in);

base::ByteArray serialize(const google::protobuf::MessageLite& message);

template <class T>
bool parse(const base::ByteArray& buffer, T* message)
{
    return message->ParseFromArray(buffer.data(), buffer.size());
}

int compare(const base::ByteArray& first, const base::ByteArray& second);

std::ostream& operator<<(std::ostream& out, const ByteArray& bytearray);

} // namespace base

#endif // BASE__MEMORY__BYTE_ARRAY_H<commit_msg>Implemented equals function.<commit_after>//
// Aspia Project
// Copyright (C) 2020 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#ifndef BASE__MEMORY__BYTE_ARRAY_H
#define BASE__MEMORY__BYTE_ARRAY_H

#include "build/build_config.h"

#include <google/protobuf/message_lite.h>

#if defined(USE_TBB)
#include <tbb/scalable_allocator.h>
#endif // defined(USE_TBB)

#include <cstdint>
#include <string>
#include <vector>

namespace base {

#if defined(USE_TBB)
using ByteArrayAllocator = tbb::scalable_allocator<uint8_t>;
#else // defined(USE_TBB)
using ByteArrayAllocator = std::allocator<uint8_t>;
#endif // defined(USE_*)

using ByteArray = std::vector<uint8_t, ByteArrayAllocator>;

ByteArray fromData(const void* data, size_t size);

ByteArray fromStdString(std::string_view in);
std::string toStdString(const ByteArray& in);

ByteArray fromHex(std::string_view in);
std::string toHex(const ByteArray& in);

base::ByteArray serialize(const google::protobuf::MessageLite& message);

template <class T>
bool parse(const base::ByteArray& buffer, T* message)
{
    return message->ParseFromArray(buffer.data(), buffer.size());
}

int compare(const base::ByteArray& first, const base::ByteArray& second);

inline bool equals(const base::ByteArray& first, const base::ByteArray& second)
{
    return compare(first, second) == 0;
}

std::ostream& operator<<(std::ostream& out, const ByteArray& bytearray);

} // namespace base

#endif // BASE__MEMORY__BYTE_ARRAY_H
{'fraction_non_alphanumeric': 0.11685728493286922, 'fraction_numerical': 0.004226752859273993, 'mean_word_length': 5.208333333333333, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '4380029', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1221, 'n_words': 409}