<commit_before>/*
 * @file DebugMessage.h
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */

#ifndef _DebugMessage_h_
#define _DebugMessage_h_

#include <sstream>
#include <map>
#include <list>
#include <vector>

namespace naoth
{

class DebugMessageIn
{
public:
  class Message
  {
  public:
    Message() : id(-1) {}

    int id;
    std::string command;
    std::map<std::string, std::string> arguments;
  };

  std::list<Message> messages;
};

class DebugMessageInCognition : public DebugMessageIn {};
class DebugMessageInMotion : public DebugMessageIn {};

class DebugMessageOut
{
public:
  class Message
  {
  public:
    Message(int id, size_t length) : id(id), data(length) {}

    int id;
    std::vector<char> data;
  };

  std::list<Message*> answers;

  void addResponse(int id, std::stringstream& str) {
    int length_raw = static_cast<int>(str.tellp()); 
    size_t length = length_raw < 0 ? 0 : static_cast<size_t>(length_raw);
  
    // NOTE: the objects are deleted later by the DebugServer
    Message* msg = new Message(id, length);

    if(length > 0) {
      str.read(msg->data.data(), static_cast<int>(msg->data.size()));
    }

    answers.push_back(msg);
  }

  void reset() {
    answers.clear();
  }
};

} // namespace naoth

#endif // _DebugMessage_h_
<commit_msg>nicer calculation of the stream length<commit_after>/*
 * @file DebugMessage.h
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */

#ifndef _DebugMessage_h_
#define _DebugMessage_h_

#include <sstream>
#include <map>
#include <list>
#include <vector>

namespace naoth
{

class DebugMessageIn
{
public:
  class Message
  {
  public:
    Message() : id(-1) {}

    int id;
    std::string command;
    std::map<std::string, std::string> arguments;
  };

  std::list<Message> messages;
};

class DebugMessageInCognition : public DebugMessageIn {};
class DebugMessageInMotion : public DebugMessageIn {};

class DebugMessageOut
{
public:
  class Message
  {
  public:
    Message(int id, size_t length) : id(id), data(length) {}

    int id;
    std::vector<char> data;
  };

  std::list<Message*> answers;

  void addResponse(int id, std::stringstream& str) {
    // get the length of the message in the stream
    size_t length = static_cast<size_t>(std::max(static_cast<int>(str.tellp()), 0));

    // NOTE: the objects are deleted later by the DebugServer
    Message* msg = new Message(id, length);

    if(length > 0) {
      str.read(msg->data.data(), static_cast<int>(msg->data.size()));
    }

    answers.push_back(msg);
  }

  void reset() {
    answers.clear();
  }
};

} // namespace naoth

#endif // _DebugMessage_h_

{'fraction_non_alphanumeric': 0.14752851711026616, 'fraction_numerical': 0.002661596958174905, 'mean_word_length': 3.648409893992933, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5629904', 'n_tokens_mistral': 921, 'n_tokens_neox': 895, 'n_words': 215}