25#include "../../codec.h"
26#include "../../field_codec_id.h"
67 void validate()
override
75 static bool user_id_set;
85 UserCustomIdCodec::user_id = id;
86 UserCustomIdCodec::user_id_set =
true;
90 UserCustomIdCodec::user_id = 0;
91 UserCustomIdCodec::user_id_set =
false;
97bool dccl::test::UserCustomIdCodec::user_id_set =
false;
100int main(
int argc,
char* argv[])
102 bool verbose =
false;
103 for (
int i = 1; i < argc; ++i)
105 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
109 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
117 codec.load<TestMessageA>();
118 codec.info<TestMessageA>(&dccl::dlog);
123 codec.load<TestMessageA>();
124 codec.info<TestMessageA>(&dccl::dlog);
130 codec.load<TestMessageB>();
131 codec.info<TestMessageB>(&dccl::dlog);
136 codec.load<TestMessageA>();
137 codec.info<TestMessageA>(&dccl::dlog);
141 unsigned byte_size_user_specified = 1;
152 unsigned byte_size_default = 2;
153 TestMessageA a_default;
161 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A1: " << a1.ShortDebugString() << std::endl;
162 assert(codec.size(a1) == byte_size_user_specified);
163 codec.encode(&bytes, a1);
164 assert(bytes.size() == byte_size_user_specified);
166 codec.decode(bytes, &a1_out);
167 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A1 decoded: " << a1_out.ShortDebugString() << std::endl;
168 assert(a1_out.SerializeAsString() == a1.SerializeAsString());
174 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A2: " << a2.ShortDebugString() << std::endl;
175 assert(codec.size(a2) == byte_size_user_specified);
176 codec.encode(&bytes, a2);
177 assert(bytes.size() == byte_size_user_specified);
179 codec.decode(bytes, &a2_out);
180 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A2 decoded: " << a2_out.ShortDebugString() << std::endl;
181 assert(a2_out.SerializeAsString() == a2.SerializeAsString());
187 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"B: " << b.ShortDebugString() << std::endl;
188 assert(codec.size(b) == byte_size_user_specified);
189 codec.encode(&bytes, b);
190 assert(bytes.size() == byte_size_user_specified);
192 codec.decode(bytes, &b_out);
193 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"B decoded: " << b_out.ShortDebugString() << std::endl;
194 assert(b_out.SerializeAsString() == b.SerializeAsString());
201 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A Default: " << a_default.ShortDebugString() << std::endl;
202 assert(codec.size(a_default) == byte_size_default);
203 codec.encode(&bytes, a_default);
204 assert(bytes.size() == byte_size_default);
205 TestMessageA a_default_out;
206 codec.decode(bytes, &a_default_out);
207 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"A Default decoded: " << a_default_out.ShortDebugString() << std::endl;
208 assert(a_default_out.SerializeAsString() == a_default.SerializeAsString());
212 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
Provides the default 1 byte or 2 byte DCCL ID codec.
Bitset encode() override
Encode an empty field.
unsigned size() override
Calculate the size (in bits) of an empty field.
void validate() override
Validate a field. Use require() inside your overloaded validate() to assert requirements or throw Exc...
uint32 decode(Bitset *bits) override
Decode a field. If the field is empty (i.e. was encoded using the zero-argument encode()),...
unsigned min_size() override
Calculate minimum size of the field in bits.
unsigned max_size() override
Calculate maximum size of the field in bits.
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)
Dynamic Compact Control Language namespace.
google::protobuf::uint32 uint32
an unsigned 32 bit integer