1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/global.h>
22
#include <drizzled/message/binary_log.h>
27
#include <google/protobuf/io/coded_stream.h>
28
#include <google/protobuf/io/zero_copy_stream_impl.h>
36
using namespace google;
38
static void print_usage_and_exit(char *prog) {
39
const char *name= strrchr(prog, '/');
44
name= "binlog_reader";
45
cerr << "Usage: " << name << " <options>\n"
46
<< " --input name Read queries from file <name> (default: 'log.bin')\n"
53
main(int argc, char *argv[])
56
static struct option options[] = {
57
{ "input", 1 /* has_arg */, NULL, 0 },
61
const char *file_name= "log.bin";
64
while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
66
print_usage_and_exit(argv[0]);
68
switch (option_index) {
77
print_usage_and_exit(argv[0]);
81
fb.open(file_name, ios::in);
84
protobuf::io::ZeroCopyInputStream* raw_input=
85
new protobuf::io::IstreamInputStream(&is);
86
protobuf::io::CodedInputStream *coded_input=
87
new protobuf::io::CodedInputStream(raw_input);
89
BinaryLog::Event event;
90
while (event.read(coded_input))
91
event.print(std::cout);