MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / EncodeVarint32

Function EncodeVarint32

tensorflow/core/lib/core/coding.cc:76–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76char* EncodeVarint32(char* dst, uint32 v) {
77 // Operate on characters as unsigneds
78 unsigned char* ptr = reinterpret_cast<unsigned char*>(dst);
79 static const int B = 128;
80 if (v < (1 << 7)) {
81 *(ptr++) = v;
82 } else if (v < (1 << 14)) {
83 *(ptr++) = v | B;
84 *(ptr++) = v >> 7;
85 } else if (v < (1 << 21)) {
86 *(ptr++) = v | B;
87 *(ptr++) = (v >> 7) | B;
88 *(ptr++) = v >> 14;
89 } else if (v < (1 << 28)) {
90 *(ptr++) = v | B;
91 *(ptr++) = (v >> 7) | B;
92 *(ptr++) = (v >> 14) | B;
93 *(ptr++) = v >> 21;
94 } else {
95 *(ptr++) = v | B;
96 *(ptr++) = (v >> 7) | B;
97 *(ptr++) = (v >> 14) | B;
98 *(ptr++) = (v >> 21) | B;
99 *(ptr++) = v >> 28;
100 }
101 return reinterpret_cast<char*>(ptr);
102}
103
104void PutVarint32(string* dst, uint32 v) {
105 char buf[5];

Callers 2

PutVarint32Function · 0.85
Encode32Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected