Created
July 7, 2020 18:51
-
-
Save adventurist/00859c2c85061b1985d2b5b6bccfd9fd to your computer and use it in GitHub Desktop.
Decoder returns vector (cpp)
This file contains 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);} | |
std::vector<unsigned char> decode(unsigned char* data, uint32_t size) { | |
if (size == 10) { | |
buffer.insert(buffer.end(), data, data + size); | |
return buffer; | |
} else { | |
buffer.insert(buffer.end(), data, data + size); | |
return {}; | |
} | |
} | |
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) { | |
decoder.decode(big_data, 10); | |
} else { | |
decoder.decode(small_data, 4); | |
} | |
} | |
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