24 #include "goby/acomms/dccl.h" 25 #include "goby/common/time.h" 26 #include "goby/util/as.h" 27 #include "goby/util/binary.h" 30 using goby::acomms::operator<<;
32 int main(
int argc,
char* argv[])
44 msg_in1.set_int32_val(1);
45 msg_in2.set_bool_val(
false);
46 msg_in3.set_string_val(
"string1");
47 msg_in4.set_string_val(
"string2");
49 std::list<const google::protobuf::Message*> msgs;
50 msgs.push_back(&msg_in1);
51 msgs.push_back(&msg_in2);
52 msgs.push_back(&msg_in3);
53 msgs.push_back(&msg_in4);
55 std::list<const google::protobuf::Descriptor*> descs;
56 descs.push_back(msg_in1.GetDescriptor());
57 descs.push_back(msg_in2.GetDescriptor());
58 descs.push_back(msg_in3.GetDescriptor());
59 descs.push_back(msg_in4.GetDescriptor());
61 codec->info_repeated(descs, &std::cout);
66 std::cout <<
"Message " << ++i <<
" in:\n" << p->DebugString() << std::endl;
69 codec->validate_repeated(descs);
71 std::cout <<
"Try encode..." << std::endl;
72 std::string bytes1 = codec->encode_repeated(msgs) + std::string(4,
'\0');
73 std::cout <<
"... got bytes (hex): " << goby::util::hex_encode(bytes1) << std::endl;
74 std::cout <<
"Try decode..." << std::endl;
76 std::list<boost::shared_ptr<google::protobuf::Message> > msgs_out =
77 codec->decode_repeated<boost::shared_ptr<google::protobuf::Message> >(bytes1);
79 std::list<const google::protobuf::Message*>::const_iterator in_it = msgs.begin();
81 assert(msgs.size() == msgs_out.size());
83 BOOST_FOREACH (boost::shared_ptr<google::protobuf::Message> p, msgs_out)
86 std::cout <<
"... got Message " << ++i <<
" out:\n" << p->DebugString() << std::endl;
87 assert((*in_it)->SerializeAsString() == p->SerializeAsString());
91 std::cout <<
"all tests passed" << std::endl;
void set_name(const std::string &s)
Set the name of the application that the logger is serving.
static DCCLCodec * get()
DCCLCodec is a singleton class; use this to get a pointer to the class.
common::FlexOstream glog
Access the Goby logger through this object.
void add_stream(logger::Verbosity verbosity=logger::VERBOSE, std::ostream *os=0)
Attach a stream object (e.g. std::cout, std::ofstream, ...) to the logger with desired verbosity...