Sha256: db8b1bdda467e1fa6e25a0242d2949ae34071502170fff0e35d8073266a92643

Contents?: true

Size: 1.8 KB

Versions: 18

Compression:

Stored size: 1.8 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 <msgpack.hpp>
#include <string>
#include <iostream>
#include <sstream>

// This example uses obsolete APIs
// See protocol_new.cpp
namespace myprotocol {
    struct Get {
        Get() {}
        Get(uint32_t f, const std::string& k) : flags(f), key(k) {}
        uint32_t flags;
        std::string key;
        MSGPACK_DEFINE(flags, key);
    };

    typedef std::vector<Get> MultiGet;
}


int main(void)
{
    // send Get request
    std::stringstream stream;
    {
        myprotocol::Get req;
        req.flags = 0;
        req.key   = "key0";
        msgpack::pack(stream, req);
    }

    stream.seekg(0);

    // receive Get request
    {
        std::string buffer(stream.str());

        msgpack::object_handle oh =
            msgpack::unpack(buffer.data(), buffer.size());
        msgpack::object o = oh.get();

        myprotocol::Get req;
        o.convert(req);
        std::cout << "received: " << o << std::endl;
    }


    stream.str("");


    // send MultiGet request
    {
        myprotocol::MultiGet req;
        req.push_back( myprotocol::Get(1, "key1") );
        req.push_back( myprotocol::Get(2, "key2") );
        req.push_back( myprotocol::Get(3, "key3") );
        msgpack::pack(stream, req);
    }

    stream.seekg(0);

    // receive MultiGet request
    {
        std::string buffer(stream.str());

        msgpack::object_handle oh =
            msgpack::unpack(buffer.data(), buffer.size());
        msgpack::object o = oh.get();


        myprotocol::MultiGet req;
        o.convert(req);
        std::cout << "received: " << o << 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/protocol_new.cpp
script_core-0.3.0 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.7 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.6 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.5 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.4 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.3 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.2 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.1 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.2.0 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.1.1 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.1.0 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.6 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.5 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.4 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.3 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.2 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp
script_core-0.0.1 ext/enterprise_script_service/msgpack/example/cpp03/protocol_new.cpp