This is Unofficial EPICS BASE Doxygen Site
epics::pvAccess::HexDump Class Reference

#include "hexDump.h"

Public Member Functions

 HexDump (const char *buf, size_t len)
 
 HexDump (const pvData::ByteBuffer &buf, size_t size=(size_t)-1, size_t offset=0u)
 
 ~HexDump ()
 
HexDumplimit (size_t n=(size_t)-1)
 safety limit on max bytes printed More...
 
HexDumpbytesPerGroup (size_t n=(size_t)-1)
 insert a space after this many bytes More...
 
HexDumpbytesPerLine (size_t n=(size_t)-1)
 start a new line after this many bytes More...
 

Friends

epicsShareFunc friend std::ostream & operator<< (std::ostream &strm, const HexDump &hex)
 

Detailed Description

Definition at line 32 of file hexDump.h.

Constructor & Destructor Documentation

epics::pvAccess::HexDump::HexDump ( const char *  buf,
size_t  len 
)

Definition at line 21 of file hexDump.cpp.

22  :buf(buf)
23  ,buflen(len)
24  ,_limit(1024u)
25  ,_groupBy(4u)
26  ,_perLine(16u)
27 {}
epics::pvAccess::HexDump::HexDump ( const pvData::ByteBuffer buf,
size_t  size = (size_t)-1,
size_t  offset = 0u 
)
explicit

Definition at line 29 of file hexDump.cpp.

31  :buf(bb.getBuffer() + bb.getPosition())
32  ,buflen(bb.getRemaining())
33  ,_limit((size_t)-1)
34  ,_groupBy(4u)
35  ,_perLine(16u)
36 {
37  if(offset > buflen)
38  offset = buflen;
39  buf += offset;
40  buflen -= offset;
41  if(buflen > size)
42  buflen = size;
43 }
epics::pvAccess::HexDump::~HexDump ( )

Definition at line 45 of file hexDump.cpp.

45 {}

Member Function Documentation

HexDump& epics::pvAccess::HexDump::bytesPerGroup ( size_t  n = (size_t)-1)
inline

insert a space after this many bytes

Definition at line 46 of file hexDump.h.

46 { _groupBy = n; return *this; }
HexDump& epics::pvAccess::HexDump::bytesPerLine ( size_t  n = (size_t)-1)
inline

start a new line after this many bytes

Definition at line 48 of file hexDump.h.

48 { _perLine = n; return *this; }
HexDump& epics::pvAccess::HexDump::limit ( size_t  n = (size_t)-1)
inline

safety limit on max bytes printed

Definition at line 44 of file hexDump.h.

44 { _limit = n; return *this; }

Friends And Related Function Documentation

epicsShareFunc friend std::ostream& operator<< ( std::ostream &  strm,
const HexDump hex 
)
friend

Definition at line 69 of file hexDump.cpp.

70 {
71  const size_t len = std::min(hex.buflen, hex._limit);
72  // find address width in hex chars
73  // find bit width, rounded up to 8 bits, divide down to bytes
74  const size_t addrwidth = bits2bytes(ilog2(len))*2u;
75  size_t nlines = len/hex._perLine;
76 
77  if(len%hex._perLine)
78  nlines++;
79 
80  for(size_t l=0; l<nlines; l++)
81  {
82  size_t start = l*hex._perLine;
83  strm<<"0x"<<std::hex<<std::setw(addrwidth)<<std::setfill('0')<<start;
84 
85  // print hex chars
86  for(size_t col=0; col<hex._perLine; col++)
87  {
88  if(col%hex._groupBy == 0) {
89  strm<<' ';
90  }
91  if(start+col < len) {
92  strm<<std::hex<<std::setw(2)<<std::setfill('0')<<unsigned(hex.buf[start+col]&0xff);
93  } else {
94  strm<<" ";
95  }
96  }
97 
98  strm<<' ';
99 
100  // printable ascii
101  for(size_t col=0; col<hex._perLine && start+col<len; col++)
102  {
103  if(col%hex._groupBy == 0) {
104  strm<<' ';
105  }
106  char val = hex.buf[start+col]&0xff;
107  if(val>=' ' && val<='~') {
108  strm<<val;
109  } else {
110  strm<<'.';
111  }
112  }
113 
114  strm<<'\n';
115  }
116 
117  return strm;
118 }
#define min(x, y)
Definition: flexdef.h:78
Definition: tool_lib.h:64

The documentation for this class was generated from the following files: