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