<commit_before>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 Aldebaran Robotics
*/

#include <qimessaging/message.hpp>
#include <qimessaging/datastream.hpp>
#include <iostream>
#include <boost/atomic.hpp>
#include <qi/log.hpp>
#include <cassert>

namespace qi {

  const unsigned int messageMagic = 0x42adde42;

  unsigned int newMessageId()
  {
    static boost::atomic_uint32_t id(0);
    id++;
    return id;
  }

  Message::Message()
  {
    _header = new qi::Message::MessageHeader();
    memset(_header, 0, sizeof(MessageHeader));
    _header->id = newMessageId();
    _header->magic = messageMagic;
    _buffer = new qi::Buffer();
    _withBuffer = false;
  }

  Message::Message(Buffer *buf)
  {
    _header = new qi::Message::MessageHeader();
    memset(_header, 0, sizeof(MessageHeader));
    _header->id = newMessageId();
    _header->magic = messageMagic;
    _buffer = buf;
    _withBuffer = true;
  }

  Message::Message(const Message &msg) {
    memcpy(_header, msg._header, sizeof(MessageHeader));
    _buffer = msg._buffer;
    _withBuffer = true;
  }

  Message &Message::operator=(const Message &msg) {
    memcpy(_header, msg._header, sizeof(MessageHeader));
    _buffer = msg._buffer;
    _withBuffer = true;
  }

  Message::~Message()
  {
    if (!_withBuffer)
      delete _buffer;
  }

  std::ostream& operator<<(std::ostream& os, const qi::Message& msg) {
    os << "message {"
       << "size=" << msg.size()
       << ", id=" << msg.id()
       << ", type=" << msg.type()<commit_msg>Fix copy constructor (missing return value).<commit_after>/*
** Author(s):
**  - <NAME> <<EMAIL>.com>
**
** Copyright (C) 2012 Aldebaran Robotics
*/

#include <qimessaging/message.hpp>
#include <qimessaging/datastream.hpp>
#include <iostream>
#include <boost/atomic.hpp>
#include <qi/log.hpp>
#include <cassert>

namespace qi {

  const unsigned int messageMagic = 0x42adde42;

  unsigned int newMessageId()
  {
    static boost::atomic_uint32_t id(0);
    id++;
    return id;
  }

  Message::Message()
  {
    _header = new qi::Message::MessageHeader();
    memset(_header, 0, sizeof(MessageHeader));
    _header->id = newMessageId();
    _header->magic = messageMagic;
    _buffer = new qi::Buffer();
    _withBuffer = false;
  }

  Message::Message(Buffer *buf)
  {
    _header = new qi::Message::MessageHeader();
    memset(_header, 0, sizeof(MessageHeader));
    _header->id = newMessageId();
    _header->magic = messageMagic;
    _buffer = buf;
    _withBuffer = true;
  }

  Message::Message(const Message &msg) {
    memcpy(_header, msg._header, sizeof(MessageHeader));
    _buffer = msg._buffer;
    _withBuffer = true;
  }

  Message &Message::operator=(const Message &msg) {
    memcpy(_header, msg._header, sizeof(MessageHeader));
    _buffer = msg._buffer;
    _withBuffer = true;
    return *this;
  }

  Message::~Message()
  {
    if (!_withBuffer)
      delete _buffer;
  }

  std::ostream& operator<<(std::ostream& os, const qi::Message& msg) {
    os << "message {"
       << "size=" << msg.size()
       << ", id=" << msg.id()
       << ", type=" << msg.type()
{'fraction_non_alphanumeric': 0.16200578592092574, 'fraction_numerical': 0.00900032144005143, 'mean_word_length': 3.471264367816092, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 29, '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': '7564279', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1039, 'n_words': 224}