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
63bool 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);
81int 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;
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
unsigned long to_ulong() const
Returns the value of the Bitset as an unsigned long integer. Equivalent to to<unsigned long>().
The Dynamic CCL enCODer/DECoder. This is the main class you will use to load, encode and decode DCCL ...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Base class for static-typed field encoders/decoders that use a fixed number of bits on the wire regar...
Dynamic Compact Control Language namespace.
google::protobuf::uint32 uint32
an unsigned 32 bit integer
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...