<commit_before>
#ifndef __CLUSTERING_SERIALIZE_HPP__
#define __CLUSTERING_SERIALIZE_HPP__

#include "arch/arch.hpp"

/* Serializing and unserializing built-in integer types */

void serialize(tcp_conn_t *conn, bool b) {
    conn->write(&b, sizeof(b));
}

void unserialize(tcp_conn_t *conn, bool *b) {
    conn->read(b, sizeof(*b));
}

void serialize(tcp_conn_t *conn, int i) {
    conn->write(&i, sizeof(i));
}

void unserialize(tcp_conn_t *conn, int *i) {
    conn->read(i, sizeof(*i));
}

void serialize(tcp_conn_t *conn, char c) {
    conn->write(&c, 1);
}

void unserialize(tcp_conn_t *conn, char *c) {
    conn->read(c, 1);
}

/* Serializing and unserializing std::string */

void serialize(tcp_conn_t *conn, const std::string &s) {
    int count = s.size();
    conn->write(&count, sizeof(int));
    conn->write(s.data(), count);
}

void unserialize(tcp_conn_t *conn, std::string *s) {
    int count;
    conn->read(&count, sizeof(int));
    char buffer[count];   // Makes an extra copy... Can we fix that?
    conn->read(buffer, count);
    s->assign(buffer, count);
}

/* Serializing and unserializing std::vector of a serializable type */

template<class element_t>
void serialize(tcp_conn_t *conn, const std::vector<element_t> &e) {
    serialize(conn, e.size());
    for (int i = 0; i < e.size(); i++) {
        serialize(conn, e[i]);
    }
}

template<class element_t>
void unserialize(tcp_conn_t *conn, std::vector<element_t> *e) {
    int count;
    unserialize(conn, &count);
    e->resize(count);
    for (int i = 0; i < count; i++) {
        unserialize(conn, &e[i]);
    }
}

/* Serializing and unserializing ip_address_t */

void serialize(tcp_conn_t *conn, const ip_address_t &addr) {
    assert(sizeof(addr) == 4);
    conn->write(&addr, sizeof(addr));
}

void unserialize(tcp_conn_t *conn, ip_address_t *addr) {
    assert(sizeof(*addr) == 4);
    conn->read(addr, sizeof(*addr));
}

#endif /* __CLUSTERING_SERIALIZE_HPP__ */<commit_msg>Changed some assert()s to rassert()s.<commit_after>
#ifndef __CLUSTERING_SERIALIZE_HPP__
#define __CLUSTERING_SERIALIZE_HPP__

#include "arch/arch.hpp"

/* Serializing and unserializing built-in integer types */

void serialize(tcp_conn_t *conn, bool b) {
    conn->write(&b, sizeof(b));
}

void unserialize(tcp_conn_t *conn, bool *b) {
    conn->read(b, sizeof(*b));
}

void serialize(tcp_conn_t *conn, int i) {
    conn->write(&i, sizeof(i));
}

void unserialize(tcp_conn_t *conn, int *i) {
    conn->read(i, sizeof(*i));
}

void serialize(tcp_conn_t *conn, char c) {
    conn->write(&c, 1);
}

void unserialize(tcp_conn_t *conn, char *c) {
    conn->read(c, 1);
}

/* Serializing and unserializing std::string */

void serialize(tcp_conn_t *conn, const std::string &s) {
    int count = s.size();
    conn->write(&count, sizeof(int));
    conn->write(s.data(), count);
}

void unserialize(tcp_conn_t *conn, std::string *s) {
    int count;
    conn->read(&count, sizeof(int));
    char buffer[count];   // Makes an extra copy... Can we fix that?
    conn->read(buffer, count);
    s->assign(buffer, count);
}

/* Serializing and unserializing std::vector of a serializable type */

template<class element_t>
void serialize(tcp_conn_t *conn, const std::vector<element_t> &e) {
    serialize(conn, e.size());
    for (int i = 0; i < e.size(); i++) {
        serialize(conn, e[i]);
    }
}

template<class element_t>
void unserialize(tcp_conn_t *conn, std::vector<element_t> *e) {
    int count;
    unserialize(conn, &count);
    e->resize(count);
    for (int i = 0; i < count; i++) {
        unserialize(conn, &e[i]);
    }
}

/* Serializing and unserializing ip_address_t */

void serialize(tcp_conn_t *conn, const ip_address_t &addr) {
    rassert(sizeof(addr) == 4);
    conn->write(&addr, sizeof(addr));
}

void unserialize(tcp_conn_t *conn, ip_address_t *addr) {
    rassert(sizeof(*addr) == 4);
    conn->read(addr, sizeof(*addr));
}

#endif /* __CLUSTERING_SERIALIZE_HPP__ */
{'fraction_non_alphanumeric': 0.1650608519269777, 'fraction_numerical': 0.0030425963488843813, 'mean_word_length': 4.031887755102041, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, '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': '2202122', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1451, 'n_words': 340}