Sha256: f15cb337a2c0666ade4929367741d1d1023af650160ad5a189e3d1eada64278e

Contents?: true

Size: 1.35 KB

Versions: 18

Compression:

Stored size: 1.35 KB

Contents

// MessagePack for C++ example
//
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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 <msgpack.hpp>
#include <sstream>
#include <string>
#include <iostream>

class old_class {
public:
    old_class() : value("default") { }

    std::string value;

    MSGPACK_DEFINE(value);
};

class new_class {
public:
    new_class() : value("default"), flag(-1) { }

    std::string value;
    int flag;

    MSGPACK_DEFINE(value, flag);
};

int main(void)
{
    {
        old_class oc;
        new_class nc;

        std::stringstream sbuf;
        msgpack::pack(sbuf, oc);

        msgpack::object_handle oh =
            msgpack::unpack(sbuf.str().data(), sbuf.str().size());
        msgpack::object obj = oh.get();

        obj.convert(nc);

        std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
    }

    {
        new_class nc;
        old_class oc;

        std::stringstream sbuf;
        msgpack::pack(sbuf, nc);

        msgpack::object_handle oh =
            msgpack::unpack(sbuf.str().data(), sbuf.str().size());
        msgpack::object obj = oh.get();

        obj.convert(oc);

        std::cout << obj << " value=" << oc.value << std::endl;
    }
}

Version data entries

18 entries across 18 versions & 1 rubygems

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