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/API_Wrapper.h"
#include "RaptorQ/v1/API_Wrapper.hpp"
#include "RaptorQ/v1/caches.hpp"
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
struct RAPTORQ_LOCAL RaptorQ_future
{
std::future<std::pair<RFC6330__v1::Error, uint8_t>> f;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
void RAPTORQ_LOCAL RFC6330_test_del (struct RaptorQ_ptr **ptr);
void RAPTORQ_LOCAL RFC6330_test_del (struct RaptorQ_ptr **ptr)
{
if (ptr == nullptr || *ptr == nullptr ||
(*ptr)->type == RaptorQ_type::RQ_NONE
|| (*ptr)->ptr == nullptr) {
if (ptr != nullptr) {
delete *ptr;
*ptr = nullptr;
return;
}
return;
}
switch ((*ptr)->type) {
case RaptorQ_type::RQ_ENC_8:
if(!(reinterpret_cast<RFC6330__v1::Encoder<uint8_t*, uint8_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_ENC_16:
if(!(reinterpret_cast<RFC6330__v1::Encoder<uint16_t, uint16_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_ENC_32:
if(!(reinterpret_cast<RFC6330__v1::Encoder<uint32_t*, uint32_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_ENC_64:
if(!(reinterpret_cast<RFC6330__v1::Encoder<uint64_t*, uint64_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_DEC_8:
if(!(reinterpret_cast<RFC6330__v1::Decoder<uint8_t*, uint8_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_DEC_16:
if(!(reinterpret_cast<RFC6330__v1::Decoder<uint16_t*, uint16_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_DEC_32:
if(!(reinterpret_cast<RFC6330__v1::Decoder<uint32_t*, uint32_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_DEC_64:
if(!(reinterpret_cast<RFC6330__v1::Decoder<uint64_t*, uint64_t*>*> (
(*ptr)->ptr))) {
RaptorQ_free (ptr);
return;
}
break;
case RaptorQ_type::RQ_NONE:
assert(false && "RaptorQ: C Wrapper: should not have gotten here");
break;
}
return;
}
struct RaptorQ_ptr *RaptorQ_Enc (const RaptorQ_type type, void *data,
const uint64_t size,
const uint16_t min_subsymbol_size,
const uint16_t symbol_size,
const size_t max_memory)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
new RFC6330__v1::Encoder<uint8_t*, uint8_t*> (
reinterpret_cast<uint8_t*> (data),
reinterpret_cast<uint8_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
new RFC6330__v1::Encoder<uint16_t*, uint16_t*> (
reinterpret_cast<uint16_t*> (data),
reinterpret_cast<uint16_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
new RFC6330__v1::Encoder<uint32_t*, uint32_t*> (
reinterpret_cast<uint32_t*> (data),
reinterpret_cast<uint32_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
new RFC6330__v1::Encoder<uint64_t*, uint64_t*> (
reinterpret_cast<uint64_t*> (data),
reinterpret_cast<uint64_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
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);
auto raw_ptr = ret.release();
RFC6330_test_del (&raw_ptr);
return raw_ptr;
}
struct RaptorQ_ptr *RaptorQ_Dec (const RaptorQ_type type,
const RaptorQ_OTI_Common_Data common,
const RaptorQ_OTI_Scheme_Specific_Data scheme)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
new RFC6330__v1::Decoder<uint8_t*, uint8_t*> (common, scheme));
new RFC6330__v1::Decoder<uint16_t*, uint16_t*> (common,scheme));
new RFC6330__v1::Decoder<uint32_t*, uint32_t*> (common,scheme));
new RFC6330__v1::Decoder<uint64_t*, uint64_t*> (common,scheme));
Loading full blame...