thy1016/moonkcp/fec does not have a README file

    MdsCodec

    pub(open) trait MdsCodec {
    fn encode_parity(Self, Array[FixedArray[Byte]]) -> Array[FixedArray[Byte]]
    fn recover(Self, Array[FixedArray[Byte]?]) -> Array[FixedArray[Byte]]?
    }

    MDS 端口:k 数据片 + m 冗余片,任意 ≤m 片抹除可恢复;片等长。

    FecRx

    pub struct FecRx {
    depth : Int
    codec_factory : (Int, Int) -> &MdsCodec
    groups : Map[Int, RxGroup]
    order : Array[Int]
    frames_in : Int
    delivered : Int
    recovered_shards : Int
    recovered_groups : Int
    dropped_malformed : Int
    dropped_late : Int
    groups_lost : Int
    }

    FEC 接收机:纯形零 IO,帧由宿主搬运。

    FecRx::feed

    fn FecRx::feed(self : FecRx, frame : FixedArray[Byte]) -> Array[FixedArray[Byte]]

    进一线上帧,出 KCP 报文流:数据帧即刻透传(剥头剥垫);组齐 k 片 当场恢复,缺失数据片补投;坏帧/重复帧/迟到帧弃置计数。

    FecRx::new

    fn FecRx::new(depth : Int) -> FecRx

    RS 缺省适配器版。

    FecRx::stats

    fn FecRx::stats(self : FecRx) -> FecRxStats

    FecRx::with_codec

    fn FecRx::with_codec(codec_factory : (Int, Int) -> &MdsCodec, depth : Int) -> FecRx

    端口注入版(编解码器工厂逐组调用,k/m 由帧头自描述)。

    FecRxStats

    pub struct FecRxStats {
    frames_in : Int
    delivered : Int
    recovered_shards : Int
    recovered_groups : Int
    dropped_malformed : Int
    dropped_late : Int
    groups_lost : Int
    }

    接收快照(观测面,R6;信号聚合器将来读此喂策略端口)。

    FecTx

    pub struct FecTx {
    k : Int
    m : Int
    capacity : Int
    codec : &MdsCodec
    group_id : Int
    slots : Array[FixedArray[Byte]]
    closed_groups : Int
    frames_out : Int
    }

    FEC 发送机:纯形零 IO,帧由宿主搬运。

    FecTx::feed

    fn FecTx::feed(self : FecTx, payload : FixedArray[Byte]) -> Array[FixedArray[Byte]]

    下一片数据:载荷进组,出线上帧——数据帧即出;组满同突发追加冗余帧。 判据:载荷 ≤ capacity - 14(12B 头 + 2B 体长前缀),超限即断言死 (刀4 以 KCP mtu 让位保证;静默截断是谎报)。

    FecTx::new

    fn FecTx::new(k : Int, m : Int, capacity : Int) -> FecTx

    RS 缺省适配器版。

    FecTx::stats

    fn FecTx::stats(self : FecTx) -> FecTxStats

    FecTx::with_codec

    fn FecTx::with_codec(codec : &MdsCodec, k : Int, m : Int, capacity : Int) -> FecTx

    端口注入版(换码 = 换适配器,层机器零改动)。 判据:k ≥ 1,m ≥ 1,k+m ≤ 255(shard_total 单字节线域;越域即断言死, k+m=256 的组形线头写不出,发出来只会全数被对端弃置——谎报不如急停)。

    FecTxStats

    pub struct FecTxStats {
    closed_groups : Int
    frames_out : Int
    }

    发送快照。

    RsCodec

    pub struct RsCodec {
    k : Int
    m : Int
    matrix : FixedArray[Int]
    }

    RS(k+m) 编解码器(系统码:数据片透传,冗余片 = Cauchy 行 × 数据片)。 判据:k ≥ 1,m ≥ 1,k+m ≤ 256(GF 域上限;Cauchy 的 x/y 两组取 [0, k+m) 不相交分割)。片长由调用面统一(刀3 垫片收口)。

    RsCodec::encode_parity

    fn RsCodec::encode_parity(self : RsCodec, data : Array[FixedArray[Byte]]) -> Array[FixedArray[Byte]]

    编码冗余片:k 个等长数据片进,m 个冗余片出(纯函数,不改输入)。

    RsCodec::new

    fn RsCodec::new(k : Int, m : Int) -> RsCodec

    RsCodec::recover

    fn RsCodec::recover(self : RsCodec, slots : Array[FixedArray[Byte]?]) -> Array[FixedArray[Byte]]?

    从存活片恢复全量:slots 长度 = k+m(Some = 存活,None = 抹除)。 存活 ≥ k 即可恢复(MDS);返回全量 k+m 片——数据片按序重造, 冗余片由数据片重编码。存活不足 / 片长不一 / 子阵不可逆 → None。

    RxGroup

    type RxGroup

    组槽位(包私有):逐组自描述 k/m——发侧逐组拍板,收侧零协商。

    FEC_HEADER_SIZE

    let FEC_HEADER_SIZE : Int

    FEC 头字节数(线帧 = 头 + 片体;刀4 以此让位 KCP mtu,D-FEC5)。

    GF_POLY

    let GF_POLY : Int

    域多项式(含 x^8 位)。

    gf_div

    fn gf_div(a : Int, b : Int) -> Int

    GF 除法:b = 0 无定义,防御返 0(调用面 = 可逆子阵消元,不产生除零)。

    gf_inv

    fn gf_inv(a : Int) -> Int

    GF 逆元:a = 0 无定义,防御返 0。

    gf_mul

    fn gf_mul(a : Int, b : Int) -> Int

    GF 乘法:全值域定义(0 吸收)。

    gf_mul_shift_add

    fn gf_mul_shift_add(a : Int, b : Int) -> Int

    移位加参照乘法:与表实现算法独立,公开供测试/交叉验证对拍 (全组合逐项相等 = 刀1 已知答案门)。