1
#include <drizzled/global.h>
3
#include "binlog_encoding.h"
16
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
void encode(int argc, char *argv[], int verbose_level, bool hex_output) {
30
for (int i = 0 ; i < argc ; ++i) {
31
size_t length = strtoul(argv[i], NULL, 0);
34
throw std::invalid_argument("Length has to be > 1");
36
unsigned char buf[128];
37
unsigned char *end= length_encode(length, buf);
38
ios::fmtflags saved_flags= cout.flags();
39
if (verbose_level > 0)
40
cout << "Length " << length << ": ";
42
cout << std::hex << std::setw(2) << std::setfill('0');
43
unsigned char *ptr= buf;
47
cout << (unsigned int) *ptr;
53
cout.setf(saved_flags);
58
void decode(int argc, char *argv[], int verbose_level, bool hex_output) {
59
unsigned char buf[128];
60
for (int i = 0 ; i < argc ; ++i)
61
buf[i]= strtoul(argv[i], NULL, 0);
64
(void) length_decode(buf, &length);
66
ios::fmtflags saved_flags= cout.flags();
67
if (verbose_level > 0)
70
cout.setf(ios::hex, ios::basefield);
71
cout << length << std::endl;
72
cout.setf(saved_flags);
76
int main(int argc, char *argv[]) {
77
enum { NO_ACTION, ENCODE_ACTION, DECODE_ACTION } action= NO_ACTION;
79
static struct option long_options[] = {
80
{ "decode", 0 /* has_arg */, NULL, 'd' },
81
{ "encode", 0 /* has_arg */, NULL, 'e' },
82
{ "verbose", 0 /* has_arg */, NULL, 'v' },
83
{ "hex", 0 /* has_arg */, NULL, 'x' },
88
bool hex_output= false;
91
while ((ch= getopt_long(argc, argv, "devx", long_options, NULL)) != -1) {
95
print_usage_and_exit(argv[0]);
99
action= DECODE_ACTION;
103
action= ENCODE_ACTION;
119
encode(argc - optind, argv + optind, verbose_level, hex_output);
122
decode(argc - optind, argv + optind, verbose_level, hex_output);
125
print_usage_and_exit(argv[0]);
129
catch (std::invalid_argument& ex) {
130
cerr << ex.what() << "\n";
131
print_usage_and_exit(argv[0]);