<commit_before>/* 
 * Author: <NAME>
 *
 * BSD license, See the LICENSE file for more information.
 */

#include <stdexcept>
#include "../c/encoding/BinaryXMLName.h"
#include "../Name.hpp"
#include "BinaryXMLEncoder.hpp"
#include "BinaryXMLWireFormat.hpp"

using namespace std;

namespace ndn {

BinaryXMLWireFormat BinaryXMLWireFormat::instance_;

void BinaryXMLWireFormat::encodeName(Name &name, vector<unsigned char> &output) 
{
  struct ndn_Name nameStruct;
  struct ndn_NameComponent components[100];
  ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
  name.get(nameStruct);

  BinaryXMLEncoder encoder;
  ndn_encodeBinaryXMLName(&nameStruct, encoder.getEncoder());
          
  output = vector<unsigned char>(encoder.getEncoder()->output.array, encoder.getEncoder()->output.array + encoder.getEncoder()->offset);
}

void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, unsigned int inputLength)
{
  struct ndn_NameComponent components[100];
  struct ndn_Name nameStruct;
  ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
    
  char *error;
  if (error = ndn_decodeBinaryXMLName(&nameStruct, (unsigned char *)input, inputLength))
    throw std::runtime_error(error);

  name.set(nameStruct);
}

}
<commit_msg>In encodeName, use insert to append to output.<commit_after>/* 
 * Author: <NAME>
 *
 * BSD license, See the LICENSE file for more information.
 */

#include <stdexcept>
#include "../c/encoding/BinaryXMLName.h"
#include "../Name.hpp"
#include "BinaryXMLEncoder.hpp"
#include "BinaryXMLWireFormat.hpp"

using namespace std;

namespace ndn {

BinaryXMLWireFormat BinaryXMLWireFormat::instance_;

void BinaryXMLWireFormat::encodeName(Name &name, vector<unsigned char> &output) 
{
  struct ndn_Name nameStruct;
  struct ndn_NameComponent components[100];
  ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
  name.get(nameStruct);

  BinaryXMLEncoder encoder;
  ndn_encodeBinaryXMLName(&nameStruct, encoder.getEncoder());
          
  output.insert(output.end(), encoder.getEncoder()->output.array, encoder.getEncoder()->output.array + encoder.getEncoder()->offset);
}

void BinaryXMLWireFormat::decodeName(Name &name, const unsigned char *input, unsigned int inputLength)
{
  struct ndn_NameComponent components[100];
  struct ndn_Name nameStruct;
  ndn_Name_init(&nameStruct, components, sizeof(components) / sizeof(components[0]));
    
  char *error;
  if (error = ndn_decodeBinaryXMLName(&nameStruct, (unsigned char *)input, inputLength))
    throw std::runtime_error(error);

  name.set(nameStruct);
}

}

{'fraction_non_alphanumeric': 0.1244343891402715, 'fraction_numerical': 0.006033182503770739, 'mean_word_length': 5.7851662404092075, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, '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': '7378460', 'n_tokens_mistral': 840, 'n_tokens_neox': 798, 'n_words': 180}