26 #include "../../codec.h"
27 #include "../../field_codec.h"
41 dccl::Bitset encode()
override {
return encode(MINI_ID_OFFSET); }
45 unsigned size()
override {
return MINI_ID_SIZE; }
47 void validate()
override {}
53 MINI_ID_OFFSET = 1000000
63 bool double_cmp(
double a,
double b,
int precision)
68 int a_part = (a - a_whole) * pow(10.0, precision);
69 int b_part = (b - b_whole) * pow(10.0, precision);
71 return (a_whole == b_whole) && (a_part == b_part);
78 return dccl::Bitset(MINI_ID_SIZE, wire_value - MINI_ID_OFFSET);
81 int main(
int ,
char* [])
83 dccl::dlog.
connect(dccl::logger::ALL, &std::cerr);
87 codec.set_crypto_passphrase(
"309ldskjfla39");
89 codec.load<MiniUser>();
90 codec.info<MiniUser>(&dccl::dlog);
92 MiniUser mini_user_msg_in, mini_user_msg_out;
93 mini_user_msg_in.set_user(876);
95 codec.encode(&encoded, mini_user_msg_in);
96 codec.decode(encoded, &mini_user_msg_out);
97 assert(mini_user_msg_out.SerializeAsString() == mini_user_msg_in.SerializeAsString());
99 codec.load<MiniOWTT>();
100 codec.info<MiniOWTT>(&dccl::dlog);
102 MiniOWTT mini_owtt_in, mini_owtt_out;
103 mini_owtt_in.set_clock_mode(3);
104 mini_owtt_in.set_tod(12);
105 mini_owtt_in.set_user(13);
108 codec.encode(&encoded, mini_owtt_in);
111 codec.decode(encoded, &mini_owtt_out);
112 assert(mini_owtt_out.SerializeAsString() == mini_owtt_in.SerializeAsString());
114 codec.load<MiniAbort>();
115 codec.info<MiniAbort>(&dccl::dlog);
117 MiniAbort mini_abort_in, mini_abort_out;
118 mini_abort_in.set_user(130);
120 codec.encode(&encoded, mini_abort_in);
121 codec.decode(encoded, &mini_abort_out);
122 assert(mini_abort_out.SerializeAsString() == mini_abort_in.SerializeAsString());
125 std::cout <<
"all tests passed" << std::endl;