-
Notifications
You must be signed in to change notification settings - Fork 38
/
common.cpp
46 lines (39 loc) · 1.24 KB
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "common.h"
#define MAXSTR 1024
//-----------------------------------------------------------------------------
void append_v(bytevec_t &out, const void *v, size_t len)
{
const uint8_t *begin = (const uint8_t *)v;
const uint8_t *end = begin + len;
out.insert(out.end(), begin, end);
}
//-----------------------------------------------------------------------------
void append_d(bytevec_t &out, uint32_t num)
{
append_v(out, &num, sizeof(num));
}
//-----------------------------------------------------------------------------
void append_q(bytevec_t &out, uint64_t num)
{
append_v(out, &num, sizeof(num));
}
//-----------------------------------------------------------------------------
void append_b(bytevec_t &out, const bytevec_t &bv)
{
append_v(out, bv.data(), bv.size());
}
//-----------------------------------------------------------------------------
void vsprnt(string_t *out, const char *format, va_list va)
{
char buf[MAXSTR];
if ( out != NULL && vsnprintf(buf, sizeof(buf), format, va) > 0 )
*out = buf;
}
//-----------------------------------------------------------------------------
void sprnt(string_t *out, const char *format, ...)
{
va_list va;
va_start(va, format);
vsprnt(out, format, va);
va_end(va);
}