Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP)Support latest MessagePack #367

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jubatus/core/anomaly/lof_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class lof_storage {
packer.pack(*this);
}
void unpack(msgpack::object o) {
o.convert(this);
o.convert(*this);
}

MSGPACK_DEFINE(lof_table_, lof_table_diff_,
Expand Down
5 changes: 1 addition & 4 deletions jubatus/core/bandit/bandit_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
#define JUBATUS_CORE_BANDIT_BANDIT_BASE_HPP_

#include <string>
#include <msgpack.hpp>

#include "arm_info.hpp"

namespace msgpack {
template <typename T>
class packer;
} // namespace msgpack
namespace jubatus {
namespace core {
namespace framework {
Expand Down
4 changes: 2 additions & 2 deletions jubatus/core/bandit/epsilon_greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

#include "epsilon_greedy.hpp"

#include <string>
#include <vector>
#include <msgpack/pack_decl.hpp>
#include "../common/exception.hpp"
#include "../framework/packer.hpp"
#include "../common/version.hpp"
Expand Down Expand Up @@ -89,7 +89,7 @@ void epsilon_greedy::pack(framework::packer& pk) const {
pk.pack(s_);
}
void epsilon_greedy::unpack(msgpack::object o) {
o.convert(&s_);
o.convert(s_);
}

void epsilon_greedy::get_diff(diff_t& diff) const {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/bandit/exp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void exp3::pack(framework::packer& pk) const {
pk.pack(s_);
}
void exp3::unpack(msgpack::object o) {
o.convert(&s_);
o.convert(s_);
}

void exp3::get_diff(diff_t& diff) const {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/bandit/softmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void softmax::pack(framework::packer& pk) const {
pk.pack(s_);
}
void softmax::unpack(msgpack::object o) {
o.convert(&s_);
o.convert(s_);
}

void softmax::get_diff(diff_t& diff) const {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/bandit/ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void ts::pack(framework::packer& pk) const {
pk.pack(s_);
}
void ts::unpack(msgpack::object o) {
o.convert(&s_);
o.convert(s_);
}

void ts::get_diff(diff_t& diff) const {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/bandit/ucb1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void ucb1::pack(framework::packer& pk) const {
pk.pack(s_);
}
void ucb1::unpack(msgpack::object o) {
o.convert(&s_);
o.convert(s_);
}

void ucb1::get_diff(diff_t& diff) const {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/burst/aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void aggregator::pack(framework::packer& packer) const {

void aggregator::unpack(msgpack::object o) {
JUBATUS_ASSERT(p_);
o.convert(p_.get());
o.convert(*p_);
}

} // namespace burst
Expand Down
10 changes: 5 additions & 5 deletions jubatus/core/burst/burst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct burst::diff_t::impl_ {
}

explicit impl_(msgpack::object o) : data() {
o.convert(this);
o.convert(*this);
}

MSGPACK_DEFINE(data);
Expand Down Expand Up @@ -467,7 +467,7 @@ class burst::impl_ : jubatus::util::lang::noncopyable {
throw msgpack::type_error();
}

o.via.array.ptr[0].convert(&unpacked_options);
o.via.array.ptr[0].convert(unpacked_options);

{
const msgpack::object& m = o.via.array.ptr[1];
Expand All @@ -477,10 +477,10 @@ class burst::impl_ : jubatus::util::lang::noncopyable {
size_t n = m.via.map.size;
for (size_t i = 0; i < n; ++i) {
string keyword;
m.via.map.ptr[i].key.convert(&keyword);
m.via.map.ptr[i].key.convert(keyword);

std::pair<keyword_params, msgpack::object> val;
m.via.map.ptr[i].val.convert(&val);
m.via.map.ptr[i].val.convert(val);
storage_ s(unpacked_options, val.first);
s.get_storage()->unpack(val.second);

Expand All @@ -496,7 +496,7 @@ class burst::impl_ : jubatus::util::lang::noncopyable {
size_t n = m.via.map.size;
for (size_t i = 0; i < n; ++i) {
string keyword;
m.via.map.ptr[i].key.convert(&keyword);
m.via.map.ptr[i].key.convert(keyword);

storages_t::const_iterator iter = unpacked_storages.find(keyword);
if (iter == unpacked_storages.end()) {
Expand Down
6 changes: 3 additions & 3 deletions jubatus/core/burst/burst_result_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ TEST(burst_result, pack_and_unpack) {

burst_result b;
{
msgpack::unpacked unpacked;
msgpack::unpack(&unpacked, buf.data(), buf.size());
unpacked.get().convert(&b);
msgpack::zone z;
msgpack::object unpacked = msgpack::unpack(z, buf.data(), buf.size());
unpacked.convert(b);
}

ASSERT_TRUE(burst_result_equals_to(a, b));
Expand Down
5 changes: 3 additions & 2 deletions jubatus/core/burst/burst_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ inline void copy_by_pack_and_unpack(const burst& src, burst& dst) {
src.pack(packer);

msgpack::unpacked unpacked;
msgpack::unpack(&unpacked, buf.data(), buf.size());
dst.unpack(unpacked.get());
msgpack::zone z;
msgpack::object o = msgpack::unpack(z, buf.data(), buf.size());
dst.unpack(o);
}

template<class F>
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/burst/result_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void result_storage::pack(framework::packer& packer) const {

void result_storage::unpack(msgpack::object o) {
JUBATUS_ASSERT(p_);
o.convert(p_.get());
o.convert(*p_);
}

} // namespace burst
Expand Down
6 changes: 3 additions & 3 deletions jubatus/core/clustering/compressive_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ void compressive_storage::pack_impl_(framework::packer& packer) const {

void compressive_storage::unpack_impl_(msgpack::object o) {
std::vector<msgpack::object> mems;
o.convert(&mems);
o.convert(mems);
if (mems.size() != 3) {
throw msgpack::type_error();
}
storage::unpack_impl_(mems[0]);
mems[1].convert(&mine_);
mems[2].convert(&status_);
mems[1].convert(mine_);
mems[2].convert(status_);
}

void compressive_storage::clear_impl_() {
Expand Down
4 changes: 2 additions & 2 deletions jubatus/core/clustering/simple_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ void simple_storage::pack_impl_(framework::packer& packer) const {

void simple_storage::unpack_impl_(msgpack::object o) {
std::vector<msgpack::object> mems;
o.convert(&mems);
o.convert(mems);
if (mems.size() != 2) {
throw msgpack::type_error();
}
storage::unpack_impl_(mems[0]);
mems[1].convert(&mine_);
mems[1].convert(mine_);
}

void simple_storage::clear_impl_() {
Expand Down
2 changes: 1 addition & 1 deletion jubatus/core/clustering/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void storage::pack_impl_(framework::packer& packer) const {
packer.pack(*this);
}
void storage::unpack_impl_(msgpack::object o) {
o.convert(this);
o.convert(*this);
}
void storage::clear_impl_() {
common_.clear();
Expand Down
6 changes: 3 additions & 3 deletions jubatus/core/clustering/storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ TEST_P(storage_test, pack_unpack) {
conf);
ASSERT_TRUE(s2 != NULL);
{
msgpack::unpacked unpacked;
msgpack::unpack(&unpacked, buf.data(), buf.size());
msgpack::zone z;
msgpack::object o = msgpack::unpack(z, buf.data(), buf.size());
// msgpack::unpack(&unpacked, buf.data(), buf.size());
s2->unpack(unpacked.get());
s2->unpack(o);
}
EXPECT_EQ(s->get_revision(), s2->get_revision());

Expand Down
4 changes: 2 additions & 2 deletions jubatus/core/common/assoc_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class assoc_vector {
}
std::vector<std::pair<K, V> > data(o.via.map.size);
for (std::size_t i = 0; i < data.size(); ++i) {
o.via.map.ptr[i].key.convert(&data[i].first);
o.via.map.ptr[i].val.convert(&data[i].second);
o.via.map.ptr[i].key.convert(data[i].first);
o.via.map.ptr[i].val.convert(data[i].second);
}
data.swap(data_);
}
Expand Down
14 changes: 6 additions & 8 deletions jubatus/core/common/assoc_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ TEST(assoc_vector, pack) {
msgpack::sbuffer buf;
msgpack::pack(buf, v);

msgpack::unpacked unpacked;
msgpack::unpack(&unpacked, buf.data(), buf.size());
msgpack::object obj = unpacked.get();
msgpack::zone z;
msgpack::object obj = msgpack::unpack(z, buf.data(), buf.size());

std::map<std::string, int> m;
m["saitama"] = 1;
obj.convert(&m);
obj.convert(m);

ASSERT_EQ(1u, m.size());
ASSERT_EQ(1u, m.count("saitama"));
Expand All @@ -100,12 +99,11 @@ TEST(assoc_vector, unpack) {
msgpack::sbuffer buf;
msgpack::pack(buf, m);

msgpack::unpacked unpacked;
msgpack::unpack(&unpacked, buf.data(), buf.size());
msgpack::object obj = unpacked.get();
msgpack::zone z;
msgpack::object obj = msgpack::unpack(z, buf.data(), buf.size());

assoc_vector<std::string, int> v;
obj.convert(&v);
obj.convert(v);

ASSERT_EQ(1u, v.size());
ASSERT_EQ(1u, v.count("saitama"));
Expand Down
22 changes: 11 additions & 11 deletions jubatus/core/common/byte_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,39 +105,39 @@ namespace msgpack {
inline jubatus::core::common::byte_buffer& operator>>(
object o,
jubatus::core::common::byte_buffer& b) {
if (o.type != type::RAW) {
if (o.type != type::BIN) {
throw type_error();
}

b.assign(o.via.raw.ptr, o.via.raw.size);
b.assign(o.via.bin.ptr, o.via.bin.size);
return b;
}

template<typename Stream>
inline packer<Stream>& operator<<(
packer<Stream>& o,
const jubatus::core::common::byte_buffer& b) {
o.pack_raw(b.size());
o.pack_raw_body(b.ptr(), b.size());
o.pack_bin(b.size());
o.pack_bin_body(b.ptr(), b.size());
return o;
}

inline void operator<<(
object::with_zone& o,
const jubatus::core::common::byte_buffer& b) {
o.type = type::RAW;
char* ptr = static_cast<char*>(o.zone->malloc(b.size()));
o.via.raw.ptr = ptr;
o.via.raw.size = static_cast<uint32_t>(b.size());
o.type = type::BIN;
char* ptr = static_cast<char*>(o.zone.allocate_no_align(b.size()));
o.via.bin.ptr = ptr;
o.via.bin.size = static_cast<uint32_t>(b.size());
std::memcpy(ptr, b.ptr(), b.size());
}

inline void operator<<(
object& o,
const jubatus::core::common::byte_buffer& b) {
o.type = type::RAW;
o.via.raw.ptr = b.ptr();
o.via.raw.size = static_cast<uint32_t>(b.size());
o.type = type::BIN;
o.via.bin.ptr = b.ptr();
o.via.bin.size = static_cast<uint32_t>(b.size());
}

} // namespace msgpack
Expand Down
Loading