From 3071bb40d8773b7c24cb87a11fc8b8ea73e6284b Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 26 Oct 2016 19:00:13 +0200 Subject: COMMON: Added debug method for printing out stream contents --- common/stream.cpp | 13 +++++++++++++ common/stream.h | 9 +++++++++ 2 files changed, 22 insertions(+) (limited to 'common') diff --git a/common/stream.cpp b/common/stream.cpp index a8446a9086..08774312fd 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -247,6 +247,19 @@ uint32 SafeSeekableSubReadStream::read(void *dataPtr, uint32 dataSize) { return SeekableSubReadStream::read(dataPtr, dataSize); } +void SeekableReadStream::hexdump(int len, int bytesPerLine, int startOffset) { + uint pos_ = pos(); + uint size_ = size(); + uint toRead = MIN(len + startOffset, size_ - pos_); + byte *data = (byte *)calloc(toRead, 1); + + read(data, toRead); + Common::hexdump(data, toRead, bytesPerLine, startOffset); + + free(data); + + seek(pos_); +} #pragma mark - diff --git a/common/stream.h b/common/stream.h index e0ffc47d7f..30107720dc 100644 --- a/common/stream.h +++ b/common/stream.h @@ -514,6 +514,15 @@ public: * err() or eos() to determine whether an exception occurred. */ virtual String readLine(); + + /** + * Print a hexdump of the stream while maintaing position. The number + * of bytes per line is customizable. + * @param len the length of that data + * @param bytesPerLine number of bytes to print per line (default: 16) + * @param startOffset shift the shown offsets by the starting offset (default: 0) + */ + void hexdump(int len, int bytesPerLine = 16, int startOffset = 0); }; /** -- cgit v1.2.3