コード例 #1
0
ファイル: Test.cpp プロジェクト: Unitrunker/Tile
static bool testJSONControl(IControl *pControl, const TCHAR *reference)
{
	//JSON::Writer reader;
	JSON::Writer writer;

	const TCHAR test[] = _T("test.json");
	bool bOK = false;

	if ( writer.Open(test) )
	{
		TCHAR shell[32] = {0};

		Factory::save(writer, pControl);

		writer.Close();

		// read access?
		if ( _taccess(reference, 04) != 0 ) 
		{
			BOOL okay = CopyFile(test, reference, FALSE);

			_tfprintf(stdout, _T("Creating reference copy %s.\n"), okay ? _T("succeeds") : _T("fails"));
		}

		wsprintf(shell, _T("FC %s %s"), test, reference);
		bOK = _tsystem(shell) == 0;
		_tunlink(test);
	}
	return bOK;
}
コード例 #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;
}
コード例 #3
0
ファイル: tagsync.cpp プロジェクト: ixxra/mymedia
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;
}
コード例 #4
0
ファイル: analyze.cpp プロジェクト: gitter-badger/dronekit-la
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());
}