~drizzle-trunk/drizzle/development

612.2.4 by Monty Taylor
Moved some defines to config.h. Stopped including config.h directly anywhere.
1
#include <drizzled/global.h>
481.1.9 by Monty Taylor
Added autoconf tests for location of cstdint and cinttypes. Use those in C++ programs now, so that we don't have to define _STDC_LIMIT_MACROS, etc by hand. Stop, in fact, defining those by hand.
2
988.1.1 by Jay Pipes
Changes libserialize to libdrizzledmessage per ML discussion. All GPB messages are now in the drizzled::message namespace.
3
#include <drizzled/message/binary_log.h>
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
4
5
#include <iostream>
520.9.1 by mordred
More solaris fixes.
6
#include <fstream>
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
7
8
#include <google/protobuf/io/coded_stream.h>
9
#include <google/protobuf/io/zero_copy_stream_impl.h>
10
11
#include <getopt.h>
12
#include <fcntl.h>
13
14
#include <sys/stat.h>
15
16
using namespace google::protobuf;
17
using namespace google::protobuf::io;
18
19
void print_usage_and_exit(char *prog) {
20
  using std::cerr;
21
  const char *name= strrchr(prog, '/');
22
23
  if (name)
24
    ++name;
25
  else
26
    name= "binlog_reader";
27
  cerr << "Usage: " << name << " <options>\n"
28
       << "    --input name   Read queries from file <name> (default: 'log.bin')\n"
29
       << std::flush;
30
  exit(1);
31
}
32
33
34
void
779.3.10 by Monty Taylor
Turned on -Wshadow.
35
print_event(BinaryLog::Event *)
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
36
{
37
}
38
39
40
int
41
main(int argc, char *argv[])
42
{
43
  using std::ios;
44
45
  static struct option options[] = {
46
    { "input",     1 /* has_arg */, NULL, 0 },
47
    { 0, 0, 0, 0 }
48
  };
49
50
  const char *file_name= "log.bin";
51
52
  int ch, option_index;
53
  while ((ch= getopt_long(argc, argv, "", options, &option_index)) != -1) {
54
    if (ch == '?')
55
      print_usage_and_exit(argv[0]);
56
57
    switch (option_index) {
58
    case 0:                                     // --input
59
      file_name= optarg;
60
      break;
61
62
    }
63
  }
64
65
  if (optind > argc)
66
    print_usage_and_exit(argv[0]);
67
520.9.1 by mordred
More solaris fixes.
68
  filebuf fb;
69
70
  fb.open(file_name, std::ios::in);
71
  istream is(&fb);
72
73
  ZeroCopyInputStream* raw_input = new IstreamInputStream(&is);
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
74
  CodedInputStream *coded_input = new CodedInputStream(raw_input);
75
76
  BinaryLog::Event event;
77
  while (event.read(coded_input))
78
    event.print(std::cout);
79
80
  delete coded_input;
81
  delete raw_input;
520.9.1 by mordred
More solaris fixes.
82
  fb.close();
324.1.1 by Mats Kindahl
Adding specification of a simple protobuf-based binary log format,
83
}