本文整理汇总了C++中json::FastWriter::omitEndingLineFeed方法的典型用法代码示例。如果您正苦于以下问题:C++ FastWriter::omitEndingLineFeed方法的具体用法?C++ FastWriter::omitEndingLineFeed怎么用?C++ FastWriter::omitEndingLineFeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json::FastWriter
的用法示例。
在下文中一共展示了FastWriter::omitEndingLineFeed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeAndPrintJson
string makeAndPrintJson(const VadEvents& events)
{
JsonValuePtr jsonEvents = serializeVadEvents(events);
Json::FastWriter fastWriter;
fastWriter.omitEndingLineFeed();
string serializedEvents = fastWriter.write(*jsonEvents);
cout << "Serialized vad events " << endl << serializedEvents << endl;
return serializedEvents;
}
示例2: _read
void ChromeCast::_read()
{
while (true)
{
char pktlen[4];
int r;
for (r = 0; r < sizeof pktlen; ++r)
if (SSL_read(m_ssl, pktlen + r, 1) < 1)
break;
if (r != sizeof pktlen) {
syslog(LOG_ERR, "SSL_read error");
_release_waiters();
return;
}
unsigned int len;
memcpy(&len, pktlen, sizeof len);
len = ntohl(len);
std::string buf;
while (buf.size() < len) {
char b[2048];
int r = SSL_read(m_ssl, b, sizeof b);
if (r < 1)
break;
buf.append(b, r);
}
if (buf.size() != len) {
syslog(LOG_ERR, "SSL_read error");
_release_waiters();
return;
}
extensions::core_api::cast_channel::CastMessage msg;
msg.ParseFromString(buf);
syslog(LOG_DEBUG, "%s -> %s (%s): %s",
msg.source_id().c_str(),
msg.destination_id().c_str(),
msg.namespace_().c_str(),
msg.payload_utf8().c_str()
);
Json::Value response;
Json::Reader reader;
if (!reader.parse(msg.payload_utf8(), response, false))
continue;
if (msg.namespace_() == "urn:x-cast:com.google.cast.tp.heartbeat")
{
Json::FastWriter fw;
fw.omitEndingLineFeed();
extensions::core_api::cast_channel::CastMessage reply(msg);
Json::Value msg;
msg["type"] = "PONG";
reply.set_payload_utf8(fw.write(msg));
std::string data;
reply.SerializeToString(&data);
unsigned int len = htonl(data.size());
SSL_write(m_ssl, &len, sizeof len);
SSL_write(m_ssl, data.c_str(), data.size());
continue;
}
if (msg.namespace_() == "urn:x-cast:com.google.cast.tp.connection")
{
if (response["type"].asString() == "CLOSE")
{
_release_waiters();
m_init = false;
}
}
if (msg.namespace_() == "urn:x-cast:com.google.cast.media")
{
if (response["type"].asString() == "MEDIA_STATUS")
{
if (response.isMember("status") &&
response["status"].isValidIndex(0u))
{
Json::Value& status = response["status"][0u];
m_media_session_id = status["mediaSessionId"].asUInt();
}
}
}
if (response.isMember("requestId"))
{
m_mutex.lock();
auto waitIter = m_wait.find(response["requestId"].asUInt());
if (waitIter != m_wait.end())
{
waitIter->second.second = response;
waitIter->second.first->notify_all();
}
m_mutex.unlock();
}
if (msg.namespace_() == "urn:x-cast:com.google.cast.media")
//.........这里部分代码省略.........
示例3: send
Json::Value ChromeCast::send(const std::string& namespace_, const Json::Value& payload)
{
Json::FastWriter fw;
fw.omitEndingLineFeed();
extensions::core_api::cast_channel::CastMessage msg;
msg.set_payload_type(msg.STRING);
msg.set_protocol_version(msg.CASTV2_1_0);
msg.set_namespace_(namespace_);
msg.set_source_id(m_source_id);
msg.set_destination_id(m_destination_id);
msg.set_payload_utf8(fw.write(payload));
std::string data, foo;
char pktlen[4];
unsigned int len = htonl(msg.ByteSize());
memcpy(&pktlen, &len, sizeof len);
foo.append(pktlen, sizeof pktlen);
msg.SerializeToString(&data);
foo += data;
std::condition_variable f;
bool wait = false;
unsigned int requestId;
if (payload.isMember("requestId"))
{
requestId = payload["requestId"].asUInt();
m_mutex.lock();
m_wait[requestId] = std::make_pair(&f, std::string());
wait = true;
m_mutex.unlock();
}
syslog(LOG_DEBUG, "%s -> %s (%s): %s",
msg.source_id().c_str(),
msg.destination_id().c_str(),
msg.namespace_().c_str(),
msg.payload_utf8().c_str()
);
int w;
m_ssl_mutex.lock();
if (m_ssl) {
w = SSL_write(m_ssl, foo.c_str(), foo.size());
if (w == -1) {
syslog(LOG_DEBUG, "SSL_write error");
disconnect();
}
} else
w = -1;
m_ssl_mutex.unlock();
if (wait && w == -1)
{
m_mutex.lock();
m_wait.erase(requestId);
m_mutex.unlock();
wait = false;
}
Json::Value ret;
if (wait) {
std::unique_lock<std::mutex> wl(m_mutex);
f.wait(wl);
ret = m_wait[requestId].second;
m_wait.erase(requestId);
m_mutex.unlock();
}
return ret;
}