Skip to content
Commits on Source (3)
...@@ -521,10 +521,19 @@ endif() ...@@ -521,10 +521,19 @@ endif()
add_executable(test_cpp_rfc EXCLUDE_FROM_ALL test/test_cpp_rfc.cpp ${HEADERS_ONLY} ${HEADERS}) add_executable(test_cpp_rfc EXCLUDE_FROM_ALL test/test_cpp_rfc.cpp ${HEADERS_ONLY} ${HEADERS})
target_compile_options( target_compile_options(
test_cpp_rfc PRIVATE test_cpp_rfc PRIVATE
${CXX_COMPILER_FLAGS} ${CXX_COMPILER_FLAGS} "-DTEST_HDR_ONLY"
) )
target_link_libraries(test_cpp_rfc ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP}) target_link_libraries(test_cpp_rfc ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
# CPP interface - RFC interface (linked version)
add_executable(test_cpp_rfc_linked EXCLUDE_FROM_ALL test/test_cpp_rfc.cpp ${HEADERS_ONLY} ${HEADERS})
target_compile_options(
test_cpp_rfc_linked PRIVATE
${CXX_COMPILER_FLAGS}
)
add_dependencies(test_cpp_rfc_linked RaptorQ)
target_link_libraries(test_cpp_rfc_linked RaptorQ ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
# CPP interface - RAW interface (header only) # CPP interface - RAW interface (header only)
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(
...@@ -569,7 +578,7 @@ target_compile_options( ...@@ -569,7 +578,7 @@ target_compile_options(
) )
target_link_libraries(example_cpp_raw ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP}) target_link_libraries(example_cpp_raw ${RQ_UBSAN} ${STDLIB} ${CMAKE_THREAD_LIBS_INIT} ${RQ_LZ4_DEP})
add_custom_target(examples DEPENDS test_c test_cpp_rfc test_cpp_raw libRaptorQ-test example_cpp_raw) add_custom_target(examples DEPENDS test_c test_cpp_rfc test_cpp_rfc_linked test_cpp_raw test_cpp_raw_linked libRaptorQ-test example_cpp_raw)
......
/* /*
* Copyright (c) 2015-2016, Luca Fulchir<luca@fulchir.it>, All rights reserved. * Copyright (c) 2015-2018, Luca Fulchir<luca@fulchir.it>, All rights reserved.
* *
* This file is part of "libRaptorQ". * This file is part of "libRaptorQ".
* *
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#pragma once #pragma once
#include "RaptorQ/v1/common.hpp" #include "RaptorQ/v1/common.hpp"
#include "RaptorQ/v1/caches.hpp"
#include "RaptorQ/v1/wrapper/CPP_RFC_API.hpp" #include "RaptorQ/v1/wrapper/CPP_RFC_API.hpp"
#include "RaptorQ/v1/wrapper/CPP_RFC_API_void.hpp" #include "RaptorQ/v1/wrapper/CPP_RFC_API_void.hpp"
#include "RaptorQ/v1/Thread_Pool.hpp" #include "RaptorQ/v1/Thread_Pool.hpp"
...@@ -62,6 +62,8 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end, ...@@ -62,6 +62,8 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end,
const uint8_t skip, const uint8_t skip,
const uint16_t from_esi) const uint16_t from_esi)
{ {
if (start == end)
return 0;
// return number of BYTES written // return number of BYTES written
size_t written = 0; size_t written = 0;
int32_t byte = 0; int32_t byte = 0;
...@@ -78,21 +80,21 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end, ...@@ -78,21 +80,21 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end,
using T = typename std::iterator_traits<Fwd_It>::value_type; using T = typename std::iterator_traits<Fwd_It>::value_type;
T element = static_cast<T> (0); T element = static_cast<T> (0);
if (skip != 0) { if (skip != 0) {
assert (skip < sizeof(T) && "De_Interleaver: skip too big");
uint8_t *p = reinterpret_cast<uint8_t *> (&*start); uint8_t *p = reinterpret_cast<uint8_t *> (&*start);
for (size_t keep = 0; keep < skip; ++keep) { for (size_t keep = 0; keep < skip; ++keep) {
element += static_cast<T> (*(p++)) << keep * 8; element += static_cast<T> (*(p++)) << keep * 8;
} }
} }
while (start != end && sub_blk < (_sub_blocks.num(0) + _sub_blocks.num(1))){ while ((start != end && sub_blk < (_sub_blocks.num(0) + _sub_blocks.num(1)))
if ((written + offset_al) >= max_bytes) && (written + offset_al) < (max_bytes + skip)) {
break;
element += static_cast<T> (static_cast<uint8_t>((*_symbols)(esi, byte))) element += static_cast<T> (static_cast<uint8_t>((*_symbols)(esi, byte)))
<< offset_al * 8; << offset_al * 8;
++offset_al; ++offset_al;
if (offset_al == sizeof(T)) { if (offset_al == sizeof(T)) {
*start = element; *start = element;
++start; ++start;
written += offset_al; written += sizeof(T);
element = static_cast<T> (0); element = static_cast<T> (0);
offset_al = 0; offset_al = 0;
} }
...@@ -115,6 +117,7 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end, ...@@ -115,6 +117,7 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end,
} }
} }
} }
assert(!(start == end && offset_al != 0) && "De_Interleaver: can't write");
if (start != end && offset_al != 0) { if (start != end && offset_al != 0) {
// we have more stuff in "element", but not enough to fill // we have more stuff in "element", but not enough to fill
// the iterator. Do not overwrite additional data of the iterator. // the iterator. Do not overwrite additional data of the iterator.
...@@ -125,8 +128,8 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end, ...@@ -125,8 +128,8 @@ size_t De_Interleaver<Fwd_It>::operator() (Fwd_It &start, const Fwd_It end,
++start; ++start;
written += offset_al; written += offset_al;
} }
if (written > 0) written -= skip;
written -= skip; assert (written <= max_bytes && "De_Interleaver: too much writing");
return written; return written;
} }
......
...@@ -141,8 +141,8 @@ public: ...@@ -141,8 +141,8 @@ public:
size_t encode (Fwd_It &output, const Fwd_It end, const uint32_t esi, size_t encode (Fwd_It &output, const Fwd_It end, const uint32_t esi,
const uint8_t sbn); const uint8_t sbn);
// id: 8-bit sbn + 24 bit esi // id: 8-bit sbn + 24 bit esi
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);
size_t encode_packet (Fwd_It &output, const Fwd_It end, const uint32_t &id); size_t encode_packet (Fwd_It &output, const Fwd_It end, const uint32_t id);
void free (const uint8_t sbn); void free (const uint8_t sbn);
uint8_t blocks() const; uint8_t blocks() const;
...@@ -685,7 +685,7 @@ std::pair<Error, uint8_t> Encoder<Rnd_It, Fwd_It>::get_report ( ...@@ -685,7 +685,7 @@ std::pair<Error, uint8_t> Encoder<Rnd_It, Fwd_It>::get_report (
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)
{ {
const uint32_t host_id = RaptorQ__v1::Impl::Endian::b_to_h<uint32_t> (id); const uint32_t host_id = RaptorQ__v1::Impl::Endian::b_to_h<uint32_t> (id);
constexpr uint32_t mask = ~(static_cast<uint32_t>(0xFF) << 24); constexpr uint32_t mask = ~(static_cast<uint32_t>(0xFF) << 24);
...@@ -740,7 +740,7 @@ size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end, ...@@ -740,7 +740,7 @@ size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end,
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
size_t Encoder<Rnd_It, Fwd_It>::encode_packet (Fwd_It &output, const Fwd_It end, size_t Encoder<Rnd_It, Fwd_It>::encode_packet (Fwd_It &output, const Fwd_It end,
const uint32_t &id) const uint32_t id)
{ {
// RFC packet, section 4.4.2 page 11 // RFC packet, section 4.4.2 page 11
...@@ -1548,8 +1548,6 @@ uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, const Fwd_It end, ...@@ -1548,8 +1548,6 @@ uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, const Fwd_It end,
sizeof(typename std::iterator_traits<Fwd_It>::value_type); sizeof(typename std::iterator_traits<Fwd_It>::value_type);
if (bytes_written == 0) if (bytes_written == 0)
return written; return written;
//new_skip = block_size (sbn) %
// sizeof(typename std::iterator_traits<Fwd_It>::value_type);
// if we ended decoding in the middle of a Fwd_It, do not advance // if we ended decoding in the middle of a Fwd_It, do not advance
// start too much, or we will end up having additional zeros. // start too much, or we will end up having additional zeros.
if (new_skip == 0) { if (new_skip == 0) {
...@@ -1557,14 +1555,8 @@ uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, const Fwd_It end, ...@@ -1557,14 +1555,8 @@ uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, const Fwd_It end,
} else { } else {
uint64_t it_written = bytes_and_skip / uint64_t it_written = bytes_and_skip /
sizeof(typename std::iterator_traits<Fwd_It>::value_type); sizeof(typename std::iterator_traits<Fwd_It>::value_type);
// RaptorQ handles at most 881GB per rfc, so
// casting uint64 to int64 is safe
// we can not do "--start" since it's a forward iterator // we can not do "--start" since it's a forward iterator
#pragma clang diagnostic push start += it_written;
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
#pragma clang diagnostic ignored "-Wsign-conversion"
start += std::max (static_cast<uint64_t>(0), it_written - 1);
#pragma clang diagnostic pop
} }
} }
return written; return written;
...@@ -1697,21 +1689,25 @@ uint32_t Decoder<In_It, Fwd_It>::block_size (const uint8_t sbn) const ...@@ -1697,21 +1689,25 @@ uint32_t Decoder<In_It, Fwd_It>::block_size (const uint8_t sbn) const
if (!operator bool()) if (!operator bool())
return 0; return 0;
size_t ret = 0; uint32_t ret = 0;
if (sbn < part.num (0)) { if (sbn < part.num (0)) {
ret = part.size (0) * _symbol_size; ret = part.size (0) * _symbol_size;
} else if (sbn - part.num (0) < part.num (1)) { } else if ((sbn - part.num (0)) < part.num (1)) {
ret = part.size (1) * _symbol_size; ret = part.size (1) * _symbol_size;
} }
if (ret != 0 && sbn == (part.num (0) + part.num (1) - 1)) { if (ret != 0 && (sbn + 1) == (part.num (0) + part.num (1))) {
// the size of the data (_size) is different from the sum of the size of // the size of the data (_size) is different from the sum of the size of
// all blocks. Get the real size, so we do not write more. // all blocks. Get the real size, so we do not write more.
// we obviously need to consider this only for the last block. // we obviously need to consider this only for the last block.
size_t left = ret; size_t size_without_last;
left -= part.num (0) * part.size (0) * _symbol_size; if (sbn < part.num (0)) {
if (part.num (1) > 1) size_without_last = (part.num (0) - 1) * part.size (0) *
left -= (part.num (1) - 1) * part.size (1) * _symbol_size; _symbol_size;
ret = static_cast<uint32_t> (left); } else {
size_without_last = part.num (0) * part.size (0) * _symbol_size +
(part.num (1) - 1) * part.size (1) * _symbol_size;
}
ret = static_cast<uint32_t> (_size - size_without_last);
} }
return ret; return ret;
} }
......
...@@ -73,8 +73,18 @@ public: ...@@ -73,8 +73,18 @@ public:
{ {
if (_enc == nullptr) if (_enc == nullptr)
return 0; return 0;
#ifdef RQ_HEADER_ONLY
return _enc->encode (start, end, return _enc->encode (start, end,
RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id)); RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id));
#else
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
uint64_t res = _enc->encode (_from, _to,
RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id));
Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return res;
#endif
} }
uint32_t id() const uint32_t id() const
{ return RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id); } { return RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id); }
...@@ -264,10 +274,18 @@ public: ...@@ -264,10 +274,18 @@ public:
uint64_t operator() (In_It &start, const In_It end) uint64_t operator() (In_It &start, const In_It end)
{ {
if (_dec == nullptr || esi (_id) > _dec->symbols (block (_id))) if (_dec == nullptr || esi() >= _dec->symbols (block()))
return 0; return 0;
return _dec->decode_symbol (start, end, #ifdef RQ_HEADER_ONLY
static_cast<uint16_t> (esi (_id)), block (_id)); return _dec->decode_symbol (start, end, esi(), block());
#else
void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end);
uint64_t res = _dec->decode_symbol (_from, _to, esi(), block());
Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return res;
#endif
} }
uint32_t id() const uint32_t id() const
{ return RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id); } { return RaptorQ__v1::Impl::Endian::h_to_b<uint32_t> (_id); }
......
...@@ -83,8 +83,10 @@ public: ...@@ -83,8 +83,10 @@ public:
#else #else
void **_from = reinterpret_cast<void**> (&start); void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end); void *_to = reinterpret_cast<void*> (end);
return _enc->encode (_from, _to, _esi); uint64_t res = _enc->encode (_from, _to, _esi);
start = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return res;
#endif #endif
} }
uint32_t id() const uint32_t id() const
...@@ -158,8 +160,10 @@ public: ...@@ -158,8 +160,10 @@ public:
#else #else
void **_from = reinterpret_cast<void**> (&start); void **_from = reinterpret_cast<void**> (&start);
void *_to = reinterpret_cast<void*> (end); void *_to = reinterpret_cast<void*> (end);
return _dec->decode_symbol (_from, _to, _esi); Error err = _dec->decode_symbol (_from, _to, _esi);
start = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return err;
#endif #endif
} }
uint16_t id() const uint16_t id() const
......
...@@ -172,7 +172,7 @@ Encoder<Rnd_It, Fwd_It>::~Encoder() ...@@ -172,7 +172,7 @@ Encoder<Rnd_It, Fwd_It>::~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); } { 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
...@@ -267,7 +267,8 @@ size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end, ...@@ -267,7 +267,8 @@ size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end,
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); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
output = *tmp;
return ret; return ret;
} }
...@@ -311,7 +312,7 @@ Decoder<In_It, Fwd_It>::~Decoder() ...@@ -311,7 +312,7 @@ Decoder<In_It, Fwd_It>::~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); } { 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
...@@ -348,7 +349,8 @@ Error Decoder<In_It, Fwd_It>::add_symbol (In_It &from, const In_It to, ...@@ -348,7 +349,8 @@ Error Decoder<In_It, Fwd_It>::add_symbol (In_It &from, const In_It to,
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); In_It *tmp = reinterpret_cast<In_It*> (_from);
from = *tmp;
return ret; return ret;
} }
...@@ -402,7 +404,8 @@ Error Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start, const Fwd_It end, ...@@ -402,7 +404,8 @@ Error Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start, const Fwd_It end,
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); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return ret; return ret;
} }
...@@ -415,7 +418,8 @@ Decoder_written Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, ...@@ -415,7 +418,8 @@ Decoder_written Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start,
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); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return ret; return ret;
} }
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
size_t precompute_max_memory (); size_t precompute_max_memory ();
size_t encode (Fwd_It &output, const Fwd_It end, const uint32_t esi, size_t encode (Fwd_It &output, const Fwd_It end, const uint32_t esi,
const uint8_t sbn); const uint8_t sbn);
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);
void free (const uint8_t sbn); void free (const uint8_t sbn);
uint8_t blocks() const; uint8_t blocks() const;
uint32_t block_size (const uint8_t sbn) const; uint32_t block_size (const uint8_t sbn) const;
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
Block_Size extended_symbols (const uint8_t sbn) const; Block_Size extended_symbols (const uint8_t sbn) const;
uint32_t max_repair (const uint8_t sbn) const; uint32_t max_repair (const uint8_t sbn) const;
private: private:
Impl::Encoder_void *_encoder; Impl::Encoder_void _encoder;
}; };
//////////////////// ////////////////////
...@@ -150,7 +150,7 @@ public: ...@@ -150,7 +150,7 @@ public:
uint16_t symbols (const uint8_t sbn) const; uint16_t symbols (const uint8_t sbn) const;
Block_Size extended_symbols (const uint8_t sbn) const; Block_Size extended_symbols (const uint8_t sbn) const;
private: private:
Impl::Decoder_void *_decoder; Impl::Decoder_void _decoder;
}; };
...@@ -165,11 +165,9 @@ inline Encoder<uint8_t*, uint8_t*>::Encoder (uint8_t* const data_from, ...@@ -165,11 +165,9 @@ inline Encoder<uint8_t*, uint8_t*>::Encoder (uint8_t* const data_from,
const uint16_t min_subsymbol_size, const uint16_t min_subsymbol_size,
const uint16_t symbol_size, const uint16_t symbol_size,
const size_t max_sub_block) const size_t max_sub_block)
{ : _encoder (RaptorQ_type::RQ_ENC_8, data_from, data_to, min_subsymbol_size,
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_8, data_from, symbol_size, max_sub_block)
data_to, min_subsymbol_size, {}
symbol_size, max_sub_block);
}
template <> template <>
inline Encoder<uint16_t*, uint16_t*>::Encoder (uint16_t* const data_from, inline Encoder<uint16_t*, uint16_t*>::Encoder (uint16_t* const data_from,
...@@ -177,11 +175,9 @@ inline Encoder<uint16_t*, uint16_t*>::Encoder (uint16_t* const data_from, ...@@ -177,11 +175,9 @@ inline Encoder<uint16_t*, uint16_t*>::Encoder (uint16_t* const data_from,
const uint16_t min_subsymbol_size, const uint16_t min_subsymbol_size,
const uint16_t symbol_size, const uint16_t symbol_size,
const size_t max_sub_block) const size_t max_sub_block)
{ : _encoder (RaptorQ_type::RQ_ENC_16, data_from, data_to, min_subsymbol_size,
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_16, data_from, symbol_size, max_sub_block)
data_to, min_subsymbol_size, {}
symbol_size, max_sub_block);
}
template <> template <>
inline Encoder<uint32_t*, uint32_t*>::Encoder (uint32_t* const data_from, inline Encoder<uint32_t*, uint32_t*>::Encoder (uint32_t* const data_from,
...@@ -189,11 +185,9 @@ inline Encoder<uint32_t*, uint32_t*>::Encoder (uint32_t* const data_from, ...@@ -189,11 +185,9 @@ inline Encoder<uint32_t*, uint32_t*>::Encoder (uint32_t* const data_from,
const uint16_t min_subsymbol_size, const uint16_t min_subsymbol_size,
const uint16_t symbol_size, const uint16_t symbol_size,
const size_t max_sub_block) const size_t max_sub_block)
{ : _encoder (RaptorQ_type::RQ_ENC_32, data_from, data_to, min_subsymbol_size,
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_32, data_from, symbol_size, max_sub_block)
data_to, min_subsymbol_size, {}
symbol_size, max_sub_block);
}
template <> template <>
inline Encoder<uint64_t*, uint64_t*>::Encoder (uint64_t* const data_from, inline Encoder<uint64_t*, uint64_t*>::Encoder (uint64_t* const data_from,
...@@ -201,159 +195,101 @@ inline Encoder<uint64_t*, uint64_t*>::Encoder (uint64_t* const data_from, ...@@ -201,159 +195,101 @@ inline Encoder<uint64_t*, uint64_t*>::Encoder (uint64_t* const data_from,
const uint16_t min_subsymbol_size, const uint16_t min_subsymbol_size,
const uint16_t symbol_size, const uint16_t symbol_size,
const size_t max_sub_block) const size_t max_sub_block)
{ : _encoder (RaptorQ_type::RQ_ENC_64, data_from, data_to, min_subsymbol_size,
_encoder = new Impl::Encoder_void (RaptorQ_type::RQ_ENC_64, data_from, symbol_size, max_sub_block)
data_to, min_subsymbol_size, {}
symbol_size, max_sub_block);
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline Encoder<Rnd_It, Fwd_It>::~Encoder() inline Encoder<Rnd_It, Fwd_It>::~Encoder()
{ delete _encoder; } {}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline It::Encoder::Block_Iterator<Rnd_It, Fwd_It> inline It::Encoder::Block_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::begin() Encoder<Rnd_It, Fwd_It>::begin()
{ return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (_encoder, 0); } { return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (&_encoder, 0); }
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline const It::Encoder::Block_Iterator<Rnd_It, Fwd_It> inline const It::Encoder::Block_Iterator<Rnd_It, Fwd_It>
Encoder<Rnd_It, Fwd_It>::end() Encoder<Rnd_It, Fwd_It>::end()
{ { return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (&_encoder, blocks());}
if (_encoder == nullptr)
return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (nullptr, 0);
return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (_encoder, blocks());
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline Encoder<Rnd_It, Fwd_It>::operator bool() const inline 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>
inline RFC6330_OTI_Common_Data Encoder<Rnd_It, Fwd_It>::OTI_Common() const inline RFC6330_OTI_Common_Data Encoder<Rnd_It, Fwd_It>::OTI_Common() const
{ { return _encoder.OTI_Common(); }
if (_encoder == nullptr)
return 0;
return _encoder->OTI_Common();
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline RFC6330_OTI_Scheme_Specific_Data inline RFC6330_OTI_Scheme_Specific_Data
Encoder<Rnd_It, Fwd_It>::OTI_Scheme_Specific() const Encoder<Rnd_It, Fwd_It>::OTI_Scheme_Specific() const
{ { return _encoder.OTI_Scheme_Specific(); }
if (_encoder == nullptr)
return 0;
return _encoder->OTI_Common();
}
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline std::future<std::pair<Error, uint8_t>> Encoder<Rnd_It, Fwd_It>::compute ( inline std::future<std::pair<Error, uint8_t>> Encoder<Rnd_It, Fwd_It>::compute (
const Compute flags) const Compute flags)
{ { return _encoder.compute (flags); }
if (_encoder != nullptr)
return _encoder->compute (flags);
std::promise<std::pair<Error, uint8_t>> ret;
ret.set_value ({Error::INITIALIZATION, 0});
return ret.get_future();
}
#endif #endif
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline size_t Encoder<Rnd_It, Fwd_It>::precompute_max_memory () inline size_t Encoder<Rnd_It, Fwd_It>::precompute_max_memory ()
{ { return _encoder.precompute_max_memory(); }
if (_encoder == nullptr)
return 0;
return _encoder->precompute_max_memory();
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end, inline size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end,
const uint32_t esi, const uint32_t esi,
const uint8_t sbn) const uint8_t sbn)
{ {
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, esi, sbn); auto ret = _encoder.encode (_from, _to, esi, sbn);
output = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
output = *tmp;
return ret; return ret;
} }
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline size_t Encoder<Rnd_It, Fwd_It>::encode (Fwd_It &output, const Fwd_It end, inline 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); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
output = *tmp;
return ret; return ret;
} }
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline void Encoder<Rnd_It, Fwd_It>::free (const uint8_t sbn) inline void Encoder<Rnd_It, Fwd_It>::free (const uint8_t sbn)
{ { return _encoder.free (sbn); }
if (_encoder == nullptr)
return;
return _encoder->free (sbn);
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline uint8_t Encoder<Rnd_It, Fwd_It>::blocks() const inline uint8_t Encoder<Rnd_It, Fwd_It>::blocks() const
{ { return _encoder.blocks(); }
if (_encoder == nullptr)
return 0;
return _encoder->blocks();
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline uint32_t Encoder<Rnd_It, Fwd_It>::block_size (const uint8_t sbn) const inline uint32_t Encoder<Rnd_It, Fwd_It>::block_size (const uint8_t sbn) const
{ { return _encoder.block_size (sbn); }
if (_encoder == nullptr)
return 0;
return _encoder->block_size (sbn);
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline uint16_t Encoder<Rnd_It, Fwd_It>::symbol_size() const inline uint16_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>
inline uint16_t Encoder<Rnd_It, Fwd_It>::symbols (const uint8_t sbn) const inline uint16_t Encoder<Rnd_It, Fwd_It>::symbols (const uint8_t sbn) const
{ { return _encoder.symbols (sbn); }
if (_encoder == nullptr)
return 0;
return _encoder->symbols (sbn);
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline Block_Size Encoder<Rnd_It, Fwd_It>::extended_symbols (const uint8_t sbn) inline Block_Size Encoder<Rnd_It, Fwd_It>::extended_symbols (const uint8_t sbn)
const const
{ { return _encoder.extended_symbols (sbn); }
if (_encoder == nullptr)
return static_cast<Block_Size>(0);
return _encoder->extended_symbols (sbn);
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline uint32_t Encoder<Rnd_It, Fwd_It>::max_repair (const uint8_t sbn) const inline uint32_t Encoder<Rnd_It, Fwd_It>::max_repair (const uint8_t sbn) const
{ { return _encoder.max_repair (sbn); }
if (_encoder == nullptr)
return 0;
return _encoder->max_repair (sbn);
}
...@@ -365,33 +301,29 @@ template <> ...@@ -365,33 +301,29 @@ template <>
inline Decoder<uint8_t*, uint8_t*>::Decoder ( inline Decoder<uint8_t*, uint8_t*>::Decoder (
const RFC6330_OTI_Common_Data common, const RFC6330_OTI_Common_Data common,
const RFC6330_OTI_Scheme_Specific_Data scheme) const RFC6330_OTI_Scheme_Specific_Data scheme)
{ : _decoder (RaptorQ_type::RQ_DEC_8, common, scheme)
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_8, common, scheme); {}
}
template <> template <>
inline Decoder<uint16_t*, uint16_t*>::Decoder ( inline Decoder<uint16_t*, uint16_t*>::Decoder (
const RFC6330_OTI_Common_Data common, const RFC6330_OTI_Common_Data common,
const RFC6330_OTI_Scheme_Specific_Data scheme) const RFC6330_OTI_Scheme_Specific_Data scheme)
{ : _decoder (RaptorQ_type::RQ_DEC_16, common, scheme)
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_16, common, scheme); {}
}
template <> template <>
inline Decoder<uint32_t*, uint32_t*>::Decoder ( inline Decoder<uint32_t*, uint32_t*>::Decoder (
const RFC6330_OTI_Common_Data common, const RFC6330_OTI_Common_Data common,
const RFC6330_OTI_Scheme_Specific_Data scheme) const RFC6330_OTI_Scheme_Specific_Data scheme)
{ : _decoder (RaptorQ_type::RQ_DEC_32, common, scheme)
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_32, common, scheme); {}
}
template <> template <>
inline Decoder<uint64_t*, uint64_t*>::Decoder ( inline Decoder<uint64_t*, uint64_t*>::Decoder (
const RFC6330_OTI_Common_Data common, const RFC6330_OTI_Common_Data common,
const RFC6330_OTI_Scheme_Specific_Data scheme) const RFC6330_OTI_Scheme_Specific_Data scheme)
{ : _decoder (RaptorQ_type::RQ_DEC_64, common, scheme)
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_64, common, scheme); {}
}
template <> template <>
inline Decoder<uint8_t*, uint8_t*>::Decoder (const uint64_t size, inline Decoder<uint8_t*, uint8_t*>::Decoder (const uint64_t size,
...@@ -399,10 +331,10 @@ inline Decoder<uint8_t*, uint8_t*>::Decoder (const uint64_t size, ...@@ -399,10 +331,10 @@ inline Decoder<uint8_t*, uint8_t*>::Decoder (const uint64_t size,
const uint16_t sub_blocks, const uint16_t sub_blocks,
const uint8_t blocks, const uint8_t blocks,
const uint8_t alignment) const uint8_t alignment)
{
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_8, size, : _decoder (RaptorQ_type::RQ_DEC_8, size,
symbol_size, sub_blocks, blocks, alignment); symbol_size, sub_blocks, blocks, alignment)
} {}
template <> template <>
inline Decoder<uint16_t*, uint16_t*>::Decoder (const uint64_t size, inline Decoder<uint16_t*, uint16_t*>::Decoder (const uint64_t size,
...@@ -410,10 +342,9 @@ inline Decoder<uint16_t*, uint16_t*>::Decoder (const uint64_t size, ...@@ -410,10 +342,9 @@ inline Decoder<uint16_t*, uint16_t*>::Decoder (const uint64_t size,
const uint16_t sub_blocks, const uint16_t sub_blocks,
const uint8_t blocks, const uint8_t blocks,
const uint8_t alignment) const uint8_t alignment)
{ : _decoder (RaptorQ_type::RQ_DEC_16, size,
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_16, size, symbol_size, sub_blocks, blocks, alignment)
symbol_size, sub_blocks, blocks, alignment); {}
}
template <> template <>
inline Decoder<uint32_t*, uint32_t*>::Decoder (const uint64_t size, inline Decoder<uint32_t*, uint32_t*>::Decoder (const uint64_t size,
...@@ -421,10 +352,9 @@ inline Decoder<uint32_t*, uint32_t*>::Decoder (const uint64_t size, ...@@ -421,10 +352,9 @@ inline Decoder<uint32_t*, uint32_t*>::Decoder (const uint64_t size,
const uint16_t sub_blocks, const uint16_t sub_blocks,
const uint8_t blocks, const uint8_t blocks,
const uint8_t alignment) const uint8_t alignment)
{ : _decoder (RaptorQ_type::RQ_DEC_32, size,
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_32, size, symbol_size, sub_blocks, blocks, alignment)
symbol_size, sub_blocks, blocks, alignment); {}
}
template <> template <>
inline Decoder<uint64_t*, uint64_t*>::Decoder (const uint64_t size, inline Decoder<uint64_t*, uint64_t*>::Decoder (const uint64_t size,
...@@ -432,48 +362,33 @@ inline Decoder<uint64_t*, uint64_t*>::Decoder (const uint64_t size, ...@@ -432,48 +362,33 @@ inline Decoder<uint64_t*, uint64_t*>::Decoder (const uint64_t size,
const uint16_t sub_blocks, const uint16_t sub_blocks,
const uint8_t blocks, const uint8_t blocks,
const uint8_t alignment) const uint8_t alignment)
{ : _decoder (RaptorQ_type::RQ_DEC_64, size,
_decoder = new Impl::Decoder_void (RaptorQ_type::RQ_DEC_64, size, symbol_size, sub_blocks, blocks, alignment)
symbol_size, sub_blocks, blocks, alignment); {}
}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline Decoder<Rnd_It, Fwd_It>::~Decoder() inline Decoder<Rnd_It, Fwd_It>::~Decoder()
{ delete _decoder; } {}
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline It::Decoder::Block_Iterator<Rnd_It, Fwd_It> inline It::Decoder::Block_Iterator<Rnd_It, Fwd_It>
Decoder<Rnd_It, Fwd_It>::begin() Decoder<Rnd_It, Fwd_It>::begin()
{ return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (_decoder, 0); } { return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (&_decoder, 0); }
template <typename Rnd_It, typename Fwd_It> template <typename Rnd_It, typename Fwd_It>
inline const It::Decoder::Block_Iterator<Rnd_It, Fwd_It> inline const It::Decoder::Block_Iterator<Rnd_It, Fwd_It>
Decoder<Rnd_It, Fwd_It>::end() Decoder<Rnd_It, Fwd_It>::end()
{ { return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (&_decoder, blocks()); }
if (_decoder == nullptr)
return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (nullptr, 0);
return It::Encoder::Block_Iterator<Rnd_It, Fwd_It> (_decoder, blocks());
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline Decoder<In_It, Fwd_It>::operator bool() const inline Decoder<In_It, Fwd_It>::operator bool() const
{ { return static_cast<bool> (_decoder); }
if (_decoder == nullptr)
return false;
return static_cast<bool> (*_decoder);
}
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline std::future<std::pair<Error, uint8_t>> Decoder<In_It, Fwd_It>::compute ( inline std::future<std::pair<Error, uint8_t>> Decoder<In_It, Fwd_It>::compute (
const Compute flags) const Compute flags)
{ { return _decoder.compute(flags); }
if (_decoder != nullptr)
return _decoder->compute(flags);
std::promise<std::pair<Error, uint8_t>> p;
p.set_value ({Error::INITIALIZATION, 0});
return p.get_future();
}
#endif #endif
...@@ -481,20 +396,12 @@ template <typename In_It, typename Fwd_It> ...@@ -481,20 +396,12 @@ template <typename In_It, typename Fwd_It>
inline std::vector<bool> Decoder<In_It, Fwd_It>::end_of_input ( inline std::vector<bool> Decoder<In_It, Fwd_It>::end_of_input (
const Fill_With_Zeros fill, const Fill_With_Zeros fill,
const uint8_t block) const uint8_t block)
{ { return _decoder.end_of_input (fill, block); }
if (_decoder != nullptr)
return _decoder->end_of_input (fill, block);
return std::vector<bool>();
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline std::vector<bool> Decoder<In_It, Fwd_It>::end_of_input ( inline 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>
inline uint64_t Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start, inline uint64_t Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start,
...@@ -502,9 +409,12 @@ inline uint64_t Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start, ...@@ -502,9 +409,12 @@ inline uint64_t Decoder<In_It, Fwd_It>::decode_symbol (Fwd_It &start,
const uint16_t esi, const uint16_t esi,
const uint8_t sbn) const uint8_t sbn)
{ {
if (_decoder == nullptr) void **_from = reinterpret_cast<void**> (&start);
return 0; void *_to = reinterpret_cast<void*> (end);
return _decoder->decode_symbol (start, end, esi, sbn); auto ret = _decoder.decode_symbol (_from, _to, esi, sbn);
Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return ret;
} }
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
...@@ -512,9 +422,12 @@ inline uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start, ...@@ -512,9 +422,12 @@ inline uint64_t Decoder<In_It, Fwd_It>::decode_bytes (Fwd_It &start,
const Fwd_It end, const Fwd_It end,
const uint8_t skip) const uint8_t skip)
{ {
if (_decoder == nullptr) void **_from = reinterpret_cast<void**> (&start);
return 0; void *_to = reinterpret_cast<void*> (end);
return _decoder->decode_bytes (start, end, skip); auto ret = _decoder.decode_bytes (_from, _to, skip);
Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return ret;
} }
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
...@@ -523,12 +436,11 @@ inline size_t Decoder<In_It, Fwd_It>::decode_block_bytes (Fwd_It &start, ...@@ -523,12 +436,11 @@ inline size_t Decoder<In_It, Fwd_It>::decode_block_bytes (Fwd_It &start,
const uint8_t skip, const uint8_t skip,
const uint8_t sbn) const uint8_t sbn)
{ {
if (_decoder == nullptr)
return 0;
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_block_bytes (_from, _to, skip, sbn); auto ret = _decoder.decode_block_bytes (_from, _to, skip, sbn);
start = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return ret; return ret;
} }
...@@ -539,12 +451,11 @@ inline typename Decoder<In_It, Fwd_It>::aligned_res ...@@ -539,12 +451,11 @@ inline typename Decoder<In_It, Fwd_It>::aligned_res
const Fwd_It end, const Fwd_It end,
const uint8_t skip) const uint8_t skip)
{ {
if (_decoder == nullptr)
return {0, 0};
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_aligned (_from, _to, skip); auto ret = _decoder.decode_aligned (_from, _to, skip);
start = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return {ret.written, ret.offset}; return {ret.written, ret.offset};
} }
...@@ -556,12 +467,11 @@ inline typename Decoder<In_It, Fwd_It>::aligned_res ...@@ -556,12 +467,11 @@ inline typename Decoder<In_It, Fwd_It>::aligned_res
const uint8_t skip, const uint8_t skip,
const uint8_t sbn) const uint8_t sbn)
{ {
if (_decoder == nullptr)
return {0, 0};
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_block_aligned (_from, _to, skip, sbn); auto ret = _decoder.decode_block_aligned (_from, _to, skip, sbn);
start = *reinterpret_cast<Fwd_It*> (_from); Fwd_It *tmp = reinterpret_cast<Fwd_It*> (_from);
start = *tmp;
return {ret.written, ret.offset}; return {ret.written, ret.offset};
} }
...@@ -569,12 +479,11 @@ template <typename In_It, typename Fwd_It> ...@@ -569,12 +479,11 @@ template <typename In_It, typename Fwd_It>
inline Error Decoder<In_It, Fwd_It>::add_symbol (In_It &start, const In_It end, inline Error Decoder<In_It, Fwd_It>::add_symbol (In_It &start, const In_It end,
const uint32_t id) const uint32_t id)
{ {
if (_decoder == nullptr)
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->add_symbol (_from, _to, id); auto ret = _decoder.add_symbol (_from, _to, id);
start = *reinterpret_cast<Fwd_It*> (_from); In_It *tmp = reinterpret_cast<In_It*> (_from);
start = *tmp;
return ret; return ret;
} }
...@@ -583,94 +492,54 @@ inline Error Decoder<In_It, Fwd_It>::add_symbol (In_It &start, const In_It end, ...@@ -583,94 +492,54 @@ inline Error Decoder<In_It, Fwd_It>::add_symbol (In_It &start, const In_It end,
const uint32_t esi, const uint32_t esi,
const uint8_t sbn) const uint8_t sbn)
{ {
if (_decoder == nullptr)
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->add_symbol (_from, _to, esi, sbn); auto ret = _decoder.add_symbol (_from, _to, esi, sbn);
start = *reinterpret_cast<Fwd_It*> (_from); In_It *tmp = reinterpret_cast<In_It*> (_from);
start = *tmp;
return ret; return ret;
} }
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline uint8_t Decoder<In_It, Fwd_It>::blocks_ready() inline uint8_t Decoder<In_It, Fwd_It>::blocks_ready()
{ { return _decoder.blocks_ready(); }
if (_decoder == nullptr)
return 0;
return _decoder->blocks_ready();
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline bool Decoder<In_It, Fwd_It>::is_ready() inline bool Decoder<In_It, Fwd_It>::is_ready()
{ { return _decoder.is_ready(); }
if (_decoder == nullptr)
return false;
return _decoder->is_ready();
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline bool Decoder<In_It, Fwd_It>::is_block_ready (const uint8_t sbn) inline bool Decoder<In_It, Fwd_It>::is_block_ready (const uint8_t sbn)
{ { return _decoder.is_block_ready (sbn); }
if (_decoder == nullptr)
return false;
return _decoder->is_block_ready (sbn);
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline void Decoder<In_It, Fwd_It>::free (const uint8_t sbn) inline void Decoder<In_It, Fwd_It>::free (const uint8_t sbn)
{ { return _decoder.free (sbn); }
if (_decoder != nullptr)
return _decoder->free (sbn);
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline uint64_t Decoder<In_It, Fwd_It>::bytes() const inline uint64_t Decoder<In_It, Fwd_It>::bytes() const
{ { return _decoder.bytes(); }
if (_decoder == nullptr)
return 0;
return _decoder->bytes();
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline uint8_t Decoder<In_It, Fwd_It>::blocks() const inline uint8_t Decoder<In_It, Fwd_It>::blocks() const
{ { return _decoder.blocks(); }
if (_decoder == nullptr)
return 0;
return _decoder->blocks();
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline uint32_t Decoder<In_It, Fwd_It>::block_size (const uint8_t sbn) const inline uint32_t Decoder<In_It, Fwd_It>::block_size (const uint8_t sbn) const
{ { return _decoder.block_size (sbn); }
if (_decoder == nullptr)
return 0;
return _decoder->block_size (sbn);
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline uint16_t Decoder<In_It, Fwd_It>::symbol_size() const inline uint16_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>
inline uint16_t Decoder<In_It, Fwd_It>::symbols (const uint8_t sbn) const inline uint16_t Decoder<In_It, Fwd_It>::symbols (const uint8_t sbn) const
{ { return _decoder.symbols (sbn); }
if (_decoder == nullptr)
return 0;
return _decoder->symbols (sbn);
}
template <typename In_It, typename Fwd_It> template <typename In_It, typename Fwd_It>
inline Block_Size Decoder<In_It, Fwd_It>::extended_symbols (const uint8_t sbn) inline Block_Size Decoder<In_It, Fwd_It>::extended_symbols (const uint8_t sbn)
const const
{ { return _decoder.extended_symbols (sbn); }
if (_decoder == nullptr)
return static_cast<Block_Size> (0);
return _decoder->extended_symbols (sbn);
}
} // namespace RFC6330__v1 } // namespace RFC6330__v1
...@@ -354,7 +354,7 @@ size_t Encoder_void::encode (void** output, const void* end, const uint32_t esi, ...@@ -354,7 +354,7 @@ size_t Encoder_void::encode (void** output, const void* end, const uint32_t esi,
return ret; return ret;
} }
size_t Encoder_void::encode (void** output, const void* end, const uint32_t &id) size_t Encoder_void::encode (void** output, const void* end, const uint32_t id)
{ {
const cast_enc _enc (_encoder); const cast_enc _enc (_encoder);
uint8_t *p_8; uint8_t *p_8;
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
size_t precompute_max_memory (); size_t precompute_max_memory ();
size_t encode (void** output, const void* end, const uint32_t esi, size_t encode (void** output, const void* end, const uint32_t esi,
const uint8_t sbn); const uint8_t sbn);
size_t encode (void** output, const void* end, const uint32_t &id); size_t encode (void** output, const void* end, const uint32_t id);
void free (const uint8_t sbn); void free (const uint8_t sbn);
uint8_t blocks() const; uint8_t blocks() const;
uint32_t block_size (const uint8_t sbn) const; uint32_t block_size (const uint8_t sbn) const;
......
...@@ -18,7 +18,11 @@ ...@@ -18,7 +18,11 @@
* 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/RFC6330_v1_hdr.hpp" #if defined (TEST_HDR_ONLY)
#include "../src/RaptorQ/RFC6330_v1_hdr.hpp"
#else
#include "../src/RaptorQ/RFC6330_v1.hpp"
#endif
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <random> #include <random>
...@@ -67,11 +71,13 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -67,11 +71,13 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
std::ceil(static_cast<float> (mysize) / sizeof(in_enc_align)))); std::ceil(static_cast<float> (mysize) / sizeof(in_enc_align))));
in_enc_align tmp = 0; in_enc_align tmp = 0;
uint8_t shift = 0; uint8_t shift = 0;
uint8_t insert = 0; uint8_t data_counter;
data_counter = 0;
for (uint32_t i = 0; i < mysize; ++i) { for (uint32_t i = 0; i < mysize; ++i) {
tmp += static_cast<in_enc_align> (insert) << shift * 8; // insert predicatable data: for debugging
++insert; //tmp += static_cast<in_enc_align> (insert++) << shift * 8;
//tmp += static_cast<in_enc_align> (i) << shift * 8; // insert random data
tmp += static_cast<in_enc_align> (distr (rnd)) << shift * 8;
++shift; ++shift;
if (shift >= sizeof(in_enc_align)) { if (shift >= sizeof(in_enc_align)) {
myvec.push_back (tmp); myvec.push_back (tmp);
...@@ -99,12 +105,11 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -99,12 +105,11 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
std::cout << "Subsymbol: " << subsymbol << " Symbol: " << symbol_size<<"\n"; std::cout << "Subsymbol: " << subsymbol << " Symbol: " << symbol_size<<"\n";
size_t aligned_symbol_size = static_cast<size_t> ( size_t aligned_symbol_size = static_cast<size_t> (
std::ceil(static_cast<float> (symbol_size) / sizeof(out_enc_align))); std::ceil(static_cast<float> (symbol_size) / sizeof(out_enc_align)));
auto enc_it = myvec.begin(); auto enc_it = myvec.begin().base();
std::uniform_int_distribution<uint32_t> mem_distr (100, 200000); std::uniform_int_distribution<uint32_t> mem_distr (10, 20000);
RFC6330::Encoder<typename std::vector<in_enc_align>::iterator, RFC6330::Encoder<in_enc_align*, out_enc_align*> enc (
typename std::vector<out_enc_align>::iterator> enc ( enc_it, myvec.end().base(), subsymbol, symbol_size, mem_distr(rnd));
enc_it, myvec.end(), subsymbol, symbol_size, mem_distr(rnd));
std::cout << "Size: " << mysize << " Blocks: " << std::cout << "Size: " << mysize << " Blocks: " <<
static_cast<int32_t>(enc.blocks()) << "\n"; static_cast<int32_t>(enc.blocks()) << "\n";
if (!enc) { if (!enc) {
...@@ -143,9 +148,9 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -143,9 +148,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 (aligned_symbol_size); source_sym.reserve (aligned_symbol_size);
source_sym.insert (source_sym.begin(), aligned_symbol_size, 0); source_sym.insert (source_sym.begin(), aligned_symbol_size, 0);
auto it = source_sym.begin(); auto it = source_sym.begin().base();
// save the symbol // save the symbol
auto written = (*sym_it) (it, source_sym.end()); auto written = (*sym_it) (it, source_sym.end().base());
if (written != aligned_symbol_size) { if (written != aligned_symbol_size) {
std::cout << written << "-vs-" << aligned_symbol_size << std::cout << written << "-vs-" << aligned_symbol_size <<
" Could not get the whole source symbol!\n"; " Could not get the whole source symbol!\n";
...@@ -169,9 +174,9 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -169,9 +174,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 (aligned_symbol_size); repair_sym.reserve (aligned_symbol_size);
repair_sym.insert (repair_sym.begin(), aligned_symbol_size, 0); repair_sym.insert (repair_sym.begin(), aligned_symbol_size, 0);
auto it = repair_sym.begin(); auto it = repair_sym.begin().base();
// save the repair symbol // save the repair symbol
auto written = (*sym_it) (it, repair_sym.end()); auto written = (*sym_it) (it, repair_sym.end().base());
if (written != aligned_symbol_size) { if (written != aligned_symbol_size) {
std::cout << written << "-vs-" << aligned_symbol_size << std::cout << written << "-vs-" << aligned_symbol_size <<
" Could not get the whole repair symbol!\n"; " Could not get the whole repair symbol!\n";
...@@ -193,8 +198,7 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -193,8 +198,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
RFC6330::Decoder<typename std::vector<in_dec_align>::iterator, RFC6330::Decoder<in_dec_align*, out_dec_align*>
typename std::vector<out_dec_align>::iterator>
dec (oti_common, oti_scheme); dec (oti_common, oti_scheme);
if (!dec) { if (!dec) {
std::cout << "Could not initialize decoder\n"; std::cout << "Could not initialize decoder\n";
...@@ -216,8 +220,8 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -216,8 +220,8 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
received.resize (out_size, 0); received.resize (out_size, 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(); auto it = encoded[i].second.begin().base();
auto err = dec.add_symbol (it, encoded[i].second.end(), auto err = dec.add_symbol (it, encoded[i].second.end().base(),
encoded[i].first); encoded[i].first);
if (err != RFC6330::Error::NONE && err != RFC6330::Error::NOT_NEEDED) { if (err != RFC6330::Error::NONE && err != RFC6330::Error::NOT_NEEDED) {
std::cout << "error adding?\n"; std::cout << "error adding?\n";
...@@ -229,12 +233,12 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob, ...@@ -229,12 +233,12 @@ bool decode (const uint32_t mysize, std::mt19937_64 &rnd, float drop_prob,
async_dec.wait(); async_dec.wait();
auto re_it = received.begin(); auto re_it = 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); auto decoded = dec.decode_bytes (re_it, received.end().base(), 0);
assert (mysize == dec.bytes()); assert (mysize == dec.bytes());
// "decoded" can be more than mysize if the alignments are different // "decoded" can be more than mysize if the alignments are different
...@@ -299,6 +303,7 @@ int main (void) ...@@ -299,6 +303,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);
...@@ -359,11 +364,13 @@ int main (void) ...@@ -359,11 +364,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);
...@@ -424,6 +431,7 @@ int main (void) ...@@ -424,6 +431,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);
......