~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/master_list_reader.cc

  • Committer: Monty Taylor
  • Date: 2008-10-13 09:29:43 UTC
  • mfrom: (509 drizzle)
  • mto: (509.1.4 codestyle)
  • mto: This revision was merged to the branch mainline in revision 511.
  • Revision ID: monty@inaugust.com-20081013092943-rwvx4a6d85b5l2dh
MergedĀ inĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
#include <fstream>
 
3
#include <string>
 
4
#include "master_list.pb.h"
 
5
using namespace std;
 
6
 
 
7
/* 
 
8
  Example reader application for master.info data.
 
9
*/
 
10
 
 
11
void printRecord(const drizzle::MasterList *list) 
 
12
{
 
13
  uint32_t x;
 
14
 
 
15
  for (x= 0; x < list->record_size(); x++) 
 
16
  {
 
17
    const drizzle::MasterList_Record record= list->record(x);
 
18
 
 
19
    cout << "HOSTNAME " << record.hostname() << endl;
 
20
    if (record.has_username())
 
21
      cout << "USERNAME " << record.username() << endl;
 
22
    if (record.has_password())
 
23
      cout << "PASSWORD " << record.password() << endl;
 
24
    if (record.has_port())
 
25
      cout << "PORT " << record.port() << endl;
 
26
    if (record.has_connect_retry())
 
27
      cout << "CONNECT RETRY " << record.connect_retry() << endl;
 
28
    if (record.has_log_name())
 
29
      cout << "LOG NAME " << record.log_name() << endl;
 
30
    if (record.has_log_position())
 
31
      cout << "LOG POSITION " << record.log_position() << endl;
 
32
    cout << endl;
 
33
  }
 
34
}
 
35
 
 
36
int main(int argc, char* argv[]) 
 
37
{
 
38
  GOOGLE_PROTOBUF_VERIFY_VERSION;
 
39
 
 
40
  if (argc != 2) 
 
41
  {
 
42
    cerr << "Usage:  " << argv[0] << " master.info " << endl;
 
43
    return -1;
 
44
  }
 
45
 
 
46
  drizzle::MasterList list;
 
47
 
 
48
  {
 
49
    // Read the existing master.info file
 
50
    fstream input(argv[1], ios::in | ios::binary);
 
51
    if (!list.ParseFromIstream(&input)) 
 
52
    {
 
53
      cerr << "Failed to parse master.info." << endl;
 
54
      return -1;
 
55
    }
 
56
  }
 
57
 
 
58
  printRecord(&list);
 
59
 
 
60
  return 0;
 
61
}