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

Function xpack_encode_string

src/proxy/hdrs/XPACK.cc:179–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)
181{
182 uint8_t *p = buf_start;
183 constexpr bool use_huffman = true;
184
185 ts::LocalBuffer<uint8_t, 4096> local_buffer(value_len * 4);
186 uint8_t *data = local_buffer.data();
187 int64_t data_len = 0;
188
189 // TODO Choose whether to use Huffman encoding wisely
190 // cppcheck-suppress knownConditionTrueFalse; leaving "use_huffman" for wise huffman usage in the future
191 if (use_huffman && value_len) {
192 data_len = huffman_encode(data, reinterpret_cast<const uint8_t *>(value), value_len);
193 }
194
195 // Length
196 const int64_t len = xpack_encode_integer(p, buf_end, data_len, n);
197 if (len == -1) {
198 return -1;
199 }
200
201 if (use_huffman) {
202 *p |= 0x01 << n;
203 } else {
204 *p &= ~(0x01 << n);
205 }
206 p += len;
207
208 if (buf_end < p || buf_end - p < data_len) {
209 return -1;
210 }
211
212 // Value
213 if (data_len) {
214 memcpy(p, data, data_len);
215 p += data_len;
216 }
217
218 return p - buf_start;
219}
220
221//
222// DynamicTable

Calls 4

huffman_encodeFunction · 0.85
xpack_encode_integerFunction · 0.85
memcpyFunction · 0.50
dataMethod · 0.45

Tested by

no test coverage detected