<commit_before>#include "modem/commands.h"

namespace firebase {
namespace modem {

bool StreamCommand::execute(const String& command,
                            InputStream* in, OutputStream* out) {
  if (in == nullptr || out == nullptr) {
    return false;
  }

  if (command != "BEGIN_STREAM") {
    return false;
  }

  std::string path = in->readLine().c_str();
  std::unique_ptr<FirebaseStream> stream(fbase().streamPtr(path));

  if (stream->error()) {
    out->print("-FAIL ");
    out->println(stream->error().message().c_str());
    return false;
  }

  bool running = true;
  while(running) {
    if (stream->available()) {
      std::string json;
      FirebaseStream::Event event = stream->read(json);
      out->print("+");
      out->print(FirebaseStream::EventToName(event).c_str());
      out->print(" ");
      // TODO(edcoyne): add json parsing and get real path.
      out->println("/dummy/path");
      out->println(json.length());
      out->println(json.c_str());
    } else if (in->available()) {
      String command = in->readLine();
      if (command == "END_STREAM") {
        out->println("+OK");
        running = false;
      } else {
        out->println("-FAIL Cannot call any command but END_STREAM.");
      }
    }
  }

  return true;
}

}  // modem
}  // firebase<commit_msg>Add json parsing to modem streaming<commit_after>#include "modem/commands.h"

namespace firebase {
namespace modem {

bool StreamCommand::execute(const String& command,
                            InputStream* in, OutputStream* out) {
  if (in == nullptr || out == nullptr) {
    return false;
  }

  if (command != "BEGIN_STREAM") {
    return false;
  }

  std::string path = in->readLine().c_str();
  std::unique_ptr<FirebaseStream> stream(fbase().streamPtr(path));

  if (stream->error()) {
    out->print("-FAIL ");
    out->println(stream->error().message().c_str());
    return false;
  }

  bool running = true;
  DynamicJsonBuffer buffer;
  while(running) {
    if (stream->available()) {
      std::string json;
      FirebaseStream::Event event = stream->read(json);
      out->print("+");
      out->print(FirebaseStream::EventToName(event).c_str());
      out->print(" ");
      const auto& object = buffer.parseObject(json.c_str());
      String data = object["data"];
      out->println(object["path"].asString());
      out->println(data.length());
      out->println(data);
    } else if (in->available()) {
      String command = in->readLine();
      if (command == "END_STREAM") {
        out->println("+OK");
        running = false;
      } else {
        out->println("-FAIL Cannot call any command but END_STREAM.");
      }
    }
  }

  return true;
}

}  // modem
}  // firebase
{'fraction_non_alphanumeric': 0.1722488038277512, 'fraction_numerical': 0.0, 'mean_word_length': 2.748965517241379, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6860397', 'n_tokens_mistral': 847, 'n_tokens_neox': 826, 'n_words': 179}