void dispatch_student_record(msgpack::object const& obj)
    {
        student_record sr;
        obj.convert(&sr);

        evaluation eval = make_evaluation(sr);

        msgpack::sbuffer ebuf;
        msgpack::pack(ebuf, eval);

        char *obuf_cusor = outgoing_buf_;
        int32_t omsg_id = EVALUATION;
        int32_t omsglen = sizeof(omsg_id) + ebuf.size();
        size_t olen = sizeof(omsglen) + omsglen;
        ensure_outgoing_buf_capa(olen);

        memcpy(obuf_cusor, &omsglen, sizeof(omsglen));
        obuf_cusor += sizeof(omsglen);
        memcpy(obuf_cusor, &omsg_id, sizeof(omsg_id));
        obuf_cusor += sizeof(omsg_id);
        memcpy(obuf_cusor, ebuf.data(), ebuf.size());

        boost::asio::async_write(socket_,
                boost::asio::buffer(outgoing_buf_, olen),
                boost::bind(&tcp_connection::handle_write,
                    shared_from_this(),
                    boost::asio::placeholders::error,
                    boost::asio::placeholders::bytes_transferred)
                );
    }
Esempio n. 2
0
void wamp_hello_details::unmarshal(const msgpack::object& object)
{
    std::unordered_map<std::string, msgpack::object> details;
    object.convert(&details);

    auto details_itr = details.find("roles");
    if (details_itr == details.end()) {
        return;
    }

    std::unordered_map<std::string, msgpack::object> roles;
    details_itr->second.convert(roles);

    for (const auto& roles_itr : roles) {
        std::unordered_map<std::string, msgpack::object> properties;
        roles_itr.second.convert(properties);

        wamp_role_features features;
        auto properties_itr = properties.find("features");
        if (properties_itr != properties.end()) {
            std::unordered_map<std::string, bool> attributes;
            properties_itr->second.convert(attributes);
            features.set_attributes(std::move(attributes));
        }

        wamp_role_type role_type = role_type_from_string(roles_itr.first);
        wamp_role role(role_type);

        role.set_features(std::move(features));
        add_role(std::move(role));
    }
}
Esempio n. 3
0
auto unpack_message(Ret(*fptr)(Args...), const msgpack::object &obj) {
  (void)fptr;
  msgpack::type::tuple<
    typename std::decay<Args>::type...> msg;
  obj.convert(msg);
  return msg;
}
Esempio n. 4
0
void Settings::msgpack_unpack(msgpack::object o)
{
	std::string data;
	o.convert(&data);
	std::istringstream os(data, std::ios_base::binary);
	os >> m_json;
	fromJson(m_json);
}
Esempio n. 5
0
void simple_storage::unpack(msgpack::object o) {
  std::vector<msgpack::object> mems;
  o.convert(&mems);
  if (mems.size() != 2) {
    throw msgpack::type_error();
  }
  mems[0].convert(static_cast<storage*>(this));
  mems[1].convert(&mine_);
}
Esempio n. 6
0
inline std::vector<msgpack::object> wamp_publish_message::marshal() const
{
    std::vector<msgpack::object> fields;

    if (!m_arguments_kw.is_nil()) {
        if (!m_arguments.is_nil()) {
            fields = { m_type, m_request_id, m_options, m_topic, m_arguments, m_arguments_kw };
        } else {
            fields = { m_type, m_request_id, m_options, m_topic, msgpack_empty_map(), m_arguments_kw };
        }
    } else if (!m_arguments.is_nil()) {
        fields = { m_type, m_request_id, m_options, m_topic, m_arguments };
    } else {
        fields = { m_type, m_request_id, m_options, m_topic };
    }

    return fields;
}
void dispatch_evaluation(msgpack::object const& obj)
{
    evaluation eval;
    obj.convert(&eval);

    std::cout << eval.get_remark() <<
        ", result = " <<
        (eval.get_passed() ? "Passed!" : "Failure!") <<
        std::endl;
}
Esempio n. 8
0
inline std::vector<msgpack::object> wamp_event_message::marshal() const
{
    std::vector<msgpack::object> fields;

    if (!m_arguments_kw.is_nil()) {
        if (!m_arguments.is_nil()) {
            fields = { m_type, m_subscription_id, m_publication_id, m_details,
                    m_arguments, m_arguments_kw };
        } else {
            fields = { m_type, m_subscription_id, m_publication_id, m_details,
                    msgpack_empty_map(), m_arguments_kw };
        }
    } else if (!m_arguments.is_nil()) {
        fields = { m_type, m_subscription_id, m_publication_id, m_details, m_arguments };
    } else {
        fields = { m_type, m_subscription_id, m_publication_id, m_details };
    }

    return fields;
}
  void msgpack_unpack(msgpack::object o)
  {
    msgpack::type::tuple<bool, msgpack::object> tuple;
    o.convert(&tuple);

    is_double = tuple.get<0>();
    if (is_double)
      tuple.get<1>().convert(&value.f);
    else
      tuple.get<1>().convert(&value.i);
  }
Esempio n. 10
0
void compressive_storage::unpack(msgpack::object o) {
  std::vector<msgpack::object> mems;
  o.convert(&mems);
  if (mems.size() != 4) {
    throw msgpack::type_error();
  }
  mems[0].convert(static_cast<storage*>(this));
  mems[1].convert(&mine_);
  mems[2].convert(&status_);
  mems[3].convert(compressor_.get());
}
Esempio n. 11
0
void DBServer::endpoint_drop(const msgpack::object& request,
                             Packer* reply_header,
                             Packer* reply_data) {
    reply_header->pack_map(header_sizes::DROP);
    std::map<std::string, std::string> msg;
    try {
        request.convert(msg);
    } catch (msgpack::type_error& e) {
        // TODO: log error, message cannot be deserialized
        set_status(status_codes::DESERIALIZATION_ERROR,
                   "Deserialization failed.",
                   e.what(),
                   reply_header);
        return;
    }
    std::string name;
    std::string path;
    try {
        name = msg["database"];
        path = msg["path"];
    } catch (std::out_of_range& e) {
        set_status(status_codes::INVALID_REQUEST,
                   "Missing database name or path.",
                   "",
                   reply_header);
        return;
    }
    if (!databases_.count(name)) {
        set_status(status_codes::INVALID_REQUEST,
                   "Database name not found.",
                   name,
                   reply_header);
        return;
    }
    std::shared_ptr<Database> db = databases_.at(name);
    if (db->path() != path) {
        set_status(status_codes::INVALID_REQUEST,
                   "Database paths do not match.",
                   path + " != " + db->path(),
                   reply_header);
        return;
    }
    databases_.erase(name);
    db->close();
    std::remove(path.c_str());
    set_status(status_codes::OK, response_messages::OK, "", reply_header);
}
Esempio n. 12
0
void CNodeDefManager::msgpack_unpack(msgpack::object o)
{
	clear();

	std::map<int, ContentFeatures> unpacked_features;
	o.convert(&unpacked_features);

	for (std::map<int, ContentFeatures>::iterator it = unpacked_features.begin();
			it != unpacked_features.end(); ++it) {
		unsigned int i = it->first;
		ContentFeatures f = it->second;

		if(i == CONTENT_IGNORE || i == CONTENT_AIR
				|| i == CONTENT_UNKNOWN){
			infostream<<"NodeDefManager::deSerialize(): WARNING: "
				<<"not changing builtin node "<<i
				<<std::endl;
			continue;
		}
		if(f.name == ""){
			infostream<<"NodeDefManager::deSerialize(): WARNING: "
				<<"received empty name"<<std::endl;
			continue;
		}
		u16 existing_id;
		bool found = m_name_id_mapping.getId(f.name, existing_id);  // ignore aliases
		if(found && i != existing_id){
			infostream<<"NodeDefManager::deSerialize(): WARNING: "
				<<"already defined with different ID: "
				<<f.name<<std::endl;
			continue;
		}

		// All is ok, add node definition with the requested ID
		if(i >= m_content_features.size())
			m_content_features.resize((u32)(i) + 1);
		m_content_features[i] = f;
		addNameIdMapping(i, f.name);
		verbosestream<<"deserialized "<<f.name<<std::endl;
	}
}
Esempio n. 13
0
void DBServer::endpoint_query(const msgpack::object& request,
                              Packer* reply_header,
                              Packer* reply_data) {
    reply_header->pack_map(header_sizes::QUERY);
    MsgType msg;
    try {
        request.convert(msg);
    } catch (msgpack::type_error& e) {
        // TODO: log error, message cannot be deserialized
        set_status(status_codes::DESERIALIZATION_ERROR,
                   "Deserialization failed.",
                   e.what(),
                   reply_header);
        write_query_header_defaults(reply_header);
        return;
    }
    if (!databases_.count(msg.database)) {
        set_status(status_codes::DATABASE_NOT_FOUND,
                   "Database not found.",
                   msg.database,
                   reply_header);
        return;
    }
    Database& db = *databases_.at(msg.database);
    try {
        db.query(msg.operation,
                 msg.query,
                 msg.parameters,
                 reply_header,
                 reply_data);
    } catch (sqlite_error& e) {
        // TODO: log error, invalid query
        set_status(status_codes::INVALID_QUERY,
                   e.what(),
                   e.extended(),
                   reply_header);
        write_query_header_defaults(reply_header);
        return;
    }
    set_status(status_codes::OK, response_messages::OK, "", reply_header);
}
void bit_index_storage::unpack(msgpack::object o) {
  o.convert(this);
}
void recommender_mock_storage::unpack(msgpack::object o) {
  o.convert(this);
}
Esempio n. 16
0
void ucb1::unpack(msgpack::object o) {
  o.convert(&s_);
}
Esempio n. 17
0
void aggregator::unpack(msgpack::object o) {
  JUBATUS_ASSERT(p_);
  o.convert(p_.get());
}
Esempio n. 18
0
 void unpack(msgpack::object o) {
   util::concurrent::scoped_lock lk(mutex_);
   o.convert(this);
 }
Esempio n. 19
0
 std::optional<T> operator()(msgpack::object const& o) const {
     if(o.is_nil()) return std::nullopt;
     return o.as<T>();
 }
Esempio n. 20
0
void local_storage::unpack(msgpack::object o) {
  o.convert(this);
}
void sparse_matrix_storage::unpack(msgpack::object o) {
  o.convert(this);
}
Esempio n. 22
0
File: bench.cpp Progetto: emilk/bon
		//msgpack::pack(&buffer, src);
		for (auto f : src) {
			msgpack::pack(&buffer, f);
		}
	});
	
#if 0
	msgpack::unpacked msg;
	msgpack_object mobj;
	
	printf("Parsing... ");
	time([&]() {
		msgpack::unpack(&msg, buffer.data(), buffer.size());
		mobj = msg.get();
	});
	msgpack::object obj = mobj;
	
	printf("Copying... ");
	time([&]() {
		obj.convert(&dst);
		REQUIRE( dst[1] == 3.14f );
	});
#endif
}

#endif

#if 1

TEST_CASE( "BON/bench/writing", "Speed of bon_w_float")
{
Esempio n. 23
0
 void unpack(msgpack::object o) {
   o.convert(this);
 }
Esempio n. 24
0
void local_storage::unpack(msgpack::object o) {
  scoped_wlock lk(mutex_);
  o.convert(this);
}
Esempio n. 25
0
void DBServer::endpoint_connect(const msgpack::object& request,
                                Packer* reply_header,
                                Packer* reply_data) {
    reply_header->pack_map(header_sizes::CONNECT);
    std::map<std::string, std::string> msg;
    try {
        request.convert(msg);
    } catch (msgpack::type_error& e) {
        // TODO: log error, message cannot be deserialized
        set_status(status_codes::DESERIALIZATION_ERROR,
                   "Deserialization failed.",
                   e.what(),
                   reply_header);
        return;
    }
    std::string name;
    std::string path;
    try {
        name = msg["database"];
        path = msg["path"];
    } catch (std::out_of_range& e) {
        set_status(status_codes::INVALID_REQUEST,
                   "Missing database name or path.",
                   "",
                   reply_header);
        return;
    }
    // check if it's already connected to the database maybe
    if (!databases_.count(name)) {
        // no connection exists yet
        std::shared_ptr<Database> db(new Database(path));
        try {
            db->connect();
        } catch (sqlite_error& e) {
            set_status(status_codes::DATABASE_OPENING_ERROR,
                       e.what(),
                       e.extended(),
                       reply_header);
            return;
        }
        // apply passed in pragmas to newly opened database
        for (auto it = msg.begin(); it != msg.end(); ++it) {
            if (std::find(std::begin(PRAGMAS),
                          std::end(PRAGMAS),
                          it->first) != std::end(PRAGMAS))
                db->pragma(it->first, it->second);
        }
        databases_.insert(std::make_pair(name, std::move(db)));
    } else {
        // already connected to a database with that name
        std::shared_ptr<Database> db = databases_.at(name);
        // in case the database was already open, verify that the passed in path
        // matches the path of the already open database. in case it doesn't, the
        // same name was used for two different databases, which is unacceptable
        if (db->path() != path) {
            set_status(status_codes::INVALID_REQUEST,
                       "Database name already in use under different path.",
                       db->path(),
                       reply_header);
            return;
        }
    }
    set_status(status_codes::OK, response_messages::OK, "", reply_header);
}