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;
97 bool dccl::test::UserCustomIdCodec::user_id_set =
false;
100 int main(
int ,
char* [])
102 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
110 codec.load<TestMessageA>();
111 codec.info<TestMessageA>(&dccl::dlog);
116 codec.load<TestMessageA>();
117 codec.info<TestMessageA>(&dccl::dlog);
123 codec.load<TestMessageB>();
124 codec.info<TestMessageB>(&dccl::dlog);
129 codec.load<TestMessageA>();
130 codec.info<TestMessageA>(&dccl::dlog);
134 unsigned byte_size_user_specified = 1;
145 unsigned byte_size_default = 2;
146 TestMessageA a_default;
154 std::cout <<
"A1: " << a1.ShortDebugString() << std::endl;
155 assert(codec.size(a1) == byte_size_user_specified);
156 codec.encode(&bytes, a1);
157 assert(bytes.size() == byte_size_user_specified);
159 codec.decode(bytes, &a1_out);
160 std::cout <<
"A1 decoded: " << a1_out.ShortDebugString() << std::endl;
161 assert(a1_out.SerializeAsString() == a1.SerializeAsString());
167 std::cout <<
"A2: " << a2.ShortDebugString() << std::endl;
168 assert(codec.size(a2) == byte_size_user_specified);
169 codec.encode(&bytes, a2);
170 assert(bytes.size() == byte_size_user_specified);
172 codec.decode(bytes, &a2_out);
173 std::cout <<
"A2 decoded: " << a2_out.ShortDebugString() << std::endl;
174 assert(a2_out.SerializeAsString() == a2.SerializeAsString());
180 std::cout <<
"B: " << b.ShortDebugString() << std::endl;
181 assert(codec.size(b) == byte_size_user_specified);
182 codec.encode(&bytes, b);
183 assert(bytes.size() == byte_size_user_specified);
185 codec.decode(bytes, &b_out);
186 std::cout <<
"B decoded: " << b_out.ShortDebugString() << std::endl;
187 assert(b_out.SerializeAsString() == b.SerializeAsString());
194 std::cout <<
"A Default: " << a_default.ShortDebugString() << std::endl;
195 assert(codec.size(a_default) == byte_size_default);
196 codec.encode(&bytes, a_default);
197 assert(bytes.size() == byte_size_default);
198 TestMessageA a_default_out;
199 codec.decode(bytes, &a_default_out);
200 std::cout <<
"A Default decoded: " << a_default_out.ShortDebugString() << std::endl;
201 assert(a_default_out.SerializeAsString() == a_default.SerializeAsString());
205 std::cout <<
"all tests passed" << std::endl;