赞
踩
1. RS_Code是什么
RS_Code是纠删码的一种。
Erasure Code(EC),即纠删码,是一种前向错误纠正技术(Forward Error Correction,FEC),主要应用在网络传输中避免包的丢失, 存储系统利用它来提高 存储 可靠性。相比多副本复制而言, 纠删码能够以更小的数据冗余度获得更高数据可靠性, 但编码方式较复杂,需要大量计算 。纠删码只能容忍数据丢失,无法容忍数据篡改,纠删码正是得名与此。
Erasure Code是一种编码技术,它可以将n份原始数据,增加m份数据,并能通过n+m份中的任意n份数据,还原为原始数据。即如果有任意小于等于m份的数据失效,仍然能通过剩下的数据还原出来。
目前,纠删码技术在分布式存储 系统中的应用主要有三类,阵列纠删码(Array Code: RAID5、RAID6等)、RS(Reed-Solomon)里德-所罗门类纠删码和LDPC(LowDensity Parity Check Code)低密度奇偶校验纠删码。
2. RS_Code库
- INCLUDEPATH += $$PWD/../depends/rscode/include
- Debug:{
- LIBS += -L$$PWD/../depends/rscode/lib/x64/Debug -lrscode
- }
- Release:{
- LIBS += -L$$PWD/../depends/rscode/lib/x64/Release -lrscode
- }
3. RS_Code的使用
- QByteArray origMsg = QByteArray::fromHex( "09 0c 09 0a 0c 0a 0b 0f 0c 0c 10 0c 0d 0d 10 11 0f 15 08 15 11 0b 0d 00 0c 00");
-
- qDebug() << "mac = " << mac << "before, origMsg = " << origMsg.toHex();
- QByteArray inbandMsg = ConvertOrigMsgToInbandMsg(origMsg);
- qDebug() << "mac = " << mac << "before, inbandMsg = " << inbandMsg.toHex();
- QList<int> lostFlag;
- lostFlag.clear();
- for (int i = 0; i< 26-3;i++)
- {
- lostFlag << (0);
- }
- lostFlag << (1);
- lostFlag << (0);
- lostFlag << (1);
- QVector<qint32> erasure = GetRSCodeErasure(lostFlag);
- RSCode::getInstance().Decode(inbandMsg, erasure);
- qDebug() << "mac = " << mac << "after, inbandMsg = " << inbandMsg.toHex();
- origMsg = InbandMsgToConvertOrigMsg(inbandMsg);
- qDebug() << "mac = " << mac << "after, origMsg = " << origMsg.toHex();

- QByteArray InbandMsg::ConvertOrigMsgToInbandMsg(QByteArray &origMsg)
- {
- QByteArray inbandMsg;
-
- //未拼接的原始消息长度必须是2的倍数(原始消息每次传4bit)
- if ((origMsg.size() % 2) != 0)
- {
- return inbandMsg;
- }
-
- int inbandMsgSize = origMsg.size() / 2;
- int high4Bit;
- int low4Bit;
- int byteValue;
- for (int i = 0; i < inbandMsgSize; i++)
- {
- high4Bit = (origMsg[2*i] - ORIG_MSG_CONTENT_BEGINE) & 0x0f;
- low4Bit = (origMsg[2*i + 1] - ORIG_MSG_CONTENT_BEGINE) & 0x0f;
- byteValue = (high4Bit << 4) + low4Bit;
- inbandMsg += static_cast<char>(byteValue);
- }
- return inbandMsg;
- }
-
-
- QByteArray InbandMsg::InbandMsgToConvertOrigMsg(QByteArray &inbandMsg)
- {
- QByteArray origMsg;
- int high4Bit;
- int low4Bit;
- for (int i = 0; i < inbandMsg.size(); i++)
- {
- high4Bit = (inbandMsg.at(i) & 0xf0) >> 4;
- origMsg+= static_cast<char>(high4Bit);
- low4Bit = inbandMsg.at(i) & 0x0f;
- origMsg+= static_cast<char>(low4Bit);
- }
-
- return origMsg;
- }

4. 参考文献
Erasure Code - EC纠删码原理 https://blog.csdn.net/shelldon/article/details/54144730
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。