DCCL v5
Loading...
Searching...
No Matches
analyze_dccl.cpp
1// Copyright 2011-2023:
2// GobySoft, LLC (2013-)
3// Massachusetts Institute of Technology (2007-2014)
4// Community contributors (see AUTHORS file)
5// File authors:
6// Toby Schneider <toby@gobysoft.org>
7//
8//
9// This file is part of the Dynamic Compact Control Language Library
10// ("DCCL").
11//
12// DCCL is free software: you can redistribute it and/or modify
13// it under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// DCCL is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
24#include <google/protobuf/descriptor.h>
25
26#include "../../codec.h"
27
28int main(int argc, char* argv[])
29{
30 std::cerr << "**** analyze_dccl is deprecated. You should consider using the newer 'dccl' tool "
31 "instead (dccl --analyze -f some_dccl.proto -I /path/to/proto) **** "
32 << std::endl;
33
34 if (argc < 2)
35 {
36 std::cerr << "usage: analyze_dccl some_dccl.proto [include_path (0-n)]" << std::endl;
37 exit(1);
38 }
39
40 dccl::dlog.connect(dccl::logger::WARN_PLUS, &std::cerr);
41
43
44 for (int i = 2; i < argc; ++i) dccl::DynamicProtobufManager::add_include_path(argv[i]);
45
46 // load_from_proto_file throws rather than returning null for a file it
47 // cannot read, so without this the tool terminates on a bad path
48 const google::protobuf::FileDescriptor* file_desc = nullptr;
49 try
50 {
52 }
53 catch (const std::exception& e)
54 {
55 std::cerr << "failed to read in: " << argv[1] << "\n\t" << e.what() << std::endl;
56 return 1;
57 }
58
60 if (file_desc)
61 {
62 std::cout << "read in: " << argv[1] << std::endl;
63 for (int i = 0, n = file_desc->message_type_count(); i < n; ++i)
64 {
65 const google::protobuf::Descriptor* desc = file_desc->message_type(i);
66
67 if (desc)
68 {
69 try
70 {
71 dccl.load(desc);
72 }
73 catch (std::exception& e)
74 {
75 std::cerr << "Not a valid DCCL message: " << desc->full_name() << "\n"
76 << e.what() << std::endl;
77 }
78 }
79 else
80 {
81 std::cerr << "No descriptor with name " << file_desc->message_type(i)->full_name()
82 << " found!" << std::endl;
83 exit(1);
84 }
85 }
86 std::cout << dccl << std::endl;
87 }
88 else
89 {
90 std::cerr << "failed to read in: " << argv[1] << std::endl;
91 return 1;
92 }
93
94 return 0;
95}
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Definition codec.h:61
static void add_include_path(const std::string &path)
Add a path for searching for import messages when loading .proto files using load_from_proto_file()
static void enable_compilation()
Enable on the fly compilation of .proto files on the local disk. Must be called before load_from_prot...
static const google::protobuf::FileDescriptor * load_from_proto_file(const std::string &protofile_absolute_path)
Load a message from a .proto file on the disk. enable_compilation() must be called first.
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Definition logger.h:213
Dynamic Compact Control Language namespace.
Definition any.h:28