<commit_before>/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
 * Implementation for OpflexPEHandler
 *
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

/* This must be included before anything else */
#if HAVE_CONFIG_H
#  include <config.h>
#endif


#include <string>
#include <vector>
#include <utility>

#include <rapidjson/document.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/address_v4.hpp>

#include "opflex/engine/Processor.h"
#include "opflex/engine/internal/OpflexPool.h"
#include "opflex/engine/internal/OpflexConnection.h"
#include "opflex/engine/internal/OpflexPEHandler.h"
#include "opflex/logging/internal/logging.hpp"
#include "opflex/engine/internal/MOSerializer.h"
#include "opflex/engine/internal/OpflexMessage.h"

namespace opflex {
namespace engine {
namespace internal {

using std::vector;
using std::string;
using std::pair;
using boost::optional;
using modb::class_id_t;
using modb::reference_t;
using modb::URI;
using internal::MOSerializer;
using modb::mointernal::StoreClient;
using rapidjson::Value;
using rapidjson::Writer;
using ofcore::OFConstants;
using boost::asio::ip::address_v4;

typedef opflex::ofcore::OFConstants::OpflexElementMode AgentMode;
typedef opflex::ofcore::OFConstants::OpflexTransportModeState AgentTransportState;

class SendIdentityReq : public OpflexMessage {
public:
    SendIdentityReq(const string& name_,
                    const string& domain_,
                    const optional<string>& location_,
                    const uint8_t roles_,
                    const string& mac_)
        : OpflexMessage("send_identity", REQUEST),
          name(name_), domain(domain_), location(location_), roles(roles_),
          mac(mac_) {}

    virtual void serializePayload(yajr::rpc::SendHandler& writer) {
        (*this)(writer);
    }

    virtual void serializePayload(MessageWriter& writer) {
        (*this)(writer);
    }

    virtual SendIdentityReq* clone() {
        return new SendIdentityReq(*this);
    }

    template <typename T>
    bool operator()(Writer<T> & writer) {
        writer.StartArray();
        writer.StartObject();
        writer.String("proto_version");
        writer.String("1.0");
        writer.String("name");
        writer.String(name.c_str());
        writer.String("domain");
        writer.String(domain.c_str());
        if (location) {
            writer.String("my_location");
            writer.String(location.get().c_str());
        }
        writer.String("my_role");
        writer.StartArray();
        if (roles & OFConstants::POLICY_ELEMENT)
            writer.String("policy_element");
        if (roles & OFConstants::POLICY_REPOSITORY)
            writer.String("policy_repository");
        if (roles & OFConstants::ENDPOINT_REGISTRY)
            writer.String("endpoint_registry");
        if (roles & OFConstants::OBSERVER)
            writer.String("observer");
        writer.EndArray();
        writer.EndObject();
        if (!mac.empty() &&
            (roles & OFConstants::POLICY_ELEMENT)) {
            writer.StartObject();
            writer.String("data");
            writer.StartArray();
            writer.StartObject();
            writer.String("mac");
            writer.String(mac.c_str());
            writer.EndObject();
            writer.EndArray();<commit_msg>Remove array in identity request data<commit_after>/* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
/*
 * Implementation for OpflexPEHandler
 *
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

/* This must be included before anything else */
#if HAVE_CONFIG_H
#  include <config.h>
#endif


#include <string>
#include <vector>
#include <utility>

#include <rapidjson/document.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ip/address_v4.hpp>

#include "opflex/engine/Processor.h"
#include "opflex/engine/internal/OpflexPool.h"
#include "opflex/engine/internal/OpflexConnection.h"
#include "opflex/engine/internal/OpflexPEHandler.h"
#include "opflex/logging/internal/logging.hpp"
#include "opflex/engine/internal/MOSerializer.h"
#include "opflex/engine/internal/OpflexMessage.h"

namespace opflex {
namespace engine {
namespace internal {

using std::vector;
using std::string;
using std::pair;
using boost::optional;
using modb::class_id_t;
using modb::reference_t;
using modb::URI;
using internal::MOSerializer;
using modb::mointernal::StoreClient;
using rapidjson::Value;
using rapidjson::Writer;
using ofcore::OFConstants;
using boost::asio::ip::address_v4;

typedef opflex::ofcore::OFConstants::OpflexElementMode AgentMode;
typedef opflex::ofcore::OFConstants::OpflexTransportModeState AgentTransportState;

class SendIdentityReq : public OpflexMessage {
public:
    SendIdentityReq(const string& name_,
                    const string& domain_,
                    const optional<string>& location_,
                    const uint8_t roles_,
                    const string& mac_)
        : OpflexMessage("send_identity", REQUEST),
          name(name_), domain(domain_), location(location_), roles(roles_),
          mac(mac_) {}

    virtual void serializePayload(yajr::rpc::SendHandler& writer) {
        (*this)(writer);
    }

    virtual void serializePayload(MessageWriter& writer) {
        (*this)(writer);
    }

    virtual SendIdentityReq* clone() {
        return new SendIdentityReq(*this);
    }

    template <typename T>
    bool operator()(Writer<T> & writer) {
        writer.StartArray();
        writer.StartObject();
        writer.String("proto_version");
        writer.String("1.0");
        writer.String("name");
        writer.String(name.c_str());
        writer.String("domain");
        writer.String(domain.c_str());
        if (location) {
            writer.String("my_location");
            writer.String(location.get().c_str());
        }
        writer.String("my_role");
        writer.StartArray();
        if (roles & OFConstants::POLICY_ELEMENT)
            writer.String("policy_element");
        if (roles & OFConstants::POLICY_REPOSITORY)
            writer.String("policy_repository");
        if (roles & OFConstants::ENDPOINT_REGISTRY)
            writer.String("endpoint_registry");
        if (roles & OFConstants::OBSERVER)
            writer.String("observer");
        writer.EndArray();
        writer.EndObject();
        if (!mac.empty() &&
            (roles & OFConstants::POLICY_ELEMENT)) {
            writer.StartObject();
            writer.String("data");
            writer.StartObject();
            writer.String("mac");
            writer.String(mac.c_str());
            writer.EndObject();
{'fraction_non_alphanumeric': 0.1292817679558011, 'fraction_numerical': 0.0038674033149171273, 'mean_word_length': 3.166283084004603, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1195674', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2077, 'n_words': 442}