public class FecDecode extends Object implements IFecDecode
融进kcp要考虑fec导致的rtt计算不准的问题 参考 https://github.com/xtaci/kcp-go/issues/63 Created by JinMiao 2018/6/8. TODO go版本使用的uint为序列id 在发送24亿条消息之后可能会出现兼容问题,以后版本修复
| 限定符和类型 | 字段和说明 |
|---|---|
private ReedSolomonNative |
codec |
private int |
dataShards |
private io.netty.buffer.ByteBuf[] |
decodeCache |
private boolean[] |
flagCache
标记是否已经缓存了
|
private int |
parityShards |
private MyArrayList<FecPacket> |
rx |
private int |
rxlimit |
private int |
shardSize
dataShards+parityShards
|
private io.netty.buffer.ByteBuf |
zeros |
| 构造器和说明 |
|---|
FecDecode(int rxlimit,
ReedSolomonNative codec,
int mtu) |
| 限定符和类型 | 方法和说明 |
|---|---|
static MyArrayList<Integer> |
build(int size) |
List<io.netty.buffer.ByteBuf> |
decode(FecPacket pkt)
1,已经收到的丢弃掉
2,找到应该插入rx的位置并插入
3,从rx中找到当前包已收到的属于当前包组的消息集合
4,检验数据包是否已经全部收到了 ,则清理rx收到的包
5,如果收到的一组包数量大于等于数据包数量(dataShards),进行消息补全,再进行数据恢复
6, 恢复后清空rx收到的包
注意: pkt在传入后不要做释放操作 pkt的data不要做释放操作
返回的对象是被丢掉的数据 需要手动 release
|
private static void |
freeRange(int first,
int n,
MyArrayList<FecPacket> q)
1,回收first后n个bytebuf
2,将q的first到first+n之间的数据移除掉
3,将尾部的n个数据的data清空
4,返回开头到尾部n个数组的对象
|
static void |
main(String[] args) |
void |
release() |
private static void |
remove(int first,
int n,
MyArrayList<Integer> q) |
private int rxlimit
private int dataShards
private int parityShards
private int shardSize
private MyArrayList<FecPacket> rx
private io.netty.buffer.ByteBuf[] decodeCache
private boolean[] flagCache
private io.netty.buffer.ByteBuf zeros
private ReedSolomonNative codec
public FecDecode(int rxlimit,
ReedSolomonNative codec,
int mtu)
public List<io.netty.buffer.ByteBuf> decode(FecPacket pkt)
decode 在接口中 IFecDecodepublic void release()
release 在接口中 IFecDecodeprivate static void freeRange(int first,
int n,
MyArrayList<FecPacket> q)
first - n - q - public static void main(String[] args)
public static MyArrayList<Integer> build(int size)
private static void remove(int first,
int n,
MyArrayList<Integer> q)
Copyright © 2022. All rights reserved.