29#include "../../codec.h"
30#include "../../codecs3/field_codec_default.h"
31#include "../../codecs3/field_codec_default_message.h"
33#include "../../binary.h"
37template <
typename Msg>
void check(
double val,
bool should_pass);
40TestMsgGroup msg_group_in;
48 double max()
override {
return 100; }
49 double min()
override {
return -100; }
50 double precision()
override {
return 1; }
51 double resolution()
override {
return 0.1; }
52 void validate()
override {}
57int main(
int argc,
char* argv[])
60 for (
int i = 1; i < argc; ++i)
62 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
66 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
73 check<TestMsg>(50,
true);
74 check<TestMsg>(-50,
false);
75 check<TestMsgGroup>(50,
true);
76 check<TestMsgGroup>(-50,
true);
77 check<TestMsgV4>(50,
true);
79 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
82template <
typename Msg>
void check(
double val,
bool should_pass)
86 msg_in.set_d(++i + 0.1);
87 msg_in.add_d_repeat(12.1);
88 msg_in.add_d_repeat(12.2);
89 msg_in.add_d_repeat(12.3);
91 msg_in.mutable_msg()->set_val(val);
92 msg_in.mutable_msg()->mutable_msg()->set_val(val);
93 if (dccl::dlog.is(dccl::logger::INFO))
95 codec.info(msg_in.GetDescriptor(), &dccl::dlog);
97 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Message in:\n" << msg_in.DebugString() << std::endl;
99 codec.load(msg_in.GetDescriptor());
101 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try encode..." << std::endl;
103 codec.encode(&bytes, msg_in);
104 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got bytes (hex): " <<
dccl::hex_encode(bytes) << std::endl;
106 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"Try decode..." << std::endl;
109 codec.decode(bytes, &msg_out);
111 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"... got Message out:\n" << msg_out.DebugString() << std::endl;
114 assert(msg_in.SerializeAsString() == msg_out.SerializeAsString());
116 assert(msg_in.SerializeAsString() != msg_out.SerializeAsString());
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Provides a basic bounded arbitrary length numeric (double, float, uint32, uint64, int32,...
Provides the default codec for encoding a base Google Protobuf message or an embedded message by call...
Dynamic Compact Control Language namespace.
void hex_encode(CharIterator begin, CharIterator end, std::string *out, bool upper_case=false)
Encodes a (little-endian) hexadecimal string from a byte string. Index 0 of begin is written to index...