cobs_decode.cpp
来自「COBS-consistent overhead byte stuffing」· C++ 代码 · 共 37 行
CPP
37 行
// COBS_decode.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
unsigned char source[] = {0x05,0x04,0x04,0x01,0x01,0x02,0x02,0x05,0x28,0xA5,0x01,0xFF}; //Max length is 12,because after encoded,00 doesn't get into buffer when receiving
unsigned char destination[12]; //Max length is 12, When less than 12, the last byte 00 can be ignored
unsigned char length = sizeof(source);
unsigned char *pEnd = source + length;
unsigned char *pSource = source;
unsigned char *pDestination = destination;
while ( pSource < pEnd)
{
unsigned char index;
unsigned code = *pSource++;
for ( index = 1; index < code; ++index)
{
*pDestination = *pSource;
++pDestination;
++pSource;
}
*pDestination++ = 0;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?