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

Function DecodeInteger

src/brpc/details/hpack.cpp:531–565  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

529static const size_t MAX_HPACK_INTEGER = 10 * 1024 * 1024ul;
530
531inline ssize_t DecodeInteger(butil::IOBufBytesIterator& iter,
532 uint8_t prefix_size, uint32_t* value) {
533 if (iter == NULL) {
534 return 0; // No enough data
535 }
536 uint8_t first_byte = *iter;
537 uint64_t tmp = first_byte & ((1 << prefix_size) - 1);
538 ++iter;
539 if (tmp < ((1u << prefix_size) - 1)) {
540 *value = static_cast<uint32_t>(tmp);
541 return 1;
542 }
543 uint8_t cur_byte = 0;
544 int m = 0;
545 ssize_t in_bytes = 1;
546 do {
547 if (!iter) {
548 return 0;
549 }
550 cur_byte = *iter;
551 in_bytes++;
552 tmp += static_cast<uint64_t>(cur_byte & 0x7f) << m;
553 m += 7;
554 ++iter;
555 } while ((cur_byte & 0x80) && (tmp < MAX_HPACK_INTEGER));
556
557 if (tmp >= MAX_HPACK_INTEGER) {
558 LOG(ERROR) << "Source stream is likely malformed";
559 return -1;
560 }
561
562 *value = static_cast<uint32_t>(tmp);
563
564 return in_bytes;
565}
566
567template <bool LOWERCASE> // use template to remove dead branches.
568inline void EncodeString(butil::IOBufAppender* out, const std::string& s,

Callers 3

DecodeStringFunction · 0.85
DecodeWithKnownPrefixMethod · 0.85
DecodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected