Drizzled Public API Documentation

table_raw_reader.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <fcntl.h>
00025 #include <string.h>
00026 #include <stdio.h>
00027 #include <errno.h>
00028 #include <unistd.h>
00029 
00030 #include <iostream>
00031 #include <string>
00032 #include <drizzled/message/table.pb.h>
00033 #include <google/protobuf/io/zero_copy_stream.h>
00034 #include <google/protobuf/io/zero_copy_stream_impl.h>
00035 #include <google/protobuf/text_format.h>
00036 
00037 using namespace std;
00038 using namespace drizzled;
00039 using namespace google;
00040 
00041 
00042 static void print_table(const message::Table &table)
00043 {
00044   string proto_as_text("");
00045 
00046   protobuf::TextFormat::PrintToString(table, &proto_as_text);
00047 
00048   cout << proto_as_text;
00049 }
00050 
00051 int main(int argc, char* argv[])
00052 {
00053   GOOGLE_PROTOBUF_VERIFY_VERSION;
00054 
00055   if (argc != 2) {
00056     fprintf(stderr, "Usage: %s SCHEMA\n", argv[0]);
00057     return -1;
00058   }
00059 
00060   message::Table table;
00061 
00062   {
00063     int fd= open(argv[1], O_RDONLY);
00064 
00065     if (fd == -1)
00066     {
00067       perror("Failed to open table definition file");
00068       return -1;
00069     }
00070 
00071     protobuf::io::ZeroCopyInputStream* input=
00072       new protobuf::io::FileInputStream(fd);
00073 
00074     if (!table.ParseFromZeroCopyStream(input))
00075     {
00076       fprintf(stderr, "Failed to parse table.");
00077       close(fd);
00078       return -1;
00079     }
00080 
00081     close(fd);
00082   }
00083 
00084   print_table(table);
00085 
00086   return 0;
00087 }