first commit
This commit is contained in:
commit
7dd9dd689e
40 changed files with 4100 additions and 0 deletions
32
ProtoGen/ProtoUtil.cpp
Normal file
32
ProtoGen/ProtoUtil.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "ProtoUtil.h"
|
||||
|
||||
size_t varint_length(uint32_t v) {
|
||||
if (v == 0) return 1;
|
||||
|
||||
size_t logcounter = 0;
|
||||
while (v > 0) {
|
||||
++logcounter;
|
||||
v >>= 7;
|
||||
}
|
||||
return logcounter;
|
||||
}
|
||||
|
||||
size_t encode_varint(std::vector<uint8_t>& dst, uint32_t value) {
|
||||
constexpr uint8_t MSB = 0b10000000;
|
||||
|
||||
uint32_t n = value;
|
||||
size_t i = 0;
|
||||
|
||||
while (n >= 0x80) {
|
||||
dst.push_back(MSB | static_cast<uint8_t>(n & 0x7F));
|
||||
++i;
|
||||
n >>= 7;
|
||||
}
|
||||
|
||||
dst.push_back(static_cast<uint8_t>(n));
|
||||
return i + 1;
|
||||
}
|
||||
|
||||
uint32_t pack_wire_tag(uint32_t field_id, uint8_t wire_type) {
|
||||
return (field_id << 3) | static_cast<uint32_t>(wire_type);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue