MCPcopy Create free account
hub / github.com/apache/trafficserver / xpack_encode_integer

Function xpack_encode_integer

src/proxy/hdrs/XPACK.cc:143–177  ·  view source on GitHub ↗

[RFC 7541] 5.1. Integer representation

Source from the content-addressed store, hash-verified

141// [RFC 7541] 5.1. Integer representation
142//
143int64_t
144xpack_encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint64_t value, uint8_t n)
145{
146 if (buf_start >= buf_end) {
147 return -1;
148 }
149
150 uint8_t *p = buf_start;
151
152 // Preserve the first n bits
153 uint8_t prefix = *buf_start & (0xFF << n);
154
155 if (value < (static_cast<uint64_t>(UINT64_C(1) << n) - 1)) {
156 *(p++) = value;
157 } else {
158 *(p++) = (1 << n) - 1;
159 value -= (1 << n) - 1;
160 while (value >= 128) {
161 if (p >= buf_end) {
162 return -1;
163 }
164 *(p++) = (value & 0x7F) | 0x80;
165 value = value >> 7;
166 }
167 if (p + 1 >= buf_end) {
168 return -1;
169 }
170 *(p++) = value;
171 }
172
173 // Restore the prefix
174 *buf_start |= prefix;
175
176 return p - buf_start;
177}
178
179int64_t
180xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, uint64_t value_len, uint8_t n)

Calls

no outgoing calls

Tested by 1

acknowledge_header_blockFunction · 0.68