Newer
Older
* Copyright (c) 2015-2018, 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
{
RaptorQ_ptr ()
: ptr (nullptr), type (RaptorQ_type::RQ_NONE) {}
RaptorQ_ptr (const RaptorQ_type _type, void *const _ptr)
: ptr (_ptr), type (_type) {}
} 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;
RaptorQ_future_enc ()
:base (RaptorQ_Future_Type::RQ_FUTURE_ENCODER) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_dec
{
const struct RaptorQ_future base;
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!
////
////////////////////////
static RaptorQ_Compress v1_supported_compressions();
static RaptorQ_Compress v1_get_compression();
static bool v1_set_compression (const RaptorQ_Compress compression);
static size_t v1_local_cache_size (const size_t local_cache);
static size_t v1_get_local_cache_size ();
const RaptorQ_Block_Size symbols,
const size_t symbol_size,
static uint16_t v1_symbols (const RaptorQ_ptr *ptr);
static size_t v1_symbol_size (const RaptorQ_ptr *ptr);
static void v1_stop (const RaptorQ_ptr *ptr);
static RaptorQ_Error v1_future_state (struct RaptorQ_future *const f);
static RaptorQ_Error v1_future_wait_for (struct RaptorQ_future *const f,
static void v1_future_wait (struct RaptorQ_future *const f);
static void v1_future_free (struct RaptorQ_future **f);
static void v1_free (struct RaptorQ_ptr **ptr);
static bool v1_ready (const RaptorQ_ptr *ptr);
static size_t v1_set_data (const RaptorQ_ptr *enc, void **from,
const size_t size);
static bool v1_precompute_sync (const RaptorQ_ptr *enc);
static bool v1_compute_sync (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* v1_precompute (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* v1_compute (const RaptorQ_ptr *enc);
static RaptorQ_Error v1_enc_future_get (struct RaptorQ_future_enc *f);
static size_t v1_encode (const RaptorQ_ptr *enc, void **from, const size_t size,
const uint32_t id);
static RaptorQ_Error v1_add_symbol (const RaptorQ_ptr *dec, void **from,
const size_t size,
static bool v1_can_decode (const RaptorQ_ptr *dec);
static uint16_t v1_needed_symbols (const RaptorQ_ptr *dec);
static RaptorQ_Dec_wait_res v1_poll (const RaptorQ_ptr *dec);
static RaptorQ_Dec_wait_res v1_wait_sync (const RaptorQ_ptr *dec);
static RaptorQ_future_dec* v1_wait (const RaptorQ_ptr *dec);
static RaptorQ_Dec_wait_res v1_dec_future_get (struct RaptorQ_future_dec *f);
static struct RaptorQ_Byte_Tracker v1_end_of_input (struct RaptorQ_ptr *dec,
const RaptorQ_Fill_With_Zeros fill);
static RaptorQ_Decoder_Result v1_decode_once (struct RaptorQ_ptr *dec);
static RaptorQ_Error v1_decode_symbol (struct RaptorQ_ptr *dec, void** start,
const size_t size, const uint16_t esi);
static RaptorQ_Dec_Written v1_decode_bytes (struct RaptorQ_ptr *dec,
void **start,
const size_t size,
const size_t from_byte,
const size_t skip);
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;
}
return reinterpret_cast<RaptorQ_base_api*> (new RaptorQ_v1());
}
RaptorQ_v1::RaptorQ_v1()
: base (1),
supported_compressions (&v1_supported_compressions),
get_compression (&v1_get_compression),
set_compression (&v1_set_compression),
local_cache_size (&v1_local_cache_size),
get_local_cache_size (&v1_get_local_cache_size),
Encoder (&v1_Encoder),
Decoder (&v1_Decoder),
initialized (&v1_initialized),
symbols (&v1_symbols),
symbol_size (&v1_symbol_size),
stop (&v1_stop),
future_state (&v1_future_state),
future_wait_for (&v1_future_wait_for),
future_wait (&v1_future_wait),
future_free (&v1_future_free),
free (&v1_free),
max_repair (&v1_max_repair),
set_data (&v1_set_data),
has_data (&v1_has_data),
clear_data (&v1_clear_data),
precompute_sync (&v1_precompute_sync),
compute_sync (&v1_compute_sync),
precompute (&v1_precompute),
compute (&v1_compute),
enc_future_get (&v1_enc_future_get),
encode (&v1_encode),
Loading full blame...