Skip to content

Commit

Permalink
Someone didn't format msgpack so im reverting and using --no-verify t…
Browse files Browse the repository at this point in the history
…o commit :/
  • Loading branch information
charlielye committed May 20, 2023
1 parent aaa0f96 commit 3be0eb6
Show file tree
Hide file tree
Showing 554 changed files with 77,369 additions and 186,082 deletions.
72 changes: 41 additions & 31 deletions cpp/src/msgpack-c/example/boost/asio_send_recv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

#include <msgpack.hpp>

int main()
{
int main() {
boost::asio::io_service ios;
std::uint16_t const port = 12345;

Expand All @@ -31,34 +30,40 @@ int main()
msgpack::unpacker unp;

do_accept = [&] {
ac.async_accept(ss, [&](boost::system::error_code const& e) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
ac.async_accept(
ss,
[&]
(boost::system::error_code const& e) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
do_async_read_some = [&] {
unp.reserve_buffer(window_size);
ss.async_read_some(
boost::asio::buffer(unp.buffer(), window_size),
[&](boost::system::error_code const& e, std::size_t bytes_transferred) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
std::cout << bytes_transferred << " bytes read." << std::endl;
unp.buffer_consumed(bytes_transferred);
msgpack::object_handle oh;
while (unp.next(oh)) {
std::cout << oh.get() << std::endl;
// In order to finish the program,
// return if one complete msgpack is processed.
// In actual server, don't return here.
return;
}
do_async_read_some();
}
);
};
do_async_read_some();
}
do_async_read_some = [&] {
unp.reserve_buffer(window_size);
ss.async_read_some(boost::asio::buffer(unp.buffer(), window_size),
[&](boost::system::error_code const& e, std::size_t bytes_transferred) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
std::cout << bytes_transferred << " bytes read." << std::endl;
unp.buffer_consumed(bytes_transferred);
msgpack::object_handle oh;
while (unp.next(oh)) {
std::cout << oh.get() << std::endl;
// In order to finish the program,
// return if one complete msgpack is processed.
// In actual server, don't return here.
return;
}
do_async_read_some();
});
};
do_async_read_some();
});
);
};
do_accept();

Expand All @@ -78,7 +83,11 @@ int main()

boost::asio::ip::tcp::socket cs(ios);
boost::asio::async_connect(
cs, it, end, [&](boost::system::error_code const& e, boost::asio::ip::tcp::resolver::iterator) {
cs,
it,
end,
[&]
(boost::system::error_code const& e, boost::asio::ip::tcp::resolver::iterator) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
Expand All @@ -87,7 +96,8 @@ int main()
msgpack::sbuffer sb;
msgpack::pack(sb, std::make_tuple(42, false, "hello world", 12.3456));
write(cs, boost::asio::buffer(sb.data(), sb.size()));
});
}
);

// Start
ios.run();
Expand Down
147 changes: 81 additions & 66 deletions cpp/src/msgpack-c/example/boost/asio_send_recv_zlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@

#include <zlib.h>

void print(std::string const& buf)
{
for (std::string::const_iterator it = buf.begin(), end = buf.end(); it != end; ++it) {
std::cout << std::setw(2) << std::hex << std::setfill('0') << (static_cast<int>(*it) & 0xff) << ' ';
void print(std::string const& buf) {
for (std::string::const_iterator it = buf.begin(), end = buf.end();
it != end;
++it) {
std::cout
<< std::setw(2)
<< std::hex
<< std::setfill('0')
<< (static_cast<int>(*it) & 0xff)
<< ' ';
}
std::cout << std::dec << std::endl;
}

int main()
{
int main() {
boost::asio::io_service ios;
std::uint16_t const port = 12345;

Expand Down Expand Up @@ -62,65 +67,70 @@ int main()
msgpack::unpacker unp;

do_accept = [&] {
ac.async_accept(ss, [&](boost::system::error_code const& e) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
ac.async_accept(
ss,
[&]
(boost::system::error_code const& e) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
do_async_read_some = [&] {
ss.async_read_some(
boost::asio::buffer(buf),
[&](boost::system::error_code const& e, std::size_t bytes_transferred) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
std::cout << bytes_transferred << " bytes read." << std::endl;
print(std::string(std::string(&buf[0], buf.size())));
strm.avail_in = static_cast<uInt>(bytes_transferred);
do {
strm.next_in = reinterpret_cast<unsigned char*>(&buf[0]) + (bytes_transferred - strm.avail_in);
int zret;
unp.reserve_buffer(window_size);
strm.avail_out = static_cast<uInt>(window_size);
strm.next_out = reinterpret_cast<unsigned char*>(unp.buffer());
do {
zret = inflate(&strm, Z_NO_FLUSH);
assert(zret != Z_STREAM_ERROR);
switch (zret) {
case Z_NEED_DICT:
zret = Z_DATA_ERROR;
// fall through
case Z_DATA_ERROR:
case Z_MEM_ERROR:
inflateEnd(&strm);
std::cout << "Zlib inflate() error = " << zret << std::endl;
std::exit(-1);
}
std::size_t decompressed_size = window_size - strm.avail_out;
std::cout << decompressed_size << " bytes decompressed." << std::endl;
unp.buffer_consumed(decompressed_size);
msgpack::object_handle oh;
while (unp.next(oh)) {
std::cout << oh.get() << std::endl;
}
} while (strm.avail_out == 0);
if (zret == Z_STREAM_END) {
inflateEnd(&strm);
std::cout << "Zlib decompress finished." << std::endl;
++idx_zlib_data;
if (idx_zlib_data == num_of_zlib_data) {
std::cout << "All zlib decompress finished." << std::endl;
return;
}
zlib_init();
}
} while (strm.avail_in != 0);
do_async_read_some();
}
);
};
do_async_read_some();
}
do_async_read_some = [&] {
ss.async_read_some(boost::asio::buffer(buf),
[&](boost::system::error_code const& e, std::size_t bytes_transferred) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
}
std::cout << bytes_transferred << " bytes read." << std::endl;
print(std::string(std::string(&buf[0], buf.size())));
strm.avail_in = static_cast<uInt>(bytes_transferred);
do {
strm.next_in = reinterpret_cast<unsigned char*>(&buf[0]) +
(bytes_transferred - strm.avail_in);
int zret;
unp.reserve_buffer(window_size);
strm.avail_out = static_cast<uInt>(window_size);
strm.next_out = reinterpret_cast<unsigned char*>(unp.buffer());
do {
zret = inflate(&strm, Z_NO_FLUSH);
assert(zret != Z_STREAM_ERROR);
switch (zret) {
case Z_NEED_DICT:
zret = Z_DATA_ERROR;
// fall through
case Z_DATA_ERROR:
case Z_MEM_ERROR:
inflateEnd(&strm);
std::cout << "Zlib inflate() error = " << zret << std::endl;
std::exit(-1);
}
std::size_t decompressed_size = window_size - strm.avail_out;
std::cout << decompressed_size << " bytes decompressed." << std::endl;
unp.buffer_consumed(decompressed_size);
msgpack::object_handle oh;
while (unp.next(oh)) {
std::cout << oh.get() << std::endl;
}
} while (strm.avail_out == 0);
if (zret == Z_STREAM_END) {
inflateEnd(&strm);
std::cout << "Zlib decompress finished." << std::endl;
++idx_zlib_data;
if (idx_zlib_data == num_of_zlib_data) {
std::cout << "All zlib decompress finished." << std::endl;
return;
}
zlib_init();
}
} while (strm.avail_in != 0);
do_async_read_some();
});
};
do_async_read_some();
});
);
};
do_accept();

Expand All @@ -141,7 +151,11 @@ int main()

boost::asio::ip::tcp::socket cs(ios);
boost::asio::async_connect(
cs, it, end, [&](boost::system::error_code const& e, boost::asio::ip::tcp::resolver::iterator) {
cs,
it,
end,
[&]
(boost::system::error_code const& e, boost::asio::ip::tcp::resolver::iterator) {
if (e) {
std::cout << __LINE__ << ":" << e.message() << std::endl;
return;
Expand All @@ -154,7 +168,8 @@ int main()
print(std::string(zb.data(), zb.size()));
write(cs, boost::asio::buffer(zb.data(), zb.size()));
}
});
}
);

// Start
ios.run();
Expand Down
35 changes: 22 additions & 13 deletions cpp/src/msgpack-c/example/boost/msgpack_variant_capitalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,47 @@ struct user {
MSGPACK_DEFINE(name, age, address);
};

struct proc : boost::static_visitor<void> {
void operator()(std::string& v) const
{
struct proc:boost::static_visitor<void> {
void operator()(std::string& v) const {
std::cout << " match std::string& v" << std::endl;
std::cout << " v: " << v << std::endl;
std::cout << " capitalize" << std::endl;
for (std::string::iterator it = v.begin(), end = v.end(); it != end; ++it) {
for (std::string::iterator it = v.begin(), end = v.end();
it != end;
++it) {
*it = std::toupper(*it);
}
}
void operator()(std::vector<msgpack::type::variant>& v) const
{
void operator()(std::vector<msgpack::type::variant>& v) const {
std::cout << "match vector (msgpack::type::ARRAY)" << std::endl;
std::vector<msgpack::type::variant>::iterator it = v.begin();
std::vector<msgpack::type::variant>::const_iterator end = v.end();
for (; it != end; ++it) {
boost::apply_visitor(*this, *it);
}
}
template <typename T> void operator()(T const&) const { std::cout << " match others" << std::endl; }
template <typename T>
void operator()(T const&) const {
std::cout << " match others" << std::endl;
}
};

void print(std::string const& buf)
{
for (std::string::const_iterator it = buf.begin(), end = buf.end(); it != end; ++it) {
std::cout << std::setw(2) << std::hex << std::setfill('0') << (static_cast<int>(*it) & 0xff) << ' ';
void print(std::string const& buf) {
for (std::string::const_iterator it = buf.begin(), end = buf.end();
it != end;
++it) {
std::cout
<< std::setw(2)
<< std::hex
<< std::setfill('0')
<< (static_cast<int>(*it) & 0xff)
<< ' ';
}
std::cout << std::dec << std::endl;
}

int main()
{

int main() {
std::stringstream ss1;
user u;
u.name = "Takatoshi Kondo";
Expand Down
Loading

0 comments on commit 3be0eb6

Please sign in to comment.