<commit_before>#include "data_type.hpp"

#include <bitcoin/format.hpp>

namespace libbitcoin {

// readable_data_type

void readable_data_type::set(uint32_t value)
{
    data_buffer_ = uncast_type(value);
    prepare();
}

void readable_data_type::set(const data_chunk& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const hash_digest& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const short_hash& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const std::string& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

Dbt* readable_data_type::get()
{
    return &dbt_;
}
const Dbt* readable_data_type::get() const
{
    return &dbt_;
}

void readable_data_type::prepare()
{
    dbt_.set_data(&data_buffer_[0]);
    dbt_.set_ulen(data_buffer_.size());
    dbt_.set_size(data_buffer_.size());
    dbt_.set_flags(DB_DBT_USERMEM);
}

// writable_data_type

writable_data_type::writable_data_type()
{
    dbt_.set_flags(DB_DBT_MALLOC);
}
writable_data_type::~writable_data_type()
{
    free(dbt_.get_data());
}

data_chunk writable_data_type::data() const
{
    std::string raw_depth(reinterpret_cast<const char*>(
        dbt_.get_data()), dbt_.get_size());
    return data_chunk(raw_depth.begin(), raw_depth.end());
}

bool writable_data_type::empty()
{
    return dbt_.get_data() == nullptr;
}

Dbt* writable_data_type::get()
{
    return &dbt_;
}
const Dbt* writable_data_type::get() const<commit_msg>set DB_DBT_READONLY on readable_data_type for bdb<commit_after>#include "data_type.hpp"

#include <bitcoin/format.hpp>

namespace libbitcoin {

// readable_data_type

void readable_data_type::set(uint32_t value)
{
    data_buffer_ = uncast_type(value);
    prepare();
}

void readable_data_type::set(const data_chunk& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const hash_digest& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const short_hash& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

void readable_data_type::set(const std::string& data)
{
    extend_data(data_buffer_, data);
    prepare();
}

Dbt* readable_data_type::get()
{
    return &dbt_;
}
const Dbt* readable_data_type::get() const
{
    return &dbt_;
}

void readable_data_type::prepare()
{
    dbt_.set_data(&data_buffer_[0]);
    dbt_.set_ulen(data_buffer_.size());
    dbt_.set_size(data_buffer_.size());
    dbt_.set_flags(DB_DBT_USERMEM|DB_DBT_READONLY);
}

// writable_data_type

writable_data_type::writable_data_type()
{
    dbt_.set_flags(DB_DBT_MALLOC);
}
writable_data_type::~writable_data_type()
{
    free(dbt_.get_data());
}

data_chunk writable_data_type::data() const
{
    std::string raw_depth(reinterpret_cast<const char*>(
        dbt_.get_data()), dbt_.get_size());
    return data_chunk(raw_depth.begin(), raw_depth.end());
}

bool writable_data_type::empty()
{
    return dbt_.get_data() == nullptr;
}

Dbt* writable_data_type::get()
{
    return &dbt_;
}
const Dbt* writable_data_type::get() const
{'fraction_non_alphanumeric': 0.13954227590591228, 'fraction_numerical': 0.0019071837253655435, 'mean_word_length': 5.294, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7535967', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1182, 'n_words': 176}