| 29 | // The printing format is optimized for humans and may change in future. |
| 30 | |
| 31 | class ToPrintable { |
| 32 | public: |
| 33 | static const size_t DEFAULT_MAX_LENGTH = 64; |
| 34 | |
| 35 | ToPrintable(const IOBuf& b, size_t max_length = DEFAULT_MAX_LENGTH) |
| 36 | : _iobuf(&b), _max_length(max_length) {} |
| 37 | |
| 38 | ToPrintable(const StringPiece& str, size_t max_length = DEFAULT_MAX_LENGTH) |
| 39 | : _iobuf(NULL), _str(str), _max_length(max_length) {} |
| 40 | |
| 41 | ToPrintable(const void* data, size_t n, size_t max_length = DEFAULT_MAX_LENGTH) |
| 42 | : _iobuf(NULL), _str((const char*)data, n), _max_length(max_length) {} |
| 43 | |
| 44 | void Print(std::ostream& os) const; |
| 45 | |
| 46 | private: |
| 47 | const IOBuf* _iobuf; |
| 48 | StringPiece _str; |
| 49 | size_t _max_length; |
| 50 | }; |
| 51 | |
| 52 | // Keep old name for compatibility. |
| 53 | typedef ToPrintable PrintedAsBinary; |
no outgoing calls