2018-01-26 14:17:51 +00:00
|
|
|
#ifndef LLARP_MEM_HPP
|
|
|
|
#define LLARP_MEM_HPP
|
2018-05-25 17:52:10 +00:00
|
|
|
#include <llarp/buffer.h>
|
2018-01-29 14:27:24 +00:00
|
|
|
#include <llarp/mem.h>
|
2018-07-19 04:58:39 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <cstdio>
|
2018-05-23 20:37:43 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
void
|
|
|
|
Zero(void *ptr, size_t sz);
|
2018-01-26 14:17:51 +00:00
|
|
|
|
2018-05-23 20:37:43 +00:00
|
|
|
template < typename T >
|
|
|
|
void
|
|
|
|
dumphex(const uint8_t *t)
|
|
|
|
{
|
|
|
|
size_t idx = 0;
|
|
|
|
while(idx < sizeof(T))
|
|
|
|
{
|
|
|
|
printf("%.2x ", t[idx++]);
|
|
|
|
if(idx % 8 == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 20:58:16 +00:00
|
|
|
template < typename T, size_t align = 8 >
|
2018-05-25 17:52:10 +00:00
|
|
|
void
|
2018-07-18 20:58:16 +00:00
|
|
|
DumpBuffer(const T &buff)
|
2018-05-25 17:52:10 +00:00
|
|
|
{
|
|
|
|
size_t idx = 0;
|
2018-08-08 16:56:45 +00:00
|
|
|
printf("buffer of size %zu\n", buff.sz);
|
2018-05-25 17:52:10 +00:00
|
|
|
while(idx < buff.sz)
|
|
|
|
{
|
2018-07-18 20:58:16 +00:00
|
|
|
if(buff.base + idx == buff.cur)
|
|
|
|
{
|
|
|
|
printf("%c[1;31m", 27);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-19 04:58:39 +00:00
|
|
|
printf("%c[0;0m", 27);
|
2018-07-18 20:58:16 +00:00
|
|
|
}
|
2018-07-19 04:58:39 +00:00
|
|
|
if(std::isprint(buff.base[idx]))
|
2018-07-18 20:58:16 +00:00
|
|
|
{
|
|
|
|
printf("%c", buff.base[idx]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("X");
|
|
|
|
}
|
|
|
|
++idx;
|
|
|
|
if(idx % align == 0)
|
2018-05-25 17:52:10 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
2018-07-20 04:50:28 +00:00
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
2018-05-25 17:52:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
} // namespace llarp
|
2018-05-18 12:39:17 +00:00
|
|
|
|
2018-01-26 14:17:51 +00:00
|
|
|
#endif
|