1
#include "binary_log.h"
5
#include <google/protobuf/io/coded_stream.h>
6
#include <google/protobuf/io/zero_copy_stream_impl.h>
13
using namespace google::protobuf;
14
using namespace google::protobuf::io;
16
void print_usage_and_exit(char *prog) {
18
const char *name= strrchr(prog, '/');
23
name= "binlog_reader";
24
cerr << "Usage: " << name << " <options>\n"
25
<< " --input name Read queries from file <name> (default: 'log.bin')\n"
32
print_event(BinaryLog::Event *event)
38
main(int argc, char *argv[])
42
static struct option options[] = {
43
{ "input", 1 /* has_arg */, NULL, 0 },
47
const char *file_name= "log.bin";
50
while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
52
print_usage_and_exit(argv[0]);
54
switch (option_index) {
63
print_usage_and_exit(argv[0]);
65
int fd = open(file_name, O_RDONLY);
66
ZeroCopyInputStream* raw_input = new FileInputStream(fd);
67
CodedInputStream *coded_input = new CodedInputStream(raw_input);
69
BinaryLog::Event event;
70
while (event.read(coded_input))
71
event.print(std::cout);