Skip to content

Instantly share code, notes, and snippets.

@adventurist
Created July 7, 2020 18:51
Show Gist options
  • Save adventurist/00859c2c85061b1985d2b5b6bccfd9fd to your computer and use it in GitHub Desktop.
Save adventurist/00859c2c85061b1985d2b5b6bccfd9fd to your computer and use it in GitHub Desktop.
Decoder returns vector (cpp)
#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