David Blume's GitList
Repositories
testcode.git
Code
Commits
Branches
Tags
Search
Tree:
3959371
Branches
Tags
c++11
main
start
testcode.git
product
copilot_serialize.cpp
Add copilot_serialization
dblume
commited
3959371
at 2023-11-14 14:51:58
copilot_serialize.cpp
Blame
History
Raw
#include <vector> // GitHub CoPilot generated this // This code will serialize a number using the minimum number of bytes. // Each byte will contain 7 bits of the number and the 8th bit will be // used to indicate if there are more bytes to follow std::vector<unsigned char> serialize(unsigned long long value) { std::vector<unsigned char> result; do { unsigned char byte = value & 0x7F; value >>= 7; if (value > 0) { byte |= 0x80; } result.push_back(byte); } while (value > 0); return result; } unsigned long long deserialize(std::vector<unsigned char> const& bytes) { unsigned long long result = 0; for (auto it = bytes.rbegin(); it != bytes.rend(); ++it) { result <<= 7; result |= *it & 0x7F; } return result; }