1
#include <drizzled/global.h>
3
#include "binlog_encoding.h"
16
static void print_usage_and_exit(char *prog) {
17
const char *name= strrchr(prog, '/');
23
<< " " << name << " [ -vvvx ] -e <number> ...\n";
24
cerr << " " << name << " [ -vvvx ] -d <byte> ...\n";
29
static void encode(int argc, char *argv[], int verbose_level, bool hex_output)
31
for (int i = 0 ; i < argc ; ++i) {
32
size_t length = strtoul(argv[i], NULL, 0);
35
throw std::invalid_argument("Length has to be > 1");
37
unsigned char buf[128];
38
unsigned char *end= length_encode(length, buf);
39
ios::fmtflags saved_flags= cout.flags();
40
if (verbose_level > 0)
41
cout << "Length " << length << ": ";
43
cout << std::hex << std::setw(2) << std::setfill('0');
44
unsigned char *ptr= buf;
48
cout << (unsigned int) *ptr;
54
cout.setf(saved_flags);
59
static void decode(int argc, char *argv[], int verbose_level, bool hex_output)
61
unsigned char buf[128];
62
for (int i = 0 ; i < argc ; ++i)
63
buf[i]= strtoul(argv[i], NULL, 0);
66
(void) length_decode(buf, &length);
68
ios::fmtflags saved_flags= cout.flags();
69
if (verbose_level > 0)
72
cout.setf(ios::hex, ios::basefield);
73
cout << length << std::endl;
74
cout.setf(saved_flags);
78
int main(int argc, char *argv[]) {
79
enum { NO_ACTION, ENCODE_ACTION, DECODE_ACTION } action= NO_ACTION;
81
static struct option long_options[] = {
82
{ "decode", 0 /* has_arg */, NULL, 'd' },
83
{ "encode", 0 /* has_arg */, NULL, 'e' },
84
{ "verbose", 0 /* has_arg */, NULL, 'v' },
85
{ "hex", 0 /* has_arg */, NULL, 'x' },
90
bool hex_output= false;
93
while ((ch= getopt_long(argc, argv, "devx", long_options, NULL)) != -1) {
97
print_usage_and_exit(argv[0]);
101
action= DECODE_ACTION;
105
action= ENCODE_ACTION;
121
encode(argc - optind, argv + optind, verbose_level, hex_output);
124
decode(argc - optind, argv + optind, verbose_level, hex_output);
127
print_usage_and_exit(argv[0]);
131
catch (std::invalid_argument& ex) {
132
cerr << ex.what() << "\n";
133
print_usage_and_exit(argv[0]);