Sha256: 22e5a3bc9b5313a0d4d70bc475411774b3820000f49b322b5a1a94f220f726e6

Contents?: true

Size: 1.1 KB

Versions: 18

Compression:

Stored size: 1.1 KB

Contents

// MessagePack for C++ example
//
// Copyright (C) 2017 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 <iostream>
#include <sstream>
#include <cassert>

// MSGPACK_USE_X3_PARSE should be defined before including msgpack.hpp
// It usually defined as a compiler option as -DMSGPACK_USE_X3_PARSE.

#include <msgpack.hpp>

int main() {
    std::stringstream ss;
    std::map<std::string, std::vector<int>> v1 {
        { "ABC", { 1, 2, 3 } },
        { "DEFG", { 4, 5 } }
    };
    std::vector<std::string> v2 {
        "HIJ", "KLM", "NOP"
    };
    msgpack::pack(ss, v1);
    msgpack::pack(ss, v2);

    std::string const& buf = ss.str();
    auto it = buf.begin();
    auto end = buf.end();
    {
        auto oh = msgpack::unpack(it, end);
        // it is updated here.
        assert(v1 == (oh.get().as<std::map<std::string, std::vector<int>>>()));
    }
    {
        auto oh = msgpack::unpack(it, end);
        assert(v2 == oh.get().as<std::vector<std::string>>());
    }
}

Version data entries

18 entries across 18 versions & 1 rubygems

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