<commit_before>/*
 * File:   KrakenBattle.cpp
 * Author: <NAME>
 *
 * Created on November 24, 2015
 */

#include "KrakenBattle.h"
#include <algorithm>
#include <iterator>
#include <g3log/g3log.hpp>

namespace {
   const std::string emptyUUID = {"00000000-0000-0000-0000-000000000000"};
   const std::vector<uint8_t> emptyData = {};
}



namespace KrakenBattle {

   /**
   * formats the data to send to the Harpoon according to the specification for
   * data transfers
   * @param uuid
   * @param type one of Data, Done, Error, End
   * @param data to send (optional, used for SendType::Data)
   * @param error message (optional, used for SendType::Error)
   * @return merged data uuid<SendType>optional:data/optional:error_msg
   *
   * Ref: KrakenBattle.h for detailed information regarding the sending
   */
   Kraken::Chunks  MergeData(const std::string& uuid, const KrakenBattle::SendType& type, const Kraken::Chunks& data, const std::string& error_msg) {
      const std::string sendType = EnumToString(type);
      const std::string& uuidToSend = (SendType::End == type ? emptyUUID : uuid);
      std::vector<uint8_t> merged;
      merged.reserve(uuidToSend.size() + sendType.size() + data.size() + error_msg.size());
      // uuid, type, possible:data, possible:error
      std::copy(uuidToSend.begin(), uuidToSend.end(), std::back_inserter(merged));
      std::copy(sendType.begin(), sendType.end(), std::back_inserter(merged));

      if (SendType::Data == type) {
         std::copy(data.begin(), data.end(), std::back_inserter(merged));
      } else if (SendType::Error == type) {
         std::copy(error_msg.begin(), error_msg.end(), std::back_inserter(merged));
      }
      return merged;
   }
<commit_msg>Handle sending data for Begin chunk<commit_after>/*
 * File:   KrakenBattle.cpp
 * Author: <NAME>
 *
 * Created on November 24, 2015
 */

#include "KrakenBattle.h"
#include <algorithm>
#include <iterator>
#include <g3log/g3log.hpp>

namespace {
   const std::string emptyUUID = {"00000000-0000-0000-0000-000000000000"};
   const std::vector<uint8_t> emptyData = {};
}



namespace KrakenBattle {

   /**
   * formats the data to send to the Harpoon according to the specification for
   * data transfers
   * @param uuid
   * @param type one of Data, Done, Error, End
   * @param data to send (optional, used for SendType::Data)
   * @param error message (optional, used for SendType::Error)
   * @return merged data uuid<SendType>optional:data/optional:error_msg
   *
   * Ref: KrakenBattle.h for detailed information regarding the sending
   */
   Kraken::Chunks  MergeData(const std::string& uuid, const KrakenBattle::SendType& type, const Kraken::Chunks& data, const std::string& error_msg) {
      const std::string sendType = EnumToString(type);
      const std::string& uuidToSend = (SendType::End == type ? emptyUUID : uuid);
      std::vector<uint8_t> merged;
      merged.reserve(uuidToSend.size() + sendType.size() + data.size() + error_msg.size());
      // uuid, type, possible:data, possible:error
      std::copy(uuidToSend.begin(), uuidToSend.end(), std::back_inserter(merged));
      std::copy(sendType.begin(), sendType.end(), std::back_inserter(merged));

      if (SendType::Data == type || SendType::Begin == type) {
         std::copy(data.begin(), data.end(), std::back_inserter(merged));
      } else if (SendType::Error == type) {
         std::copy(error_msg.begin(), error_msg.end(), std::back_inserter(merged));
      } 
      return merged; 
   }

{'fraction_non_alphanumeric': 0.1445301342473579, 'fraction_numerical': 0.023993144815766924, 'mean_word_length': 3.960339943342776, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '5176445', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1118, 'n_words': 277}