MCPcopy Create free account
hub / github.com/deepseek-ai/3FS / EncodeVarint32

Function EncodeVarint32

src/common/utils/coding.cc:21–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21char *EncodeVarint32(char *dst, uint32_t v) {
22 // Operate on characters as unsigneds
23 uint8_t *ptr = reinterpret_cast<uint8_t *>(dst);
24 static const int B = 128;
25 if (v < (1 << 7)) {
26 *(ptr++) = v;
27 } else if (v < (1 << 14)) {
28 *(ptr++) = v | B;
29 *(ptr++) = v >> 7;
30 } else if (v < (1 << 21)) {
31 *(ptr++) = v | B;
32 *(ptr++) = (v >> 7) | B;
33 *(ptr++) = v >> 14;
34 } else if (v < (1 << 28)) {
35 *(ptr++) = v | B;
36 *(ptr++) = (v >> 7) | B;
37 *(ptr++) = (v >> 14) | B;
38 *(ptr++) = v >> 21;
39 } else {
40 *(ptr++) = v | B;
41 *(ptr++) = (v >> 7) | B;
42 *(ptr++) = (v >> 14) | B;
43 *(ptr++) = (v >> 21) | B;
44 *(ptr++) = v >> 28;
45 }
46 return reinterpret_cast<char *>(ptr);
47}
48
49void PutVarint32(std::string *dst, uint32_t v) {
50 char buf[5];

Callers 1

PutVarint32Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected