MCPcopy Create free account
hub / github.com/apache/brpc / EncodeString

Function EncodeString

src/brpc/details/hpack.cpp:568–604  ·  view source on GitHub ↗

use template to remove dead branches.

Source from the content-addressed store, hash-verified

566
567template <bool LOWERCASE> // use template to remove dead branches.
568inline void EncodeString(butil::IOBufAppender* out, const std::string& s,
569 bool huffman_encoding) {
570 if (!huffman_encoding) {
571 EncodeInteger(out, 0x00, 7, s.size());
572 if (LOWERCASE) {
573 for (size_t i = 0; i < s.size(); ++i) {
574 out->push_back(butil::ascii_tolower(s[i]));
575 }
576 } else {
577 out->append(s);
578 }
579 return;
580 }
581 // Calculate length of encoded string
582 uint32_t bit_len = 0;
583 if (LOWERCASE) {
584 for (size_t i = 0; i < s.size(); ++i) {
585 bit_len += s_huffman_table[(uint8_t)butil::ascii_tolower(s[i])].bit_len;
586 }
587 } else {
588 for (size_t i = 0; i < s.size(); ++i) {
589 bit_len += s_huffman_table[(uint8_t)s[i]].bit_len;
590 }
591 }
592 EncodeInteger(out, 0x80, 7, (bit_len >> 3) + !!(bit_len & 7));
593 HuffmanEncoder e(out, s_huffman_table);
594 if (LOWERCASE) {
595 for (size_t i = 0; i < s.size(); ++i) {
596 e.Encode(butil::ascii_tolower(s[i]));
597 }
598 } else {
599 for (size_t i = 0; i < s.size(); ++i) {
600 e.Encode(s[i]);
601 }
602 }
603 e.EndStream();
604}
605
606inline ssize_t DecodeString(butil::IOBufBytesIterator& iter, std::string* out) {
607 if (iter == NULL) {

Callers

nothing calls this directly

Calls 7

EncodeIntegerFunction · 0.85
ascii_tolowerFunction · 0.85
sizeMethod · 0.45
push_backMethod · 0.45
appendMethod · 0.45
EncodeMethod · 0.45
EndStreamMethod · 0.45

Tested by

no test coverage detected