<commit_before>/*!
    \file record.inl
    \brief Logging record inline implementation
    \author <NAME>
    \date 08.07.2016
    \copyright MIT License
*/

namespace CppLogging {

//! @cond INTERNALS
namespace Internals {

template <typename Char, typename T>
std::size_t CalculateExtraSize(const fmt::internal::Arg& arg)
{
    std::size_t result = 0;

    if (arg.type == fmt::internal::Arg::CSTRING)
        result = sizeof(std::size_t) + (std::strlen(arg.string.value) + 1) * sizeof(char);
    else if (arg.type == fmt::internal::Arg::STRING)
        result = sizeof(std::size_t) + arg.string.size * sizeof(char);
    else if (arg.type == fmt::internal::Arg::WSTRING)
        result = sizeof(std::size_t) + arg.wstring.size * sizeof(wchar_t);
    else if (arg.type == fmt::internal::Arg::CUSTOM)
        result = sizeof(T);

    return result;
}

template <typename Char>
unsigned CalculateBufferSize(std::size_t&)
{
    return 0;
}

template <typename Char, typename T>
unsigned CalculateBufferSize(std::size_t& extra_size, const fmt::internal::NamedArgWithType<Char, T>& argument)
{
    extra_size += sizeof(fmt::internal::NamedArgWithType<Char, T>) + sizeof(std::size_t) + argument.name.size() * sizeof(Char) + CalculateExtraSize<Char, fmt::internal::NamedArgWithType<Char, T>>(argument);
    return 1;
}

template <typename Char, typename T>
unsigned CalculateBufferSize(std::size_t& extra_size, const T& argument)
{
    fmt::internal::MakeArg<fmt::BasicFormatter<Char>> arg(argument);
    extra_size += CalculateExtraSize<Char, T>(arg);
    return 1;
}

template <typename Char, typename T, typename... Args>
unsigned CalculateBufferSize(std::size_t& extra_size, const T& argument, const Args&... args)
{
    unsigned count = 0;
    count += CalculateBufferSize<Char>(extra_size, argument);
    count += CalculateBufferSize<Char>(extra_size, args...);
    return count;
}

template <typename Char, typename T>
void SerializeExtraData(uint8_t*& data_buffer, const fmt::internal::NamedArgWithType<Char, T>& named)
{
    std::memcpy(data_buffer, &named, sizeof(fmt::internal::NamedArgWithType<Char, T>));
    data_buffer += sizeof(fmt::internal::NamedArgWithType<Char, T>);
    std::size_t size = named.name.size() * sizeof(Char);
    std::memcpy(data_buffer, &size, sizeof(std::size_t));
    data_buffer += sizeof(std::size_t);
    std::memcpy(data_buffer, named.name.data(), size);
    data_buffer += size;
    SerializeExtraData<Char, T>(data_buffer, named.type, named);
}

template <typename Char, typename T>
void SerializeExtraData(uint8_t*& data_buffer, fmt::internal::Arg::Type type, const fmt::internal::Value& value)
{
    // Serialize extra data
    if (type == fmt::internal::Arg::CSTRING)
    {
        std::size_t size = (std::strlen(value.string.value) + 1) * sizeof(char);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.string.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::STRING)
    {
        std::size_t size = value.string.size * sizeof(char);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.string.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::WSTRING)
    {
        std::size_t size = value.wstring.size * sizeof(wchar_t);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.wstring.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::CUSTOM)
    {
        std::size_t size = sizeof(T);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.custom.value, size);
        data_buffer += size;
    }
}

template <typename Char>
void SerializeArguments(std::size_t, uint8_t*&, uint8_t*&)
{
}

template <typename Char, typename T>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const fmt::internal::NamedArgWithType<Char, T>& argument)
{
    // Serialize argument
    const fmt::internal::Arg& arg = argument;
    std::memcpy(base_buffer, &arg, item_size);
    base_buffer += item_size;
    // Serialize extra data
    SerializeExtraData<Char, T>(data_buffer, argument);
}

template <typename Char, typename T>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const T& argument)
{
    // Serialize argument
    fmt::internal::MakeArg<fmt::BasicFormatter<Char>> arg(argument);
    std::memcpy(base_buffer, &arg, item_size);
    base_buffer += item_size;
    // Serialize extra data
    SerializeExtraData<Char, T>(data_buffer, arg.type, arg);
}

template <typename Char, typename T, typename... Args>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const T& argument, const Args&... args)
{
    SerializeArguments<Char>(item_size, base_buffer, data_buffer, argument);
    SerializeArguments<Char>(item_size, base_buffer, data_buffer, args...);
}

template <typename Char, typename... Args>
void Serialize(std::vector<uint8_t>& buffer, const Args&... args)
{
    std::size_t extra_size = 0;
    unsigned count = CalculateBufferSize<Char>(extra_size, args...);

    // Special check for none format arguments
    if (count == 0)
        return;
<commit_msg>build<commit_after>/*!
    \file record.inl
    \brief Logging record inline implementation
    \author <NAME>
    \date 08.07.2016
    \copyright MIT License
*/

namespace CppLogging {

//! @cond INTERNALS
namespace Internals {

template <typename Char, typename T>
std::size_t CalculateExtraSize(const fmt::internal::Arg& arg)
{
    std::size_t result = 0;

    if (arg.type == fmt::internal::Arg::CSTRING)
        result = sizeof(std::size_t) + (std::strlen(arg.string.value) + 1) * sizeof(char);
    else if (arg.type == fmt::internal::Arg::STRING)
        result = sizeof(std::size_t) + arg.string.size * sizeof(char);
    else if (arg.type == fmt::internal::Arg::WSTRING)
        result = sizeof(std::size_t) + arg.wstring.size * sizeof(wchar_t);
    else if (arg.type == fmt::internal::Arg::CUSTOM)
        result = sizeof(T);

    return result;
}

template <typename Char>
unsigned CalculateBufferSize(std::size_t&)
{
    return 0;
}

template <typename Char, typename T>
unsigned CalculateBufferSize(std::size_t& extra_size, const T& argument)
{
    fmt::internal::MakeArg<fmt::BasicFormatter<Char>> arg(argument);
    extra_size += CalculateExtraSize<Char, T>(arg);
    return 1;
}

template <typename Char, typename T>
unsigned CalculateBufferSize(std::size_t& extra_size, const fmt::internal::NamedArgWithType<Char, T>& argument)
{
    extra_size += sizeof(fmt::internal::NamedArgWithType<Char, T>) + sizeof(std::size_t) + argument.name.size() * sizeof(Char) + CalculateExtraSize<Char, fmt::internal::NamedArgWithType<Char, T>>(argument);
    return 1;
}

template <typename Char, typename T, typename... Args>
unsigned CalculateBufferSize(std::size_t& extra_size, const T& argument, const Args&... args)
{
    unsigned count = 0;
    count += CalculateBufferSize<Char>(extra_size, argument);
    count += CalculateBufferSize<Char>(extra_size, args...);
    return count;
}

template <typename Char, typename T>
void SerializeExtraData(uint8_t*& data_buffer, fmt::internal::Arg::Type type, const fmt::internal::Value& value)
{
    // Serialize extra data
    if (type == fmt::internal::Arg::CSTRING)
    {
        std::size_t size = (std::strlen(value.string.value) + 1) * sizeof(char);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.string.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::STRING)
    {
        std::size_t size = value.string.size * sizeof(char);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.string.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::WSTRING)
    {
        std::size_t size = value.wstring.size * sizeof(wchar_t);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.wstring.value, size);
        data_buffer += size;
    }
    else if (type == fmt::internal::Arg::CUSTOM)
    {
        std::size_t size = sizeof(T);
        std::memcpy(data_buffer, &size, sizeof(std::size_t));
        data_buffer += sizeof(std::size_t);
        std::memcpy(data_buffer, value.custom.value, size);
        data_buffer += size;
    }
}

template <typename Char, typename T>
void SerializeExtraData(uint8_t*& data_buffer, const fmt::internal::NamedArgWithType<Char, T>& named)
{
    std::memcpy(data_buffer, &named, sizeof(fmt::internal::NamedArgWithType<Char, T>));
    data_buffer += sizeof(fmt::internal::NamedArgWithType<Char, T>);
    std::size_t size = named.name.size() * sizeof(Char);
    std::memcpy(data_buffer, &size, sizeof(std::size_t));
    data_buffer += sizeof(std::size_t);
    std::memcpy(data_buffer, named.name.data(), size);
    data_buffer += size;
    SerializeExtraData<Char, T>(data_buffer, named.type, named);
}

template <typename Char>
void SerializeArguments(std::size_t, uint8_t*&, uint8_t*&)
{
}

template <typename Char, typename T>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const T& argument)
{
    // Serialize argument
    fmt::internal::MakeArg<fmt::BasicFormatter<Char>> arg(argument);
    std::memcpy(base_buffer, &arg, item_size);
    base_buffer += item_size;
    // Serialize extra data
    SerializeExtraData<Char, T>(data_buffer, arg.type, arg);
}

template <typename Char, typename T>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const fmt::internal::NamedArgWithType<Char, T>& argument)
{
    // Serialize argument
    const fmt::internal::Arg& arg = argument;
    std::memcpy(base_buffer, &arg, item_size);
    base_buffer += item_size;
    // Serialize extra data
    SerializeExtraData<Char, T>(data_buffer, argument);
}

template <typename Char, typename T, typename... Args>
void SerializeArguments(std::size_t item_size, uint8_t*& base_buffer, uint8_t*& data_buffer, const T& argument, const Args&... args)
{
    SerializeArguments<Char>(item_size, base_buffer, data_buffer, argument);
    SerializeArguments<Char>(item_size, base_buffer, data_buffer, args...);
}

template <typename Char, typename... Args>
void Serialize(std::vector<uint8_t>& buffer, const Args&... args)
{
    std::size_t extra_size = 0;
    unsigned count = CalculateBufferSize<Char>(extra_size, args...);

    // Special check for none format arguments
    if (count == 0)
        return;

{'fraction_non_alphanumeric': 0.1488667271078876, 'fraction_numerical': 0.005077062556663644, 'mean_word_length': 4.36266407389402, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1652062', 'n_tokens_mistral': 3619, 'n_tokens_neox': 3550, 'n_words': 782}