Beispiel #1
0
bool parseAndWrite(const char* location, Json::Writer& writer)
{
  Json::Value metadata;
  metadata[LOCATION] = location;
  TagLib::FileRef f(location);

  if (f.isNull()){
    return false;
  }

  if (f.tag() && !f.tag()->isEmpty()){
    TagLib::Tag* tag = f.tag();
    TagLib::String artist = tag->artist();
    TagLib::String album = tag->artist();
    TagLib::String title = tag->title();

    uint track = tag->track();
    uint year = tag->year();

    metadata[TITLE] = title.toCString(true);
    metadata[ARTIST] = artist.toCString(true);
    metadata[ALBUM] = album.toCString(true);
    metadata[TRACK] = track;
    metadata[YEAR] = year;
  }

  std::cout << writer.write(metadata);
  return true;
}
Beispiel #2
0
std::vector<char> command_protocol_t::serialize_command(const Json::Value& command)
{
    Json::Writer writer;
    const std::string& str = writer.write(command);

    std::vector<char> ret(str.size());

    std::copy(str.begin(), str.end(), ret.begin());
    ret.push_back('\0');

    return ret;
}
Beispiel #3
0
void Analyze::end_of_log(uint32_t packet_count, uint64_t bytes_dropped) {

    std::for_each(_analyzers.begin(),
                  _analyzers.end(),
                  [packet_count](Analyzer* c){c->end_of_log(packet_count); });

    Json::Value root;
    root["format-version"] = "0.1";
    root["timestamp"] = (Json::UInt64)start_time;
    root["duration"] = (Json::UInt64)(now() - start_time);

    results_json(root);

    root["packet_count"] = packet_count;
    root["packet-count"] = packet_count;
    root["bytes-dropped"] = (Json::UInt64)bytes_dropped;

    Json::Writer *writer;
    switch(_output_style) {
    case OUTPUT_JSON: {
        writer = new Json::StyledWriter();
        break;
    }
    case OUTPUT_PLAINTEXT:
        writer = new Json::PlainTextWriter();
        break;
    case OUTPUT_HTML:
        writer = new Json::HTMLWriter();
        break;
    case OUTPUT_BRIEF:
        writer = new Json::BriefPlainTextWriter();
        break;
    default:
        ::fprintf(stderr, "Writer not set for output style");
        abort();
    }
    std::string document = writer->write(root);
    fprintf(stdout, "%s", document.c_str());
}