mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-19 06:19:34 +08:00
45 lines
631 B
C
45 lines
631 B
C
/*
|
|
* rs.c
|
|
*
|
|
* Created on: Sep 14, 2017
|
|
* Author: root
|
|
*/
|
|
#include "rs.h"
|
|
|
|
void rs_encode(void *code,char *data[],int size)
|
|
{
|
|
int k=get_k(code);
|
|
int n=get_n(code);
|
|
for(int i=k;i<n;i++)
|
|
{
|
|
fec_encode(code, (void **)data, data[i],i, size);
|
|
}
|
|
|
|
return ;
|
|
}
|
|
|
|
int rs_decode(void *code,char *data[],int size)
|
|
{
|
|
int k=get_k(code);
|
|
int n=get_n(code);
|
|
int index[n];
|
|
int count=0;
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
if(data[i]!=0)
|
|
{
|
|
index[count++]=i;
|
|
}
|
|
}
|
|
if(count<k)
|
|
return -1;
|
|
for(int i=0;i<n;i++)
|
|
{
|
|
if(i<count)
|
|
data[i]=data[index[i]];
|
|
else
|
|
data[i]=0;
|
|
}
|
|
return fec_decode(code,(void**)data,index,size);
|
|
}
|