3
#include "binary_log.h"
7
#include <google/protobuf/io/coded_stream.h>
8
#include <google/protobuf/io/zero_copy_stream_impl.h>
15
using namespace google::protobuf;
16
using namespace google::protobuf::io;
18
void print_usage_and_exit(char *prog) {
20
const char *name= strrchr(prog, '/');
25
name= "binlog_reader";
26
cerr << "Usage: " << name << " <options>\n"
27
<< " --input name Read queries from file <name> (default: 'log.bin')\n"
34
print_event(BinaryLog::Event *event)
40
main(int argc, char *argv[])
44
static struct option options[] = {
45
{ "input", 1 /* has_arg */, NULL, 0 },
49
const char *file_name= "log.bin";
52
while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
54
print_usage_and_exit(argv[0]);
56
switch (option_index) {
65
print_usage_and_exit(argv[0]);
67
int fd = open(file_name, O_RDONLY);
68
ZeroCopyInputStream* raw_input = new FileInputStream(fd);
69
CodedInputStream *coded_input = new CodedInputStream(raw_input);
71
BinaryLog::Event event;
72
while (event.read(coded_input))
73
event.print(std::cout);