Add GWBUF pretty-printing
The gwbuf_hexdump_pretty displays the hex contents of the buffer alongside the human-readable version of it. The text version helps identify parts of the buffer that contain text which makes protocol data decoding easier.
This commit is contained in:
@ -165,7 +165,7 @@ inline bool gwbuf_is_contiguous(const GWBUF* b)
|
||||
/*< True if all bytes in the buffer have been consumed */
|
||||
inline bool gwbuf_link_empty(const GWBUF* b)
|
||||
{
|
||||
return ((char*)b->start >= (char*)b->end);
|
||||
return (char*)b->start >= (char*)b->end;
|
||||
}
|
||||
|
||||
#define GWBUF_EMPTY(b) gwbuf_link_empty(b)
|
||||
@ -422,11 +422,22 @@ extern void dprintAllBuffers(void* pdcb);
|
||||
/**
|
||||
* Debug function for dumping buffer contents to log
|
||||
*
|
||||
* @see mxs::Buffer::hexdump
|
||||
*
|
||||
* @param buffer Buffer to dump
|
||||
* @param log_level Log priority where the message is written
|
||||
*/
|
||||
void gwbuf_hexdump(GWBUF* buffer, int log_level);
|
||||
void gwbuf_hexdump(const mxs::Buffer& buffer, int log_level);
|
||||
void gwbuf_hexdump(GWBUF* buffer, int log_level = LOG_INFO);
|
||||
|
||||
/**
|
||||
* Debug function for pretty-printing buffer contents to log
|
||||
*
|
||||
* @see mxs::Buffer::hexdump_pretty
|
||||
*
|
||||
* @param buffer Buffer to dump
|
||||
* @param log_level Log priority where the message is written
|
||||
*/
|
||||
void gwbuf_hexdump_pretty(GWBUF* buffer, int log_level = LOG_INFO);
|
||||
|
||||
/**
|
||||
* Return pointer of the byte at offset from start of chained buffer
|
||||
@ -1213,6 +1224,24 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug function for dumping buffer contents to log
|
||||
*
|
||||
* Prints contents as hexadecimal. Only the first 1024 bytes are dumped to avoid filling up the log.
|
||||
*
|
||||
* @param log_level Log priority where the message is written
|
||||
*/
|
||||
void hexdump(int log_level = LOG_INFO) const;
|
||||
|
||||
/**
|
||||
* Debug function for pretty-printing buffer contents to log
|
||||
*
|
||||
* The output format is similar to `hexdump -C` and provides both hex and human-readable values.
|
||||
*
|
||||
* @param log_level Log priority where the message is written
|
||||
*/
|
||||
void hexdump_pretty(int log_level = LOG_INFO) const;
|
||||
|
||||
private:
|
||||
// To prevent @c Buffer from being created on the heap.
|
||||
void* operator new(size_t); // standard new
|
||||
|
Reference in New Issue
Block a user