Skip to content
Commits on Source (2)
......@@ -529,9 +529,18 @@ target_link_libraries(test_cpp_rfc ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INI
add_executable(test_cpp_raw EXCLUDE_FROM_ALL test/test_cpp_raw.cpp ${HEADERS_ONLY} ${HEADERS})
target_compile_options(
test_cpp_raw PRIVATE
${CXX_COMPILER_FLAGS} "-DTEST_HDR_ONLY"
)
target_link_libraries(test_cpp_raw RaptorQ ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
# CPP interface - RAW interface (linked version)
add_executable(test_cpp_raw_linked EXCLUDE_FROM_ALL test/test_cpp_raw.cpp)
target_compile_options(
test_cpp_raw_linked PRIVATE
${CXX_COMPILER_FLAGS}
)
target_link_libraries(test_cpp_raw ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
add_dependencies(test_cpp_raw_linked RaptorQ)
target_link_libraries(test_cpp_raw_linked RaptorQ ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
# CLI tool - RAW API interface (header only)
set(CLI_raw_sources src/cli/RaptorQ.cpp external/optionparser-1.4/optionparser.h ${HEADERS} ${HEADERS_ONLY})
......
......@@ -20,6 +20,7 @@
#pragma once
#include "RaptorQ/v1/caches.hpp"
#include "RaptorQ/v1/wrapper/CPP_RAW_API.hpp"
#include "RaptorQ/v1/wrapper/CPP_RAW_API_void.hpp"
......@@ -82,8 +82,8 @@ public:
Raw_Decoder() = delete;
Raw_Decoder (const Raw_Decoder&) = delete;
Raw_Decoder& operator= (const Raw_Decoder&) = delete;
Raw_Decoder (Raw_Decoder&&) = default;
Raw_Decoder& operator= (Raw_Decoder&&) = default;
Raw_Decoder (Raw_Decoder&&) = delete;
Raw_Decoder& operator= (Raw_Decoder&&) = delete;
Error add_symbol (In_It &start, const In_It end, const uint32_t esi,
bool padded);
......
......@@ -62,8 +62,8 @@ public:
Raw_Encoder() = delete;
Raw_Encoder (const Raw_Encoder&) = delete;
Raw_Encoder& operator= (const Raw_Encoder&) = delete;
Raw_Encoder (Raw_Encoder&&) = default;
Raw_Encoder& operator= (Raw_Encoder&&) = default;
Raw_Encoder (Raw_Encoder&&) = delete;
Raw_Encoder& operator= (Raw_Encoder&&) = delete;
// set data early so we can encode source symbols without
// having done any precomputation.
......
......@@ -78,8 +78,8 @@ public:
Encoder() = delete;
Encoder (const Encoder&) = delete;
Encoder& operator= (const Encoder&) = delete;
Encoder (Encoder&&) = default;
Encoder& operator= (Encoder&&) = default;
Encoder (Encoder&&) = delete;
Encoder& operator= (Encoder&&) = delete;
~Encoder();
Encoder (const Rnd_It data_from, const Rnd_It data_to,
const uint16_t min_subsymbol_size,
......@@ -228,8 +228,8 @@ public:
//};
Decoder (const Decoder&) = delete;
Decoder& operator= (const Decoder&) = delete;
Decoder (Decoder&&) = default;
Decoder& operator= (Decoder&&) = default;
Decoder (Decoder&&) = delete;
Decoder& operator= (Decoder&&) = delete;
~Decoder();
Decoder (const RFC6330_OTI_Common_Data common,
const RFC6330_OTI_Scheme_Specific_Data scheme)
......
......@@ -71,8 +71,8 @@ public:
Encoder() = delete;
Encoder (const Encoder&) = delete;
Encoder& operator= (const Encoder&) = delete;
Encoder (Encoder &&) = default;
Encoder& operator= (Encoder &&) = default;
Encoder (Encoder &&) = delete;
Encoder& operator= (Encoder &&) = delete;
explicit operator bool() const;
......@@ -136,8 +136,8 @@ public:
const Dec_Report type);
Decoder (const Decoder&) = delete;
Decoder& operator= (const Decoder&) = delete;
Decoder (Decoder &&) = default;
Decoder& operator= (Decoder &&) = default;
Decoder (Decoder &&) = delete;
Decoder& operator= (Decoder &&) = delete;
explicit operator bool() const;
......
......@@ -78,7 +78,14 @@ public:
{
if (_enc == nullptr)
return 0;
#ifdef RQ_HEADER_ONLY
return _enc->encode (start, end, _esi);
#else
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
return _enc->encode (_from, _to, _esi);
start = *reinterpret_cast<Fwd_It*> (_from);
#endif
}
uint32_t id() const
{ return _esi; }
......@@ -145,7 +152,15 @@ public:
{
if (_dec == nullptr)
return Error::INITIALIZATION;
return _dec->decode_symbol (start, end, _esi);
#ifdef RQ_HEADER_ONLY
return _dec->encode (start, end, _esi);
#else
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
return _dec->decode_symbol (_from, _to, _esi);
start = *reinterpret_cast<Fwd_It*> (_from);
#endif
}
uint16_t id() const
{ return _esi; }
......
......@@ -85,17 +85,18 @@ public:
size_t encode (Fwd_It &output, const Fwd_It end, const uint32_t id);
private:
Impl::Encoder_void *_encoder;
Impl::Encoder_void _encoder;
};
template <typename In_It, typename Fwd_It>
class RAPTORQ_API Decoder
{
public:
using Report = Dec_Report;
~Decoder();
Decoder (const Block_Size symbols, const size_t symbol_size,
const Dec_Report type);
const Report type);
Decoder (const Decoder&) = delete;
Decoder& operator= (const Decoder&) = delete;
Decoder (Decoder &&) = default;
......@@ -132,7 +133,7 @@ public:
Decoder_written decode_bytes (Fwd_It &start, const Fwd_It end,
const size_t from_byte, const size_t skip);
private:
Impl::Decoder_void *_decoder;
Impl::Decoder_void _decoder;
};
......@@ -144,92 +145,60 @@ private:
template <>
inline Encoder<uint8_t*, uint8_t*>::Encoder (const Block_Size symbols,
const size_t symbol_size)
{
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_8,
symbols, symbol_size);
}
: _encoder (RaptorQ_type::RQ_ENC_8, symbols, symbol_size)
{}
template <>
inline Encoder<uint16_t*, uint16_t*>::Encoder (const Block_Size symbols,
const size_t symbol_size)
{
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_16,
symbols, symbol_size);
}
: _encoder (RaptorQ_type::RQ_ENC_16, symbols, symbol_size)
{}
template <>
inline Encoder<uint32_t*, uint32_t*>::Encoder (const Block_Size symbols,
const size_t symbol_size)
{
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_32,
symbols, symbol_size);
}
: _encoder (RaptorQ_type::RQ_ENC_32, symbols, symbol_size)
{}
template <>
inline Encoder<uint64_t, uint64_t*>::Encoder (const Block_Size symbols,
const size_t symbol_size)
{
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_64,
symbols, symbol_size);
}
: _encoder (RaptorQ_type::RQ_ENC_64, symbols, symbol_size)
{}
template <typename Rnd_It, typename Fwd_It>
Encoder<Rnd_It, Fwd_It>::~Encoder()
{ delete _encoder; }
{}
template <typename Rnd_It, typename Fwd_It>
Encoder<Rnd_It, Fwd_It>::operator bool() const
{
if (_encoder == nullptr)
return false;
return static_cast<bool> (*_encoder);
}
{ return static_cast<bool> (*_encoder); }
template <typename Rnd_It, typename Fwd_It>
uint16_t Encoder<Rnd_It, Fwd_It>::symbols() const
{
if (_encoder == nullptr)
return 0;
return _encoder->symbols();
}
{ return _encoder.symbols(); }
template <typename Rnd_It, typename Fwd_It>
size_t Encoder<Rnd_It, Fwd_It>::symbol_size() const
{
if (_encoder == nullptr)
return 0;
return _encoder->symbol_size();
}
{ return _encoder.symbol_size(); }
template <typename Rnd_It, typename Fwd_It>
uint32_t Encoder<Rnd_It, Fwd_It>::max_repair() const
{
if (_encoder == nullptr)
return 0;
return _encoder->max_repair();
}
{ return _encoder.max_repair(); }
template <typename Rnd_It, typename Fwd_It>
RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::begin_source()
{
if (_encoder == nullptr) {
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (
nullptr, 0);
}
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (
_encoder, 0);
&_encoder, 0);
}
template <typename Rnd_It, typename Fwd_It>
RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::end_source ()
{
if (_encoder == nullptr) {
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (
nullptr, 0);
}
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (_encoder,
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (&_encoder,
symbols());
}
......@@ -237,11 +206,7 @@ template <typename Rnd_It, typename Fwd_It>
RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::begin_repair()
{
if (_encoder == nullptr) {
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (
nullptr, 0);
}
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (_encoder,
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (&_encoder,
symbols());
}
......@@ -249,105 +214,59 @@ template <typename Rnd_It, typename Fwd_It>
RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::end_repair (const uint32_t repair)
{
if (_encoder == nullptr) {
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (
nullptr, 0);
}
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (_encoder,
return RaptorQ__v1::It::Encoder::Symbol_Iterator<Rnd_It, Fwd_It> (&_encoder,
symbols() + repair);
}
template <typename Rnd_It, typename Fwd_It>
bool Encoder<Rnd_It, Fwd_It>::has_data() const
{
if (_encoder == nullptr)
return false;
return _encoder->has_data();
}
{ return _encoder.has_data(); }
template <typename Rnd_It, typename Fwd_It>
size_t Encoder<Rnd_It, Fwd_It>::set_data (const Rnd_It &from, const Rnd_It &to)
{
if (_encoder == nullptr)
return 0;
const void *_from = reinterpret_cast<const void*> (from);
const void *_to = reinterpret_cast<const void*> (to);
return _encoder->set_data (_from, _to);
return _encoder.set_data (_from, _to);
}
template <typename Rnd_It, typename Fwd_It>
void Encoder<Rnd_It, Fwd_It>::clear_data()
{
if (_encoder == nullptr)
return;
_encoder->clear_data();
}
{ _encoder.clear_data(); }
template <typename Rnd_It, typename Fwd_It>
bool Encoder<Rnd_It, Fwd_It>::ready() const
{
if (_encoder == nullptr)
return false;
_encoder->ready();
}
{ _encoder.ready(); }
template <typename Rnd_It, typename Fwd_It>
void Encoder<Rnd_It, Fwd_It>::stop()
{
if (_encoder == nullptr)
return;
_encoder->stop();
}
{ _encoder.stop(); }
template <typename Rnd_It, typename Fwd_It>
bool Encoder<Rnd_It, Fwd_It>::precompute_sync()
{
if (_encoder == nullptr)
return false;
return _encoder->precompute_sync();
}
{ return _encoder.precompute_sync(); }
template <typename Rnd_It, typename Fwd_It>
bool Encoder<Rnd_It, Fwd_It>::compute_sync()
{
if (_encoder == nullptr)
return false;
return _encoder->compute_sync();
}
{ return _encoder.compute_sync(); }
#if __cplusplus >= 201103L
template <typename Rnd_It, typename Fwd_It>
std::shared_future<Error> Encoder<Rnd_It, Fwd_It>::precompute()
{
if (_encoder == nullptr) {
std::promise<Error> p;
p.set_value (Error::INITIALIZATION);
return p.get_future();
}
return _encoder->precompute();
}
{ return _encoder.precompute(); }
template <typename Rnd_It, typename Fwd_It>
std::shared_future<Error> Encoder<Rnd_It, Fwd_It>::compute()
{
if (_encoder == nullptr) {
std::promise<Error> p;
p.set_value (Error::INITIALIZATION);
return p.get_future();
}
return _encoder->compute();
}
{ return _encoder.compute(); }
#endif
template <typename Rnd_It, typename Fwd_It>
size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end,
const uint32_t id)
{
if (_encoder == nullptr)
return 0;
void **_from = reinterpret_cast<void**> (&output);
void *_to = reinterpret_cast<void*> (end);
auto ret = _encoder->encode (_from, _to, id);
auto ret = _encoder.encode (_from, _to, id);
output = *reinterpret_cast<Fwd_It*> (_from);
return ret;
}
......@@ -361,75 +280,52 @@ template <>
inline Decoder<uint8_t*, uint8_t*>::Decoder (const Block_Size symbols,
const size_t symbol_size,
const Dec_Report type)
{
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_8,
symbols, symbol_size, type);
}
: _decoder (RaptorQ_type::RQ_DEC_8, symbols, symbol_size, type)
{}
template <>
inline Decoder<uint16_t*, uint16_t*>::Decoder (const Block_Size symbols,
const size_t symbol_size,
const Dec_Report type)
{
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_16,
symbols, symbol_size, type);
}
:_decoder (RaptorQ_type::RQ_DEC_16, symbols, symbol_size, type)
{}
template <>
inline Decoder<uint32_t*, uint32_t*>::Decoder (const Block_Size symbols,
const size_t symbol_size,
const Dec_Report type)
{
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_32,
symbols, symbol_size, type);
}
:_decoder (RaptorQ_type::RQ_DEC_32, symbols, symbol_size, type)
{}
template <>
inline Decoder<uint64_t*, uint64_t*>::Decoder (const Block_Size symbols,
const size_t symbol_size,
const Dec_Report type)
{
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_64,
symbols, symbol_size, type);
}
:_decoder (RaptorQ_type::RQ_DEC_64, symbols, symbol_size, type)
{}
template <typename In_It, typename Fwd_It>
Decoder<In_It, Fwd_It>::~Decoder()
{ delete _decoder; }
{}
template <typename In_It, typename Fwd_It>
Decoder<In_It, Fwd_It>::operator bool() const
{
if (_decoder == nullptr)
return 0;
return static_cast<bool> (*_decoder);
}
{ return static_cast<bool> (*_decoder); }
template <typename In_It, typename Fwd_It>
uint16_t Decoder<In_It, Fwd_It>::symbols() const
{
if (_decoder == nullptr)
return 0;
return _decoder->symbols();
}
{ return _decoder.symbols(); }
template <typename In_It, typename Fwd_It>
size_t Decoder<In_It, Fwd_It>::symbol_size() const
{
if (_decoder == nullptr)
return 0;
return _decoder->symbol_size();
}
{ return _decoder.symbol_size(); }
template <typename In_It, typename Fwd_It>
RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It>
Decoder<In_It, Fwd_It>::begin()
{
if (_decoder == nullptr)
return RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It> (
nullptr, 0);
return RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It> (_decoder,
return RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It> (&_decoder,
0);
}
......@@ -437,30 +333,21 @@ template <typename In_It, typename Fwd_It>
RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It>
Decoder<In_It, Fwd_It>::end()
{
if (_decoder == nullptr)
return RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It> (
nullptr, 0);
return RaptorQ__v1::It::Decoder::Symbol_Iterator<In_It, Fwd_It> (
_decoder, symbols());
&_decoder, symbols());
}
template <typename In_It, typename Fwd_It>
uint16_t Decoder<In_It, Fwd_It>::needed_symbols() const
{
if (_decoder == nullptr)
return 0;
return _decoder->needed_symbols();
}
{ return _decoder.needed_symbols(); }
template <typename In_It, typename Fwd_It>
Error Decoder<In_It, Fwd_It>::add_symbol (In_It &from, const In_It to,
const uint32_t esi)
{
if (_decoder == nullptr)
return Error::INITIALIZATION;
void **_from = reinterpret_cast<void**> (&from);
void *_to = reinterpret_cast<void*> (to);
auto ret = _decoder->add_symbol (_from, _to, esi);
auto ret = _decoder.add_symbol (_from, _to, esi);
from = *reinterpret_cast<In_It*> (_from);
return ret;
}
......@@ -468,97 +355,53 @@ Error Decoder<In_It, Fwd_It>::add_symbol (In_It &from, const In_It to,
template <typename In_It, typename Fwd_It>
std::vector<bool> Decoder<In_It, Fwd_It>::end_of_input (
const Fill_With_Zeros fill)
{
if (_decoder != nullptr)
return _decoder->end_of_input (fill);
return std::vector<bool>();
}
{ return _decoder.end_of_input (fill); }
template <typename In_It, typename Fwd_It>
void Decoder<In_It, Fwd_It>::set_max_concurrency (const uint16_t max_threads)
{
if (_decoder != nullptr)
return _decoder->set_max_concurrency (max_threads);
}
{ return _decoder.set_max_concurrency (max_threads); }
template <typename In_It, typename Fwd_It>
Decoder_Result Decoder<In_It, Fwd_It>::decode_once()
{
if (_decoder == nullptr)
return Decoder_Result::NEED_DATA;
return _decoder->decode_once();
}
{ return _decoder.decode_once(); }
template <typename In_It, typename Fwd_It>
Decoder_wait_res Decoder<In_It, Fwd_It>::poll()
{
if (_decoder == nullptr)
return {Error::INITIALIZATION, 0};
return _decoder->poll();
}
{ return _decoder.poll(); }
template <typename In_It, typename Fwd_It>
Decoder_wait_res Decoder<In_It, Fwd_It>::wait_sync()
{
if (_decoder == nullptr) {
return {Error::INITIALIZATION, 0};
}
return _decoder->wait_sync();
}
{ return _decoder.wait_sync(); }
#if __cplusplus >= 201103L || _MSC_VER > 1900
template <typename In_It, typename Fwd_It>
std::future<struct Decoder_wait_res> Decoder<In_It, Fwd_It>::wait()
{
if (_decoder == nullptr) {
std::promise<struct Decoder_wait_res> p;
p.set_value ({Error::INITIALIZATION, 0});
return p.get_future();
}
return _decoder->wait();
}
{ return _decoder.wait(); }
#endif
template <typename In_It, typename Fwd_It>
bool Decoder<In_It, Fwd_It>::can_decode() const
{
if (_decoder == nullptr)
return false;
return _decoder->can_decode();
}
{ return _decoder.can_decode(); }
template <typename In_It, typename Fwd_It>
bool Decoder<In_It, Fwd_It>::ready() const
{
if (_decoder == nullptr)
return false;
return _decoder->ready();
}
{ return _decoder.ready(); }
template <typename In_It, typename Fwd_It>
void Decoder<In_It, Fwd_It>::stop()
{
if (_decoder != nullptr)
_decoder->stop();
}
{ _decoder.stop(); }
template <typename In_It, typename Fwd_It>
void Decoder<In_It, Fwd_It>::clear_data()
{
if (_decoder == nullptr)
return;
_decoder->clear_data();
}
{ _decoder.clear_data(); }
template <typename In_It, typename Fwd_It>
Error Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start, const Fwd_It end,
const uint16_t esi)
{
if (_decoder == nullptr || end < start)
return Error::INITIALIZATION;
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
auto ret = _decoder->decode_symbol (_from, _to, esi);
auto ret = _decoder.decode_symbol (_from, _to, esi);
start = *reinterpret_cast<Fwd_It*> (_from);
return ret;
}
......@@ -569,11 +412,9 @@ Decoder_written Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start,
const size_t from_byte,
const size_t skip)
{
if (_decoder == nullptr)
return {0, skip};
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
auto ret = _decoder->decode_bytes (_from, _to, from_byte, skip);
auto ret = _decoder.decode_bytes (_from, _to, from_byte, skip);
start = *reinterpret_cast<Fwd_It*> (_from);
return ret;
}
......
......@@ -88,8 +88,9 @@ private:
class RAPTORQ_API Decoder_void
{
public:
using Report = Dec_Report;
Decoder_void (const RaptorQ_type type, const Block_Size symbols,
const size_t symbol_size, const Dec_Report computation);
const size_t symbol_size, const Report computation);
~Decoder_void();
Decoder_void() = delete;
Decoder_void (const Decoder_void&) = delete;
......
......@@ -283,9 +283,10 @@ static struct RaptorQ_ptr* v1_Decoder (RaptorQ_type type,
const size_t symbol_size,
const RQ_Dec_Report report)
{
if (report != RQ_COMPUTE_PARTIAL_FROM_BEGINNING &&
report != RQ_COMPUTE_PARTIAL_ANY &&
report != RQ_COMPUTE_COMPLETE) {
const auto _report = static_cast<RFC6330_Compute> (report);
if (_report != RQ_COMPUTE_PARTIAL_FROM_BEGINNING &&
_report != RQ_COMPUTE_PARTIAL_ANY &&
_report != RQ_COMPUTE_COMPLETE) {
return nullptr;
}
......
......@@ -19,7 +19,12 @@
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../src/RaptorQ/RaptorQ_v1_hdr.hpp"
// we can switch easily between header-only and linked version of the library
#if defined (TEST_HDR_ONLY)
#include "../src/RaptorQ/RaptorQ_v1_hdr.hpp"
#else
#include "../src/RaptorQ/RaptorQ_v1.hpp"
#endif
#include <algorithm>
#include <fstream>
#include <iostream>
......@@ -131,10 +136,8 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
}
}
RaptorQ::Encoder<typename std::vector<in_enc_align>::iterator,
typename std::vector<out_enc_align>::iterator> enc (
block, symbol_size);
if (enc.set_data (myvec.begin(), myvec.end()) != mysize) {
RaptorQ::Encoder<in_enc_align*, out_enc_align*> enc (block, symbol_size);
if (enc.set_data (myvec.begin().base(), myvec.end().base()) != mysize) {
std::cout << "Could not give data to the encoder :(\n";
return false;
}
......@@ -172,9 +175,9 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
std::vector<out_enc_align> source_sym;
source_sym.reserve (out_aligned_symbol_size);
source_sym.insert (source_sym.begin(), out_aligned_symbol_size, 0);
auto it = source_sym.begin();
out_enc_align* from = source_sym.begin().base();
// save the symbol
auto written = (*sym_it) (it, source_sym.end());
auto written = (*sym_it) (from, source_sym.end().base());
if (written != out_aligned_symbol_size) {
std::cout << written << "-vs-" << out_aligned_symbol_size <<
" Could not get the whole source symbol!\n";
......@@ -204,9 +207,9 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
std::vector<out_enc_align> repair_sym;
repair_sym.reserve (out_aligned_symbol_size);
repair_sym.insert (repair_sym.begin(), out_aligned_symbol_size, 0);
auto it = repair_sym.begin();
out_enc_align* from = repair_sym.begin().base();
// save the repair symbol
auto written = (*sym_it) (it, repair_sym.end());
auto written = (*sym_it) (from, repair_sym.end().base());
if (written != out_aligned_symbol_size) {
std::cout << written << "-vs-" << out_aligned_symbol_size <<
" Could not get the whole repair symbol!\n";
......@@ -225,9 +228,7 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
// encoding done. now "encoded" is the vector with the trnasmitted data.
// let's decode it
using Decoder_type = RaptorQ::Decoder<
typename std::vector<in_dec_align>::iterator,
typename std::vector<out_dec_align>::iterator>;
using Decoder_type = RaptorQ::Decoder<in_dec_align*, out_dec_align*>;
Decoder_type dec (block, symbol_size, Decoder_type::Report::COMPLETE);
......@@ -244,8 +245,8 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
received.push_back (static_cast<out_dec_align> (0));
for (size_t i = 0; i < encoded.size(); ++i) {
auto it = encoded[i].second.begin();
auto err = dec.add_symbol (it, encoded[i].second.end(),
out_enc_align *from = encoded[i].second.begin().base();
auto err = dec.add_symbol (from, encoded[i].second.end().base(),
encoded[i].first);
if (err != RaptorQ::Error::NONE && err != RaptorQ::Error::NOT_NEEDED) {
std::cout << "error adding?\n";
......@@ -263,12 +264,12 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
return false;
}
auto re_it = received.begin();
out_dec_align *from = received.begin().base();
// decode all blocks
// you can actually call ".decode(...)" as many times
// as you want. It will only start decoding once
// it has enough data.
auto decoded = dec.decode_bytes (re_it, received.end(), 0, 0);
auto decoded = dec.decode_bytes (from, received.end().base(), 0, 0);
// NOTE: decoded.first might be > mysize.
// This can happen since "misize" might not fit the whole
......@@ -325,7 +326,7 @@ int main (void)
rand.close ();
rnd.seed (seed);
RaptorQ__v1::local_cache_size (5000000);
RaptorQ::local_cache_size (5000000);
// encode and decoder
for (size_t i = 0; i < 1000; ++i) {
......@@ -334,6 +335,7 @@ int main (void)
rnd_size (rnd, sizeof(uint8_t)), rnd, 20.0, 4);
if (!ret)
return -1;
#if defined (TEST_HDR_ONLY)
std::cout << "08-08-16\n";
ret = decode<uint8_t, uint8_t, uint16_t> (
rnd_size (rnd, sizeof(uint8_t)), rnd, 20.0, 4);
......@@ -394,11 +396,13 @@ int main (void)
rnd_size (rnd, sizeof(uint16_t)), rnd, 20.0, 4);
if (!ret)
return -1;
#endif
std::cout << "16-16-16\n";
ret = decode<uint16_t, uint16_t, uint16_t> (
rnd_size (rnd, sizeof(uint16_t)), rnd, 20.0, 4);
if (!ret)
return -1;
#if defined (TEST_HDR_ONLY)
std::cout << "16-16-32\n";
ret = decode<uint16_t, uint16_t, uint32_t> (
rnd_size (rnd, sizeof(uint16_t)), rnd, 20.0, 4);
......@@ -459,6 +463,7 @@ int main (void)
rnd_size (rnd, sizeof(uint32_t)), rnd, 20.0, 4);
if (!ret)
return -1;
#endif
std::cout << "32-32-32\n";
ret = decode<uint32_t, uint32_t, uint32_t> (
rnd_size (rnd, sizeof(uint32_t)), rnd, 20.0, 4);
......