Sha256: fff1707968ae88d2edb4049c5e98ee38536671e659d4a4af2b2815725043c6ad

Contents?: true

Size: 1.14 KB

Versions: 18

Compression:

Stored size: 1.14 KB

Contents

// MessagePack for C++ example
//
// Copyright (C) 2015 KONDO Takatoshi
//
//    Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//    http://www.boost.org/LICENSE_1_0.txt)
//

#include <cassert>
#include <memory>
#include <iostream>

#include <msgpack.hpp>

struct my {
    my() = delete;

    // target class should be either copyable or movable (or both).
    my(my const&) = delete;
    my(my&&) = default;

    my(int a):a(a) {}
    int a;
    MSGPACK_DEFINE(a);
};

namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
namespace adaptor {

template<>
struct as<my> {
    my operator()(msgpack::object const& o) const {
        if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
        if (o.via.array.size != 1) throw msgpack::type_error();
        return my(o.via.array.ptr[0].as<int>());
    }
};

} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
} // namespace msgpack

int main() {
    my m1(42);
    msgpack::zone z;
    msgpack::object obj(m1, z);
    std::cout << obj << std::endl;
    assert(m1.a == obj.as<my>().a);
}

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
script_core-0.3.2 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.3.0 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.7 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.6 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.5 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.4 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.3 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.2 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.1 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.2.0 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.1.1 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.1.0 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.6 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.5 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.4 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.3 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.2 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp
script_core-0.0.1 ext/enterprise_script_service/msgpack/example/cpp11/non_def_con_class.cpp