Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
/*
* Copyright (c) 2015, 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 "cRaptorQ.h"
#include "RaptorQ.hpp"
#include <memory>
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));
switch (type) {
case RaptorQ_type::ENC_8:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Encoder<uint8_t*, uint8_t*> (
reinterpret_cast<uint8_t*> (data),
reinterpret_cast<uint8_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
case RaptorQ_type::ENC_16:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Encoder<uint16_t*, uint16_t*> (
reinterpret_cast<uint16_t*> (data),
reinterpret_cast<uint16_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
case RaptorQ_type::ENC_32:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Encoder<uint32_t*, uint32_t*> (
reinterpret_cast<uint32_t*> (data),
reinterpret_cast<uint32_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
case RaptorQ_type::ENC_64:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::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::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return new RaptorQ_ptr (RaptorQ_type::NONE);
}
return ret.release();
}
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) {
case RaptorQ_type::DEC_8:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Decoder<uint8_t*, uint8_t*> (common, scheme));
break;
case RaptorQ_type::DEC_16:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Decoder<uint16_t*, uint16_t*> (common,scheme));
break;
case RaptorQ_type::DEC_32:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Decoder<uint32_t*, uint32_t*> (common,scheme));
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
break;
case RaptorQ_type::DEC_64:
ret->ptr = reinterpret_cast<void *> (
new RaptorQ::Decoder<uint64_t*, uint64_t*> (common,scheme));
break;
case RaptorQ_type::ENC_8:
case RaptorQ_type::ENC_16:
case RaptorQ_type::ENC_32:
case RaptorQ_type::ENC_64:
case RaptorQ_type::NONE:
return new RaptorQ_ptr (RaptorQ_type::NONE);
}
return ret.release();
}
///////////
// Encoding
///////////
RaptorQ_OTI_Common_Data RaptorQ_OTI_Common (struct RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->OTI_Common();
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->OTI_Common();
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->OTI_Common();
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->OTI_Common();
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
RaptorQ_OTI_Scheme_Specific_Data RaptorQ_OTI_Scheme (struct RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->OTI_Scheme_Specific();
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->OTI_Scheme_Specific();
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->OTI_Scheme_Specific();
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->OTI_Scheme_Specific();
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
}
uint16_t RaptorQ_symbol_size (RaptorQ_ptr *ptr) {
if (ptr == nullptr || ptr->type == RaptorQ_type::NONE ||ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbol_size();
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
}
uint8_t RaptorQ_blocks (RaptorQ_ptr *ptr)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::NONE ||ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t, uint16_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->blocks();
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
}
uint32_t RaptorQ_block_size (RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::NONE ||ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->block_size(sbn);
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
}
uint16_t RaptorQ_symbols (RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::NONE ||ptr->ptr == nullptr)
return 0;
switch (ptr->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->symbols(sbn);
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint32_t RaptorQ_max_repair (RaptorQ_ptr *enc, const uint8_t sbn)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->max_repair (sbn);
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->max_repair (sbn);
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->max_repair (sbn);
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->max_repair (sbn);
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
}
size_t RaptorQ_precompute_max_memory (RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||enc->ptr == nullptr)
return 0;
switch (enc->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->precompute_max_memory();
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->precompute_max_memory();
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->precompute_max_memory();
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->precompute_max_memory();
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
}
void RaptorQ_precompute (RaptorQ_ptr *enc, const uint8_t threads,
const bool background)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||enc->ptr == nullptr)
return;
switch (enc->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->precompute (threads, background);
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->precompute (threads, background);
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->precompute (threads, background);
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->precompute (threads, background);
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return;
#endif
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
}
uint64_t RaptorQ_encode_id (RaptorQ_ptr *enc, void **data, const uint64_t size,
const uint32_t id)
{
uint8_t sbn = id >> 24;
uint32_t esi = (id << 8) >> 8;
return RaptorQ_encode (enc, data, size, esi, sbn);
}
uint64_t RaptorQ_encode (RaptorQ_ptr *enc, void **data, const uint64_t size,
const uint32_t esi,
const uint8_t sbn)
{
if (enc == nullptr || enc->type == RaptorQ_type::NONE ||
enc->ptr == nullptr || data == nullptr || *data == nullptr) {
return 0;
}
// uhm... better ideas?
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (enc->type) {
case RaptorQ_type::ENC_8:
p_8 = reinterpret_cast<uint8_t*> (*data);
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
enc->ptr))->encode (p_8, p_8 + size,esi, sbn);
case RaptorQ_type::ENC_16:
p_16 = reinterpret_cast<uint16_t*> (*data);
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
enc->ptr))->encode (p_16, p_16 + size,esi, sbn);
case RaptorQ_type::ENC_32:
p_32 = reinterpret_cast<uint32_t*> (*data);
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
enc->ptr))->encode (p_32, p_32 + size,esi, sbn);
case RaptorQ_type::ENC_64:
p_64 = reinterpret_cast<uint64_t*> (*data);
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
enc->ptr))->encode (p_64, p_64 + size,esi, sbn);
case RaptorQ_type::DEC_8:
case RaptorQ_type::DEC_16:
case RaptorQ_type::DEC_32:
case RaptorQ_type::DEC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
uint32_t RaptorQ_id (const uint32_t esi, const uint8_t sbn)
{
uint32_t ret = static_cast<uint32_t> (sbn) << 24;
ret += esi % static_cast<uint32_t> (std::pow (2, 24));
return ret;
}
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
uint64_t RAPTORQ_API RaptorQ_bytes (struct RaptorQ_ptr *dec)
{
if (dec == nullptr || dec->type == RaptorQ_type::NONE)
return 0;
switch (dec->type) {
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr))->bytes ();
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr))->bytes ();
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr))->bytes ();
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr))->bytes ();
case RaptorQ_type::ENC_8:
case RaptorQ_type::ENC_16:
case RaptorQ_type::ENC_32:
case RaptorQ_type::ENC_64:
case RaptorQ_type::NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint64_t RaptorQ_decode (RaptorQ_ptr *dec, void **data, const size_t size)
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
{
if (dec == nullptr || dec->type == RaptorQ_type::NONE ||
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (dec->type) {
case RaptorQ_type::DEC_8:
p_8 = reinterpret_cast<uint8_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr))->decode (p_8, p_8 + size);
case RaptorQ_type::DEC_16:
p_16 = reinterpret_cast<uint16_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr))->decode (p_16, p_16 + size);
case RaptorQ_type::DEC_32:
p_32 = reinterpret_cast<uint32_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr))->decode (p_32, p_32 + size);
case RaptorQ_type::DEC_64:
p_64 = reinterpret_cast<uint64_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr))->decode (p_64, p_64 + size);
case RaptorQ_type::ENC_8:
case RaptorQ_type::ENC_16:
case RaptorQ_type::ENC_32:
case RaptorQ_type::ENC_64:
case RaptorQ_type::NONE:
return false;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return false;
#endif
uint64_t RaptorQ_decode_block (RaptorQ_ptr *dec, void **data, const size_t size,
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
const uint8_t sbn)
{
if (dec == nullptr || dec->type == RaptorQ_type::NONE ||
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (dec->type) {
case RaptorQ_type::DEC_8:
p_8 = reinterpret_cast<uint8_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr))->decode (p_8, p_8 + size, sbn);
case RaptorQ_type::DEC_16:
p_16 = reinterpret_cast<uint16_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr))->decode (p_16, p_16 + size, sbn);
case RaptorQ_type::DEC_32:
p_32 = reinterpret_cast<uint32_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr))->decode (p_32, p_32 + size, sbn);
case RaptorQ_type::DEC_64:
p_64 = reinterpret_cast<uint64_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr))->decode (p_64, p_64 + size, sbn);
case RaptorQ_type::ENC_8:
case RaptorQ_type::ENC_16:
case RaptorQ_type::ENC_32:
case RaptorQ_type::ENC_64:
case RaptorQ_type::NONE:
return false;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return false;
#endif
630
631
632
633
634
635
636
637
638
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
}
bool RaptorQ_add_symbol_id (RaptorQ_ptr *dec, void **data, const uint32_t size,
const uint32_t id)
{
uint8_t sbn = id >> 24;
uint32_t esi = (id << 8) >> 8;
return RaptorQ_add_symbol (dec, data, size, esi, sbn);
}
bool RaptorQ_add_symbol (RaptorQ_ptr *dec, void **data, const uint32_t size,
const uint32_t esi,
const uint8_t sbn)
{
if (dec == nullptr || dec->type == RaptorQ_type::NONE ||
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (dec->type) {
case RaptorQ_type::DEC_8:
p_8 = reinterpret_cast<uint8_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
dec->ptr))->add_symbol (p_8, p_8 + size, esi, sbn);
case RaptorQ_type::DEC_16:
p_16 = reinterpret_cast<uint16_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
dec->ptr))->add_symbol (p_16, p_16 + size, esi, sbn);
case RaptorQ_type::DEC_32:
p_32 = reinterpret_cast<uint32_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
dec->ptr))->add_symbol (p_32, p_32 + size, esi, sbn);
case RaptorQ_type::DEC_64:
p_64 = reinterpret_cast<uint64_t*> (*data);
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
dec->ptr))->add_symbol (p_64, p_64 + size, esi, sbn);
case RaptorQ_type::ENC_8:
case RaptorQ_type::ENC_16:
case RaptorQ_type::ENC_32:
case RaptorQ_type::ENC_64:
case RaptorQ_type::NONE:
return false;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return false;
#endif
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
}
///////////////////////
// General: free memory
///////////////////////
void RaptorQ_free (struct RaptorQ_ptr **ptr)
{
if (ptr == nullptr || *ptr == nullptr || (*ptr)->type == RaptorQ_type::NONE
|| (*ptr)->ptr == nullptr) {
if (ptr != nullptr) {
if (*ptr != nullptr) {
// (*ptr)->ptr == nullptr
free (*ptr);
*ptr = nullptr;
return;
}
return;
}
return;
}
switch ((*ptr)->type) {
case RaptorQ_type::ENC_8:
delete reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::ENC_16:
delete reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::ENC_32:
delete reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::ENC_64:
delete reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::DEC_8:
delete reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::DEC_16:
delete reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
(*ptr)->ptr);
case RaptorQ_type::DEC_32:
delete reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
(*ptr)->ptr);
delete reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
case RaptorQ_type::NONE:
break;
}
(*ptr)->ptr = nullptr;
free (*ptr);
*ptr = nullptr;
return;
}
void RaptorQ_free_block (struct RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::NONE ||ptr->ptr == nullptr)
return;
switch (ptr->type) {
case RaptorQ_type::ENC_8:
return (reinterpret_cast<RaptorQ::Encoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::ENC_16:
return (reinterpret_cast<RaptorQ::Encoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::ENC_32:
return (reinterpret_cast<RaptorQ::Encoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::ENC_64:
return (reinterpret_cast<RaptorQ::Encoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::DEC_8:
return (reinterpret_cast<RaptorQ::Decoder<uint8_t*, uint8_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::DEC_16:
return (reinterpret_cast<RaptorQ::Decoder<uint16_t*, uint16_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::DEC_32:
return (reinterpret_cast<RaptorQ::Decoder<uint32_t*, uint32_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::DEC_64:
return (reinterpret_cast<RaptorQ::Decoder<uint64_t*, uint64_t*>*> (
ptr->ptr))->free(sbn);
case RaptorQ_type::NONE:
return;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return;
#endif