2018-08-13 23:22:31 +00:00
|
|
|
#ifndef LLARP_MEM_HPP
|
|
|
|
#define LLARP_MEM_HPP
|
|
|
|
#include <llarp/buffer.h>
|
|
|
|
#include <llarp/mem.h>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cstdio>
|
2018-08-20 19:12:12 +00:00
|
|
|
#include <memory>
|
2018-08-13 23:22:31 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
void
|
|
|
|
Zero(void *ptr, size_t sz);
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T, size_t align = 128 >
|
|
|
|
void
|
2018-08-31 13:51:24 +00:00
|
|
|
DumpBufferHex(const T &buff)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
|
|
|
size_t idx = 0;
|
|
|
|
printf("buffer of size %zu\n", buff.sz);
|
|
|
|
while(idx < buff.sz)
|
|
|
|
{
|
|
|
|
if(buff.base + idx == buff.cur)
|
|
|
|
{
|
|
|
|
printf("%c[1;31m", 27);
|
|
|
|
}
|
2018-08-22 15:52:10 +00:00
|
|
|
printf("%.2x", buff.base[idx]);
|
|
|
|
if(buff.base + idx == buff.cur)
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2018-08-22 15:52:10 +00:00
|
|
|
printf("%c[0;0m", 27);
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
2018-08-22 15:52:10 +00:00
|
|
|
++idx;
|
|
|
|
if(idx % align == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
template < typename T, size_t align = 128 >
|
|
|
|
void
|
2018-08-31 13:51:24 +00:00
|
|
|
DumpBuffer(const T &buff)
|
2018-08-22 15:52:10 +00:00
|
|
|
{
|
|
|
|
size_t idx = 0;
|
|
|
|
printf("buffer of size %zu\n", buff.sz);
|
|
|
|
while(idx < buff.sz)
|
|
|
|
{
|
|
|
|
if(buff.base + idx == buff.cur)
|
|
|
|
{
|
|
|
|
printf("%c[1;31m", 27);
|
|
|
|
}
|
|
|
|
if(std::isprint(buff.base[idx]))
|
2018-08-13 23:22:31 +00:00
|
|
|
{
|
2018-08-22 15:52:10 +00:00
|
|
|
printf("%c", buff.base[idx]);
|
2018-08-13 23:22:31 +00:00
|
|
|
}
|
2018-08-31 13:51:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
printf(".");
|
|
|
|
}
|
2018-08-13 23:22:31 +00:00
|
|
|
if(buff.base + idx == buff.cur)
|
|
|
|
{
|
|
|
|
printf("%c[0;0m", 27);
|
|
|
|
}
|
|
|
|
++idx;
|
|
|
|
if(idx % align == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llarp
|
|
|
|
|
2018-08-20 19:12:12 +00:00
|
|
|
#if __cplusplus < 201402L
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template < typename T, typename... Args >
|
|
|
|
std::unique_ptr< T >
|
|
|
|
make_unique(Args &&... args)
|
|
|
|
{
|
|
|
|
return std::unique_ptr< T >(new T(std::forward< Args >(args)...));
|
|
|
|
}
|
|
|
|
} // namespace std
|
|
|
|
#endif
|
2018-08-13 23:22:31 +00:00
|
|
|
#endif
|