Created
July 7, 2020 19:03
-
-
Save adventurist/3730b8350f259e1887e821b29dc923d4 to your computer and use it in GitHub Desktop.
Decoder getter (cpp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <vector> | |
class Decoder { | |
public: | |
Decoder() { buffer.reserve(4990);} | |
bool decode(unsigned char* data, uint32_t size) { | |
if (size == 10) { | |
buffer.insert(buffer.end(), data, data + size); | |
return true; | |
} else { | |
buffer.insert(buffer.end(), data, data + size); | |
return false; | |
} | |
} | |
std::vector<unsigned char> get() { | |
return buffer; | |
} | |
private: | |
std::vector<unsigned char> buffer; | |
}; | |
unsigned char big_data[10]{5}; | |
unsigned char small_data[5]{4}; | |
class Link { | |
public: | |
void process(bool big) { | |
if (big) { | |
if (decoder.decode(big_data, 10)) { | |
auto data = decoder.get(); | |
} | |
} else { | |
if (decoder.decode(small_data, 4)) { | |
auto data = decoder.get(); | |
} | |
} | |
} | |
private: | |
Decoder decoder; | |
}; | |
int main() { | |
Decoder decoder{}; | |
Link link{}; | |
link.process(false); | |
link.process(false); | |
link.process(false); | |
link.process(false); | |
link.process(false); | |
link.process(true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment