<commit_before>/**
 * Copyright (C) 2013 Regents of the University of California.
 * @author: <NAME> <<EMAIL>>
 * Derived from Name.js by <NAME>.
 * See COPYING for copyright and distribution information.
 */

#include "binary-xml-encoder.h"
#include "binary-xml-decoder.h"
#include "binary-xml-name.h"

ndn_Error ndn_encodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlEncoder *encoder)
{
  ndn_Error error;
  if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Name)))
    return error;
  
  size_t i;
  for (i = 0; i < name->nComponents; ++i) {
    if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Component, &name->components[i].value)))
      return error;
  }
  
  if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
    return error;
  
  return NDN_ERROR_success;
}

ndn_Error ndn_decodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlDecoder *decoder)
{
  ndn_Error error;
  if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Name)))
    return error;
    
  name->nComponents = 0;
  while (1) {
    int gotExpectedTag;
    if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Component, &gotExpectedTag)))
      return error;
    
    if (!gotExpectedTag)
      // No more components.
      break;
    
    struct ndn_Blob component;
    if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Component, 0, &component)))
      return error;
    
    // Add the component to the name.
    if (name->nComponents >= name->maxComponents)
      return NDN_ERROR_read_a_component_past_the_maximum_number_of_components_allowed_in_the_name;
    ndn_NameComponent_initialize(name->components + name->nComponents, component.value, component.length);
    ++name->nComponents;
  }
  
  if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
    return error;
  
  return NDN_ERROR_success;
}<commit_msg>encoding: In ndn_decodeBinaryXmlName, use ndn_Name_appendBlob.<commit_after>/**
 * Copyright (C) 2013 Regents of the University of California.
 * @author: <NAME> <<EMAIL>>
 * Derived from Name.js by <NAME>.
 * See COPYING for copyright and distribution information.
 */

#include "binary-xml-encoder.h"
#include "binary-xml-decoder.h"
#include "binary-xml-name.h"

ndn_Error ndn_encodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlEncoder *encoder)
{
  ndn_Error error;
  if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_Name)))
    return error;
  
  size_t i;
  for (i = 0; i < name->nComponents; ++i) {
    if ((error = ndn_BinaryXmlEncoder_writeBlobDTagElement(encoder, ndn_BinaryXml_DTag_Component, &name->components[i].value)))
      return error;
  }
  
  if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
    return error;
  
  return NDN_ERROR_success;
}

ndn_Error ndn_decodeBinaryXmlName(struct ndn_Name *name, struct ndn_BinaryXmlDecoder *decoder)
{
  ndn_Error error;
  if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_Name)))
    return error;
    
  name->nComponents = 0;
  while (1) {
    int gotExpectedTag;
    if ((error = ndn_BinaryXmlDecoder_peekDTag(decoder, ndn_BinaryXml_DTag_Component, &gotExpectedTag)))
      return error;
    
    if (!gotExpectedTag)
      // No more components.
      break;
    
    struct ndn_Blob component;
    if ((error = ndn_BinaryXmlDecoder_readBinaryDTagElement(decoder, ndn_BinaryXml_DTag_Component, 0, &component)))
      return error;
    if ((error = ndn_Name_appendBlob(name, &component)))
      return error;
  }
  
  if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
    return error;
  
  return NDN_ERROR_success;
}
{'fraction_non_alphanumeric': 0.09973474801061008, 'fraction_numerical': 0.004244031830238726, 'mean_word_length': 4.537444933920705, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '7369563', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1248, 'n_words': 266}