mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-22 16:40:22 +02:00

msgpack::unpacked is a typedef of the msgpack::object_handle. I recommend using msgpack::object_handle. It can be used not only holding unpacked msgpack objects but also msgpack::objects that are created by any types. Replaced unpack() APIs in test codes and examples. They used to use old APIs.
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include <msgpack.hpp>
|
|
#include <gtest/gtest.h>
|
|
|
|
template <typename T>
|
|
void check_size(size_t size) {
|
|
T v(0);
|
|
msgpack::sbuffer sbuf;
|
|
msgpack::pack(sbuf, v);
|
|
EXPECT_EQ(size, sbuf.size());
|
|
}
|
|
|
|
TEST(fixint, size)
|
|
{
|
|
check_size<msgpack::type::fix_int8>(2);
|
|
check_size<msgpack::type::fix_int16>(3);
|
|
check_size<msgpack::type::fix_int32>(5);
|
|
check_size<msgpack::type::fix_int64>(9);
|
|
|
|
check_size<msgpack::type::fix_uint8>(2);
|
|
check_size<msgpack::type::fix_uint16>(3);
|
|
check_size<msgpack::type::fix_uint32>(5);
|
|
check_size<msgpack::type::fix_uint64>(9);
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
void check_convert() {
|
|
T v1(-11);
|
|
msgpack::sbuffer sbuf;
|
|
msgpack::pack(sbuf, v1);
|
|
|
|
msgpack::object_handle oh =
|
|
msgpack::unpack(sbuf.data(), sbuf.size());
|
|
|
|
T v2;
|
|
oh.get().convert(v2);
|
|
|
|
EXPECT_EQ(v1.get(), v2.get());
|
|
|
|
EXPECT_EQ(oh.get(), msgpack::object(T(v1.get())));
|
|
}
|
|
|
|
TEST(fixint, convert)
|
|
{
|
|
check_convert<msgpack::type::fix_int8>();
|
|
check_convert<msgpack::type::fix_int16>();
|
|
check_convert<msgpack::type::fix_int32>();
|
|
check_convert<msgpack::type::fix_int64>();
|
|
|
|
check_convert<msgpack::type::fix_uint8>();
|
|
check_convert<msgpack::type::fix_uint16>();
|
|
check_convert<msgpack::type::fix_uint32>();
|
|
check_convert<msgpack::type::fix_uint64>();
|
|
}
|