"git@fenrirproject.org:Sikabo/libRaptorQ.git" did not exist on "37eaf8755edfd83b4926e06c40c5b2d544a6b715"
Newer
Older
/*
* Copyright (c) 2015-2016, Luca Fulchir<luca@fulchir.it>, All rights reserved.
*
* This file is part of "libRaptorQ".
*
* libRaptorQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* libRaptorQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and a copy of the GNU Lesser General Public License
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "RaptorQ/v1/wrapper/C_RAW_API.h"
#include "RaptorQ/v1/RaptorQ.hpp"
#include <future>
#include <utility>
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
typedef enum {
} RAPTORQ_LOCAL RaptorQ_Future_Type;
struct RAPTORQ_LOCAL RaptorQ_future
{
const RaptorQ_Future_Type type;
RaptorQ_future (const RaptorQ_Future_Type t)
:type (t) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_enc
{
const struct RaptorQ_future base;
std::future<RaptorQ__v1::Error> f;
RaptorQ_future_enc ()
:base (RaptorQ_Future_Type::RQ_FUTURE_ENCODER) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_dec
{
const struct RaptorQ_future base;
std::future<std::pair<RaptorQ__v1::Error, uint16_t>> f;
RaptorQ_future_dec ()
:base (RaptorQ_Future_Type::RQ_FUTURE_DECODER) {}
};
////////////////////////
////
//// For ease of development please keep the function declaration
//// and implementation in the same orders as defined in the structs!
////
////////////////////////
// precomputation caching
static RaptorQ_Compress RAPTORQ_LOCAL v1_supported_compressions();
static RaptorQ_Compress RAPTORQ_LOCAL v1_get_compression();
static bool RAPTORQ_LOCAL v1_set_compression (
const RaptorQ_Compress compression);
static size_t RAPTORQ_LOCAL v1_shared_cache_size (const size_t shared_cache);
static size_t RAPTORQ_LOCAL v1_local_cache_size (const size_t local_cache);
static size_t RAPTORQ_LOCAL v1_get_shared_cache_size ();
static size_t RAPTORQ_LOCAL v1_get_local_cache_size ();
// constructors
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder (RaptorQ_type type,
const size_t symbol_size);
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Decoder (RaptorQ_type type,
const RaptorQ_Block_Size symbols,
const size_t symbol_size,
const RaptorQ_Compute report);
static bool RAPTORQ_LOCAL v1_initialized (const RaptorQ_ptr *ptr);
// common functions
static uint16_t RAPTORQ_LOCAL v1_symbols (const RaptorQ_ptr *ptr);
static size_t RAPTORQ_LOCAL v1_symbol_size (const RaptorQ_ptr *ptr);
static void RAPTORQ_LOCAL v1_stop (const RaptorQ_ptr *ptr);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_state (struct RaptorQ_future *f);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_wait_for (struct RaptorQ_future *f,
const uint64_t time,
const RaptorQ_Unit_Time unit);
static void RAPTORQ_LOCAL v1_future_wait (struct RaptorQ_future *f);
static void RAPTORQ_LOCAL v1_future_free (struct RaptorQ_future **f);
// encoder-specific
static uint32_t RAPTORQ_LOCAL v1_max_repair (const RaptorQ_ptr *enc);
static size_t RAPTORQ_LOCAL v1_set_data (const RaptorQ_ptr *enc, void *from,
static bool RAPTORQ_LOCAL v1_has_data (const RaptorQ_ptr *enc);
static void RAPTORQ_LOCAL v1_clear_data (const RaptorQ_ptr *enc);
static bool RAPTORQ_LOCAL v1_precompute_sync (const RaptorQ_ptr *enc);
static bool RAPTORQ_LOCAL v1_compute_sync (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* RAPTORQ_LOCAL v1_precompute (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* RAPTORQ_LOCAL v1_compute (const RaptorQ_ptr *enc);
static RaptorQ_Error RAPTORQ_LOCAL v1_enc_future_get (
struct RaptorQ_future_enc *f);
static size_t RAPTORQ_LOCAL v1_encode (const RaptorQ_ptr *enc, void *from,
const void *to, const uint32_t id);
// decoder-specific
static RaptorQ_Error RAPTORQ_LOCAL v1_add_symbol (const RaptorQ_ptr *dec,
void *from,
const void *to,
const uint32_t esi);
static bool RAPTORQ_LOCAL v1_can_decode (const RaptorQ_ptr *dec);
static uint16_t RAPTORQ_LOCAL v1_needed_symbols (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_poll (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_wait_sync (const RaptorQ_ptr *dec);
static RaptorQ_future_dec* RAPTORQ_LOCAL v1_wait (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_dec_future_get (
struct RaptorQ_future_dec *f);
void RaptorQ_free_api (struct RaptorQ_base_api **api)
{
if (api == nullptr || *api == nullptr)
return;
if ((*api)->version == 1) {
delete reinterpret_cast<struct RaptorQ_v1*> (*api);
} // else it's all your fault anway
*api = nullptr;
}
struct RaptorQ_base_api* RAPTORQ_API RaptorQ_api (uint32_t version)
{
if (version != 1)
return nullptr;
auto api = new RaptorQ_v1();
api->base.version = 1;
// precomputation caching
api->supported_compressions = &v1_supported_compressions;
api->get_compression = &v1_get_compression;
api->set_compression = &v1_set_compression;
api->shared_cache_size = &v1_shared_cache_size;
api->local_cache_size = &v1_local_cache_size;
api->get_shared_cache_size = &v1_get_shared_cache_size;
api->get_local_cache_size = &v1_get_local_cache_size;
// constructors
api->Encoder = &v1_Encoder;
api->Decoder = &v1_Decoder;
// common functions
api->symbols = &v1_symbols;
api->symbol_size = &v1_symbol_size;
api->future_state = &v1_future_state;
api->future_wait_for = &v1_future_wait_for;
api->future_wait = &v1_future_wait;
api->future_free = &v1_future_free;
// encoder-specific functions
api->max_repair = &v1_max_repair;
api->set_data = &v1_set_data;
api->has_data = &v1_has_data;
api->compute = &v1_compute;
api->enc_future_get = &v1_enc_future_get;
api->encode = &v1_encode;
// decoder-specific functions
api->add_symbol = &v1_add_symbol;
api->can_decode = &v1_can_decode;
api->needed_symbols = &v1_needed_symbols;
api->poll = &v1_poll;
api->wait_sync = &v1_wait_sync;
api->wait = &v1_wait;
api->dec_future_get = &v1_dec_future_get;
return reinterpret_cast<RaptorQ_base_api *> (api);
}
///////////////////////////
// Precomputation caching
///////////////////////////
static RaptorQ_Compress v1_supported_compressions()
{
return static_cast<RaptorQ_Compress>(RaptorQ__v1::supported_compressions());
}
static RaptorQ_Compress v1_get_compression()
{ return static_cast<RaptorQ_Compress>(RaptorQ__v1::get_compression()); }
static bool v1_set_compression (const RaptorQ_Compress compression)
{
return static_cast<RaptorQ_Compress> (RaptorQ__v1::set_compression (
static_cast<RaptorQ__v1::Compress> (compression)));
}
static size_t v1_shared_cache_size (const size_t shared_cache)
{ return RaptorQ__v1::shared_cache_size (shared_cache); }
static size_t v1_local_cache_size (const size_t local_cache)
{ return RaptorQ__v1::local_cache_size (local_cache); }
static size_t v1_get_shared_cache_size ()
{ return RFC6330__v1::get_shared_cache_size(); }
static size_t v1_get_local_cache_size ()
/////////////////////
// Constructors
/////////////////////
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder (RaptorQ_type type,
const size_t symbol_size)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
case RaptorQ_type::RQ_ENC_8:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*> (
break;
case RaptorQ_type::RQ_ENC_16:
ret->ptr = reinterpret_cast<void *> (
break;
case RaptorQ_type::RQ_ENC_32:
ret->ptr = reinterpret_cast<void *> (
break;
case RaptorQ_type::RQ_ENC_64:
ret->ptr = reinterpret_cast<void *> (
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
}
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Decoder (RaptorQ_type type,
const RaptorQ_Block_Size symbols,
const size_t symbol_size,
const RaptorQ_Compute report)
{
if (report != RQ_COMPUTE_PARTIAL_FROM_BEGINNING &&
report != RQ_COMPUTE_PARTIAL_ANY &&
report != RQ_COMPUTE_COMPLETE) {
return nullptr;
}
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
namespace RQ = RaptorQ__v1::Impl;
switch (type) {
case RaptorQ_type::RQ_DEC_8:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint8_t*, uint8_t*> (
static_cast<RaptorQ__v1::Block_Size>(symbols),
symbol_size,
static_cast<RQ::Decoder<uint8_t*, uint8_t*>::Report>
(report)));
break;
case RaptorQ_type::RQ_DEC_16:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint16_t*, uint16_t*> (
static_cast<RaptorQ__v1::Block_Size>(symbols),
symbol_size,
static_cast<RQ::Decoder<uint16_t*, uint16_t*>::Report>
(report)));
break;
case RaptorQ_type::RQ_DEC_32:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint32_t*, uint32_t*> (
static_cast<RaptorQ__v1::Block_Size>(symbols),
symbol_size,
static_cast<RQ::Decoder<uint32_t*, uint32_t*>::Report>
(report)));
break;
case RaptorQ_type::RQ_DEC_64:
ret->ptr = reinterpret_cast<void *> (
new RQ::Decoder<uint64_t*, uint64_t*> (
static_cast<RaptorQ__v1::Block_Size>(symbols),
symbol_size,
static_cast<RQ::Decoder<uint64_t*, uint64_t*>::Report>
(report)));
break;
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
static bool RAPTORQ_LOCAL v1_initialized (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_ENC_16:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_ENC_32:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_ENC_64:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_DEC_8:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_DEC_16:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_DEC_32:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_DEC_64:
return (*reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr));
case RaptorQ_type::RQ_NONE:
break;
}
/////////////////////
// Common functions
/////////////////////
static uint16_t v1_symbols (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols();
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols();
case RaptorQ_type::RQ_DEC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols();
return 0;
}
static size_t v1_symbol_size (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::RQ_DEC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
static void v1_stop (const RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->ptr == nullptr)
return;
switch (ptr->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_DEC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_DEC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_DEC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_DEC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->stop();
case RaptorQ_type::RQ_NONE:
break;
}
}
static RaptorQ_Error v1_future_state (struct RaptorQ_future *f)
{
if (f == nullptr)
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
if (reinterpret_cast<RaptorQ_future_enc*> (f)->f.valid())
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
if (reinterpret_cast<RaptorQ_future_dec*> (f)->f.valid())
}
static RaptorQ_Error v1_future_wait_for (struct RaptorQ_future *f,
const uint64_t time,
const RaptorQ_Unit_Time unit)
{
if (f == nullptr)
return RQ_ERR_WRONG_INPUT;
std::future_status status = std::future_status::timeout;
switch (unit) {
case RQ_TIME_NANOSEC:
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::nanoseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::nanoseconds (time));
}
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::microseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::microseconds (time));
}
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::milliseconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::milliseconds (time));
}
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::seconds (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::seconds (time));
}
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::minutes (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::minutes (time));
}
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
status = reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait_for (
std::chrono::hours (time));
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
status = reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait_for (
std::chrono::hours (time));
}
break;
}
if (status == std::future_status::ready)
return RaptorQ_Error::RQ_ERR_NONE;
return RaptorQ_Error::RQ_ERR_WORKING;
}
static void v1_future_wait (struct RaptorQ_future *f)
{
if (f == nullptr)
switch (f->type)
{
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
reinterpret_cast<RaptorQ_future_enc*>(f)->f.wait();
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
reinterpret_cast<RaptorQ_future_dec*>(f)->f.wait();
}
}
static void v1_future_free (struct RaptorQ_future **f)
{
if (f == nullptr || *f == nullptr)
switch ((*f)->type) {
case RaptorQ_Future_Type::RQ_FUTURE_ENCODER:
delete reinterpret_cast<RaptorQ_future_enc*>(*f);
break;
case RaptorQ_Future_Type::RQ_FUTURE_DECODER:
delete reinterpret_cast<RaptorQ_future_dec*>(*f);
}
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
static void v1_free (struct RaptorQ_ptr **ptr)
{
if (ptr == nullptr || *ptr == nullptr)
return;
if ((*ptr)->ptr == nullptr) {
delete *ptr;
return;
}
switch ((*ptr)->type) {
case RaptorQ_type::RQ_ENC_8:
delete reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> ((*ptr)->ptr);
break;
case RaptorQ_type::RQ_ENC_16:
delete reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_ENC_32:
delete reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_ENC_64:
delete reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_DEC_8:
delete reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint8_t*, uint8_t*>*> ((*ptr)->ptr);
break;
case RaptorQ_type::RQ_DEC_16:
delete reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint16_t*, uint16_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_DEC_32:
delete reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint32_t*, uint32_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_DEC_64:
delete reinterpret_cast<
RaptorQ__v1::Impl::Decoder<uint64_t*, uint64_t*>*>((*ptr)->ptr);
break;
case RaptorQ_type::RQ_NONE:
break;
}
}
//////////////////////////////
// Encoder-specific functions
//////////////////////////////
static uint32_t v1_max_repair (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->max_repair();
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->max_repair();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
static size_t v1_set_data (const RaptorQ_ptr *enc, void *from, const void *to)
uint8_t *f_8 = reinterpret_cast<uint8_t*> (from);
uint16_t *f_16 = reinterpret_cast<uint16_t*> (from);
uint32_t *f_32 = reinterpret_cast<uint32_t*> (from);
uint64_t *f_64= reinterpret_cast<uint64_t*> (from);
size_t ret;
switch (enc->type) {
reinterpret_cast<uint8_t*> (
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_8);
return ret;
reinterpret_cast<uint16_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_16);
return ret;
reinterpret_cast<uint32_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_32);
return ret;
ret = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
reinterpret_cast<uint64_t*>(
const_cast<void*>(to)));
from = reinterpret_cast<void*> (f_64);
return ret;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
static bool v1_has_data (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return false;
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->has_data();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->has_data();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->has_data();
case RaptorQ_type::RQ_ENC_64:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->has_data();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
break;
}
return false;
}
static void v1_clear_data (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->clear_data();
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->clear_data();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return;
}
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
}
static bool v1_compute_sync (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_ENC_16:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_ENC_32:
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->compute_sync();
return (reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->compute_sync();
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
static RaptorQ_future_enc* v1_precompute (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
return nullptr;
RaptorQ_future_enc *fut = new RaptorQ_future_enc();
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->precompute();
break;
case RaptorQ_type::RQ_ENC_16:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr)->precompute();
break;
case RaptorQ_type::RQ_ENC_32:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr)->precompute();
break;
case RaptorQ_type::RQ_ENC_64:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr)->precompute();
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return nullptr;
}
return fut;
}
static RaptorQ_future_enc* v1_compute (const RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->ptr == nullptr)
RaptorQ_future_enc *fut = new RaptorQ_future_enc();
switch (enc->type) {
case RaptorQ_type::RQ_ENC_8:
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->compute();
break;
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr)->compute();
break;
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr)->compute();
break;
fut->f = reinterpret_cast<
RaptorQ__v1::Impl::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr)->compute();
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return nullptr;
}
return fut;
}
static RaptorQ_Error v1_enc_future_get (struct RaptorQ_future_enc *f)
{
if (f == nullptr)
if (f->f.valid())
return static_cast<RaptorQ_Error> (f->f.get());
return RaptorQ_Error::RQ_ERR_WORKING;
}
static size_t v1_encode (const RaptorQ_ptr *enc, void *from, const void *to,
const uint32_t id)
{
if (enc == nullptr || enc->ptr == nullptr)
uint8_t *f_8 = reinterpret_cast<uint8_t*> (from);
uint16_t *f_16 = reinterpret_cast<uint16_t*> (from);
uint32_t *f_32 = reinterpret_cast<uint32_t*> (from);
uint64_t *f_64= reinterpret_cast<uint64_t*> (from);
size_t ret;
switch (enc->type) {
RaptorQ__v1::Impl::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr)->encode (f_8,
reinterpret_cast<uint8_t*> (
const_cast<void*>(to)), id);
from = reinterpret_cast<void*> (f_8);
return ret;