1414// you should put json.hpp in ../common
1515#include " json.hpp"
1616
17+ USING_NAMESPACE (std);
18+ USING_NAMESPACE (cpp_study);
19+
1720static
1821auto debug_print = [](auto & b)
1922{
@@ -29,39 +32,60 @@ auto debug_print = [](auto& b)
2932 std::cout << j.dump (2 ) << std::endl;
3033};
3134
32- int main ()
33- try
35+ // sales data
36+ static
37+ auto make_sales = [=](const auto & id, auto s, auto r)
38+ // -> msgpack::sbuffer
3439{
35- USING_NAMESPACE (std);
36- USING_NAMESPACE (cpp_study);
37-
38- cout << " hello cpp_study" << endl;
40+ return SalesData (id, s, r).pack ();
3941
40- // sales data
42+ #if 0
43+ SalesData book(id);
4144
42- SalesData book1 (" isbn001" );
45+ book.inc_sold(s);
46+ book.inc_revenue(r);
4347
44- book1.inc_sold (10 );
45- book1.inc_revenue (100 );
48+ debug_print(book);
4649
47- debug_print (book1);
48-
49- auto buf = book1.pack ();
50+ auto buf = book.pack();
5051 cout << buf.size() << endl;
5152
52- // zmq send
53+ //SalesData book2 {buf};
54+ //assert(book.id() == book2.id());
55+ //debug_print(book2);
56+
57+ return buf;
58+ #endif
59+ };
5360
61+ // zmq send
62+ static
63+ auto send_sales = [](const auto & addr, const auto & buf)
64+ {
5465 using zmq_ctx = ZmqContext<1 >;
5566
5667 auto sock = zmq_ctx::send_sock ();
5768
58- sock.connect (" tcp://127.0.0.1:5555 " );
69+ sock.connect (addr );
5970 assert (sock.connected ());
6071
6172 auto len = sock.send (buf.data (), buf.size ());
6273 assert (len == buf.size ());
6374
6475 cout << " send len = " << len << endl;
76+ };
77+
78+ int main ()
79+ try
80+ {
81+ cout << " hello cpp_study client" << endl;
82+
83+ // auto buf = make_sales("001", 10, 100);
84+ // send_sales("tcp://127.0.0.1:5555", buf);
85+
86+ send_sales (" tcp://127.0.0.1:5555" ,
87+ make_sales (" 001" , 10 , 100 ));
88+
6589}
6690catch (std::exception& e)
6791{
0 commit comments