<commit_before>/**
 * This file is part of the "libfnord" project
 *   Copyright (c) 2015 <NAME>
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include <fnord-msg/MessagePrinter.h>
#include <fnord-base/stringutil.h>

namespace fnord {
namespace msg {

String MessagePrinter::print(
    const MessageObject& msg,
    const MessageSchema& schema) {
  return printObject(0, msg, schema);
}

String MessagePrinter::printObject(
    size_t level,
    const MessageObject& msg,
    const MessageSchema& schema) {
  String ws(level * 2, ' ');

  switch (schema.type(msg.id)) {

    case FieldType::OBJECT: {
      String str;
      str.append(StringUtil::format("$0$1 {\n", ws, schema.name(msg.id)));

      for (const auto& o : msg.asObject()) {
        str.append(printObject(level + 1, o, schema));
      }

      str.append(ws + "}\n");
      return str;
    }

    case FieldType::BOOLEAN:
      return StringUtil::format(
          "$0$1 = $2\n",
          ws,
          schema.name(msg.id),
          msg.asBool());

    case FieldType::STRING:
      return StringUtil::format(
          "$0$1 = $2\n",
          ws,
          schema.name(msg.id),
          msg.asString());

    case FieldType::UINT32:
      return StringUtil::format(
          "$0$1 = $2\n",
          ws,<commit_msg>MessagePrinter<commit_after>/**
 * This file is part of the "libfnord" project
 *   Copyright (c) 2015 <NAME>
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include <fnord-msg/MessagePrinter.h>
#include <fnord-base/stringutil.h>

namespace fnord {
namespace msg {

String MessagePrinter::print(
    const MessageObject& msg,
    const MessageSchema& schema) {
  return printObject(0, msg, schema);
}

String MessagePrinter::printObject(
    size_t level,
    const MessageObject& msg,
    const MessageSchema& schema) {
  String ws(level * 2, ' ');

  switch (schema.type(msg.id)) {

    case FieldType::OBJECT: {
      String str;
      str.append(StringUtil::format("$0$1 {\n", ws, schema.name(msg.id)));

      for (const auto& o : msg.asObject()) {
        str.append(printObject(level + 1, o, schema));
      }

      str.append(ws + "}\n");
      return str;
    }

    case FieldType::BOOLEAN:
      return StringUtil::format(
          "$0$1 = $2\n",
          ws,
          schema.name(msg.id),
          msg.asBool());

    case FieldType::STRING:
      return StringUtil::format(
          "$0$1 = \"$2\"\n",
          ws,
          schema.name(msg.id),
          msg.asString());

    case FieldType::UINT32:
      return StringUtil::format(
          "$0$1 = $2\n",
          ws,
{'fraction_non_alphanumeric': 0.13709412922269595, 'fraction_numerical': 0.014430960970810102, 'mean_word_length': 2.558926487747958, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2983272', 'n_tokens_mistral': 999, 'n_tokens_neox': 966, 'n_words': 269}