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

Method Print

src/brpc/redis_reply.cpp:292–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292void RedisStringPrinter::Print(std::ostream& os) const {
293 size_t flush_start = 0;
294 for (size_t i = 0; i < _str.size(); ++i) {
295 const char c = _str[i];
296 if (c <= 0) { // unprintable chars
297 if (i != flush_start) {
298 os << butil::StringPiece(_str.data() + flush_start, i - flush_start);
299 }
300 char buf[8] = "\\u0000";
301 uint8_t d1 = ((uint8_t)c) & 0xF;
302 uint8_t d2 = ((uint8_t)c) >> 4;
303 buf[4] = (d1 < 10 ? d1 + '0' : (d1 - 10) + 'A');
304 buf[5] = (d2 < 10 ? d2 + '0' : (d2 - 10) + 'A');
305 os << butil::StringPiece(buf, 6);
306 flush_start = i + 1;
307 } else if (c == '"' || c == '\\') { // need to escape
308 if (i != flush_start) {
309 os << butil::StringPiece(_str.data() + flush_start, i - flush_start);
310 }
311 os << '\\' << c;
312 flush_start = i + 1;
313 }
314 }
315 if (flush_start != _str.size()) {
316 os << butil::StringPiece(_str.data() + flush_start, _str.size() - flush_start);
317 }
318}
319
320// Mimic how official redis-cli prints.
321void RedisReply::Print(std::ostream& os) const {

Callers 1

redis_reply.cppFile · 0.45

Calls 3

RedisStringPrinterClass · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected