24 #include "goby/acomms/acomms_helpers.h" 25 #include "goby/acomms/dccl.h" 28 using goby::acomms::operator<<;
35 void decode(
const std::string& bytes);
37 int main(
int argc,
char* argv[])
50 msg_in1.set_int32_val(1);
51 msg_in2.set_bool_val(
false);
52 msg_in3.set_string_val(
"string1");
54 std::cout <<
"Try encode..." << std::endl;
55 std::string bytes1, bytes2, bytes3;
56 codec->encode(&bytes1, msg_in1);
57 std::cout <<
"... got bytes for GobyMessage1 (hex): " << goby::util::hex_encode(bytes1)
59 codec->encode(&bytes2, msg_in2);
60 std::cout <<
"... got bytes for GobyMessage2 (hex): " << goby::util::hex_encode(bytes2)
62 codec->encode(&bytes3, msg_in3);
63 std::cout <<
"... got bytes for GobyMessage3 (hex): " << goby::util::hex_encode(bytes3)
66 std::cout <<
"Try decode..." << std::endl;
73 std::cout <<
"all tests passed" << std::endl;
76 void decode(
const std::string& bytes)
78 unsigned dccl_id = codec->id_from_encoded(bytes);
83 codec->decode(bytes, &msg_out1);
85 std::cout <<
"Got..." << msg_out1 << std::endl;
86 assert(msg_out1.SerializeAsString() == msg_in1.SerializeAsString());
91 codec->decode(bytes, &msg_out2);
93 std::cout <<
"Got..." << msg_out2 << std::endl;
94 assert(msg_out2.SerializeAsString() == msg_in2.SerializeAsString());
99 codec->decode(bytes, &msg_out3);
101 std::cout <<
"Got..." << msg_out3 << std::endl;
102 assert(msg_out3.SerializeAsString() == msg_in3.SerializeAsString());
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...