当前位置: 首页>>代码示例>>C++>>正文


C++ FastWriter::write方法代码示例

本文整理汇总了C++中json::FastWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ FastWriter::write方法的具体用法?C++ FastWriter::write怎么用?C++ FastWriter::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json::FastWriter的用法示例。


在下文中一共展示了FastWriter::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BeginDelete

void AsyncHttpRequest::BeginDelete(std::string path, Json::Value reqData,
                                   std::function<void(std::string)>&& Callback) {
    _callback = Callback;

    Json::FastWriter writer;

    std::string paramstr = writer.write(reqData);
    tcp::resolver::query	query(_hostname, "http");

    std::ostream request_stream(&_request);
    request_stream << "DELETE " << path << " HTTP/1.1\r\n";
    request_stream << "Host: " << _hostname << "\r\n";
    request_stream << "Accept: */*\r\n";
    request_stream << "Connection: close\r\n";
    request_stream << "Content-Length: " << paramstr.size() << "\r\n\r\n";
    request_stream << paramstr;

    _resolver.async_resolve(query,
                            std::bind(&AsyncHttpRequest::handle_resolve,
                                      shared_from_this(), std::placeholders::_1, std::placeholders::_2));
}
开发者ID:quilime,项目名称:Cinder-HttpRequest,代码行数:21,代码来源:HttpRequest.cpp

示例2: GetSendData

// 获取待发送的数据,可先获取data长度,如:GetSendData(NULL, 0, dataLen);
bool UploadPopLadyAutoInviteTask::GetSendData(void* data, unsigned int dataSize, unsigned int& dataLen)
{
	bool result = false;
	
	// 构造json协议
	Json::Value root;
	root[TARGETID_PARAM] = m_userId;
	root[MSGID_PARAM] = m_msg;
	root[KEY_PARAM] = atof(m_key.c_str());
	Json::FastWriter writer;
	string json = writer.write(root);
	
	// 填入buffer
	if (json.length() < dataSize) {
		memcpy(data, json.c_str(), json.length());
		dataLen = json.length();

		result  = true;
	}
	return result;
}
开发者ID:KingsleyYau,项目名称:Dating4Man-iOS,代码行数:22,代码来源:UploadPopLadyAutoInviteTask.cpp

示例3: WriteToFile

int WriteToFile()
{
    using namespace std;
    Json::Value root;
    Json::FastWriter writer;
    Json::Value person;

    person["name"] = "hello world";
    person["age"] = 100;
    root.append(person);

    std::string json_file = writer.write(root);


    ofstream ofs;
    ofs.open("test1.json");
    assert(ofs.is_open());
    ofs << json_file;

    return 0;
}
开发者ID:github188,项目名称:BasicFunctionCodeBase,代码行数:21,代码来源:jsonCppTest.cpp

示例4: SignalQuality

int SignalQuality(Json::Value& response)
{
    if(!g_current_livestream.empty())
    {
        Json::FastWriter writer;
        std::string arguments = writer.write(g_current_livestream);

        int retval = ArgusTVJSONRPC("ArgusTV/Control/GetLiveStreamTuningDetails", arguments, response);

        //if (retval != E_FAILED)
        //{
        //  printValueTree(response);
        //}

        return retval;
    }
    else
    {
        return E_FAILED;
    }
}
开发者ID:notspiff,项目名称:pvr.argustv,代码行数:21,代码来源:argustvrpc.cpp

示例5: InitParam

// 初始化参数
bool SendCamShareInviteTask::InitParam(const string& userId, CamshareInviteType inviteType, int sessionId, const string& fromName)
{
	bool result = false;
	if (!userId.empty()) {
		m_userId = userId;
        
        Json::Value root;
        root[CamshareInviteTypeKey] = inviteType;
        root[CamshareInviteTypeSessionIdKey] = sessionId;
        root[CamshareInviteTypeFromNameKey] = fromName;
        
        Json::FastWriter writer;
        string camShareMsg = writer.write(root);
        
        m_camShareMsg = camShareMsg;
        
		result = true;
	}
	
	return result;
}
开发者ID:KingsleyYau,项目名称:Dating4Man-iOS,代码行数:22,代码来源:SendCamShareInviteTask.cpp

示例6: write

int SocketIO::write(const Json::Value &data, const string& key){
	Json::FastWriter writer;
	string msg = writer.write(data);
	uint32_t len = htonl(msg.length());
	string hmac_key;

	hmac_msje(key, msg, hmac_key);

	if(send(this->fd, (void*) &len, 4, 0) != 4)
		return -1;

	if ((uint32_t) send(this->fd,
			(void*) msg.c_str(), msg.length(), 0) != msg.length())
		return -1;

	if ((uint32_t) send(this->fd,
			(void*) hmac_key.c_str(), hmac_key.length(), 0) != hmac_key.length())
		return -1;

	return 0;
}
开发者ID:rburdet,项目名称:CandyCrash,代码行数:21,代码来源:common.socket_io.cpp

示例7: queryByISBN

bool CLibrary::queryByISBN(const char * strISBN, IBook ** ppBook)
{
	std::string strRequest;
	std::string strRespond;
	Json::Value value0;
	value0["command"] = "library_queryByISBN";
	value0["isbn"] = strISBN;
	Json::FastWriter writer;
	strRequest = writer.write(value0);
	if (sendRequest(strRequest, strRespond)) {
		Json::Reader reader;
		Json::Value value;
		reader.parse(strRespond, value);
		if (value["result"].asString() == "1") {
			TBookBasicInfo *Info = new TBookBasicInfo;
			Info->id = value["id"].asInt();
			Info->count = value["count"].asInt();
			Info->bcount = value["bcount"].asInt();
			Info->name = value["name"].asString();
			Info->author = value["author"].asString();
			Info->isbn = value["isbn"].asString();
			Info->publisher = value["publisher"].asString();
			CBook *book = new CBook();
			book->m_CBBI = Info;
			book->id = Info->id;
			book->AddRef();
			*ppBook = book;
			return true;
		}
		else
		{
			if (value["result"].asString() == "DatabaseError")
				setError(DatabaseError, 0, "database_error");
			else setError(InvalidParam, 1, "Invalid strISBN");//jere w about 1
			return false;
		}
	}
	else setError(NetworkError, 0, "network_error");
	return false;
}
开发者ID:sxtyzhangzk,项目名称:LiBrother,代码行数:40,代码来源:library.cpp

示例8: queryByName

int CLibrary::queryByName(const char * strName, IFvector& vBooks, int nCount, int nTop)
{
	std::string strRequest;
	std::string strRespond;
	Json::Value value0;
	value0["command"] = "library_queryByName";
	value0["name"] = strName;
	value0["nCount"] = nCount;
	value0["nTop"] = nTop;
	Json::FastWriter writer;
	strRequest = writer.write(value0);
	if (!sendRequest(strRequest, strRespond))
	{
		setError(NetworkError, 0, "Network Error");
		return -1;
	}
	Json::Reader reader;
	Json::Value value;
	reader.parse(strRespond, value);

	int num = value[0].asInt();
	for (int i = 0; i < num; i++) {
		TBookBasicInfo Info;
		Json::Value bookinfo = value[i + 1];
		Info.id = bookinfo["id"].asInt();
		Info.count = bookinfo["count"].asInt();
		Info.bcount = bookinfo["bcount"].asInt();
		Info.name = bookinfo["name"].asString();
		Info.author = bookinfo["author"].asString();
		Info.isbn = bookinfo["isbn"].asString();
		Info.publisher = bookinfo["publisher"].asString();;
		CBook *book = new CBook;
		TBookBasicInfo *pInfo = new TBookBasicInfo(Info);
		book->m_CBBI = pInfo;
		book->id = Info.id;
		//book->setBasicInfo(Info);
		vBooks.push_back(book);
	}
	return 	num;
}
开发者ID:sxtyzhangzk,项目名称:LiBrother,代码行数:40,代码来源:library.cpp

示例9: Pkt

void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
{
	cServer * Server = cRoot::Get()->GetServer();
	AString ServerDescription = Server->GetDescription();
	auto NumPlayers = static_cast<signed>(Server->GetNumPlayers());
	auto MaxPlayers = static_cast<signed>(Server->GetMaxPlayers());
	AString Favicon = Server->GetFaviconData();
	cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);

	// Version:
	Json::Value Version;
	Version["name"] = "Cuberite 1.11";
	Version["protocol"] = cProtocolRecognizer::PROTO_VERSION_1_11_0;

	// Players:
	Json::Value Players;
	Players["online"] = NumPlayers;
	Players["max"] = MaxPlayers;
	// TODO: Add "sample"

	// Description:
	Json::Value Description;
	Description["text"] = ServerDescription.c_str();

	// Create the response:
	Json::Value ResponseValue;
	ResponseValue["version"] = Version;
	ResponseValue["players"] = Players;
	ResponseValue["description"] = Description;
	m_Client->ForgeAugmentServerListPing(ResponseValue);
	if (!Favicon.empty())
	{
		ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
	}

	// Serialize the response into a packet:
	Json::FastWriter Writer;
	cPacketizer Pkt(*this, 0x00);  // Response packet
	Pkt.WriteString(Writer.write(ResponseValue));
}
开发者ID:lkolbly,项目名称:MCServer,代码行数:40,代码来源:Protocol_1_11.cpp

示例10: SendData

IOTAPI::IOTAPI_err IOT_API::SendData(const std::string& devId, const std::vector<IOT_WriteData>& data) const
{
    IOTAPI::IOTAPI_err ret = IOT_ERR_PARAM;
    Json::Value writeData;

    if(data.empty()) {
        return ret;
    }

    for(uint32_t i = 0; i < data.size(); ++i)
    {
        Json::Value oneData;
        if(data.at(i).ToJSON(oneData)) {
            writeData.append(oneData);
        } else {
            return ret;
        }
    }

    std::string url = m_servAddr + IOT_WRITE_PATH + "/" + devId;
    std::string response;
    Json::FastWriter fastWriter;
    std::string json = fastWriter.write(writeData);

    ret = m_client.PostAndReadResponse(url, m_authName, m_password, json, response);

    Json::Value writeAnswer;
    if(ParseJson(response, writeAnswer)) {
        if(ret != IOTAPI::IOT_ERR_OK) {
            ret = GetErrorCode(writeAnswer);
        } else if(writeAnswer.isMember("totalWritten") && writeAnswer["totalWritten"].isIntegral()) {
            if(writeAnswer["totalWritten"].asUInt() == data.size())
                ret = IOT_ERR_OK;
        } else {
            ret = IOT_ERR_GENERAL;
        }
    }

    return ret;
}
开发者ID:IoT-Ticket,项目名称:IoT-LinuxCppClient,代码行数:40,代码来源:IOT_API.cpp

示例11: PerformAction

bool ContextMenuUtil::PerformAction(int command)
{
	ContextMenuItem* contextMenuItem;

	if (!GetContextMenuItem(command, &contextMenuItem))
	{
		return false;
	}

	Json::Value jsonValue;

	jsonValue[NATIVITY_UUID] = StringUtil::toString(contextMenuItem->GetUuid()->c_str());

	for (vector<wstring>::iterator it = _selectedFiles->begin(); it != _selectedFiles->end(); it++)
	{
		wstring selectedFile = *it;

		jsonValue[NATIVITY_FILES].append(StringUtil::toString(selectedFile));
	}

	Json::Value jsonRoot;

	jsonRoot[NATIVITY_COMMAND] = NATIVITY_CONTEXT_MENU_ACTION;
	jsonRoot[NATIVITY_VALUE] = jsonValue;

	Json::FastWriter jsonWriter;

	wstring* jsonMessage = new wstring();

	jsonMessage->append(StringUtil::toWstring(jsonWriter.write(jsonRoot)));

	wstring* response = new wstring();

	if (!_communicationSocket->SendMessageReceiveResponse(jsonMessage->c_str(), response))
	{
		return false;
	}

	return true;
}
开发者ID:Moscarda,项目名称:liferay-nativity,代码行数:40,代码来源:ContextMenuUtil.cpp

示例12: sdgetsize

std::string ScreenDisplayNDK::sdgetsize() {
	bb::device::DisplayInfo display;
	Json::FastWriter writer;
	Json::Value root;

	double physx = display.physicalSize().width();
	double physy = display.physicalSize().height();
	int pixx = display.pixelSize().width();
	int pixy = display.pixelSize().height();
	double ppmm = 0;
	double ppmmx = 0;
	double ppmmy = 0;
	double pshape = 0;

	double physdiag = 0; // Diagonal metrics
	double pixdiag = 0;

	if((pixx > 0) && (pixy > 0) && (physx > 0) && (physy > 0)) {
		ppmmx = pixx / physx;
		ppmmy = pixy / physy;
		pshape = (ppmmx / ppmmy);
		physdiag = sqrt((physx * physx) + (physy * physy));
		pixdiag = sqrt((pixx * pixx) + (pixy * pixy));
		ppmm = pixdiag / physdiag;
	}

	root["physicalWidth"] = physx;
	root["physicalHeight"] = physy;
	root["pixelWidth"] = pixx;
	root["pixelHeight"] = pixy;
	root["ppmm"] = ppmm;
	root["ppmmX"] = ppmmx;
	root["ppmmY"] = ppmmy;
	root["ppi"] = ppmm * MMPERINCH;
	root["ppiX"] = ppmmx * MMPERINCH;
	root["ppiY"] = ppmmy * MMPERINCH;
	root["pixelShape"] = pshape;

	return writer.write(root);
}
开发者ID:Balgam,项目名称:WebWorks-Community-APIs,代码行数:40,代码来源:ScreenDisplay_ndk.cpp

示例13: HandlePacketStatusRequest

void cProtocolRecognizer::HandlePacketStatusRequest(void)
{
	cServer * Server = cRoot::Get()->GetServer();
	AString ServerDescription = Server->GetDescription();
	auto NumPlayers = static_cast<signed>(Server->GetNumPlayers());
	auto MaxPlayers = static_cast<signed>(Server->GetMaxPlayers());
	AString Favicon = Server->GetFaviconData();
	cRoot::Get()->GetPluginManager()->CallHookServerPing(*m_Client, ServerDescription, NumPlayers, MaxPlayers, Favicon);

	// Version:
	Json::Value Version;
	Version["name"] = "Cuberite " MCS_CLIENT_VERSIONS;
	Version["protocol"] = MCS_LATEST_PROTOCOL_VERSION;

	// Players:
	Json::Value Players;
	Players["online"] = NumPlayers;
	Players["max"] = MaxPlayers;
	// TODO: Add "sample"

	// Description:
	Json::Value Description;
	Description["text"] = ServerDescription.c_str();

	// Create the response:
	Json::Value ResponseValue;
	ResponseValue["version"] = Version;
	ResponseValue["players"] = Players;
	ResponseValue["description"] = Description;
	if (!Favicon.empty())
	{
		ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
	}

	Json::FastWriter Writer;
	AString Response = Writer.write(ResponseValue);

	cPacketizer Pkt(*this, 0x00);  // Response packet
	Pkt.WriteString(Response);
}
开发者ID:UltraCoderRU,项目名称:MCServer,代码行数:40,代码来源:ProtocolRecognizer.cpp

示例14: comm_type

std::string const* MessageFactory::CreateMoveMessage(enum Tetromino::Move move, int pieceId) const {
    Json::Value root;
    Json::FastWriter writer;

    Json::Value comm_type ("GameMove");
    Json::Value client_token (m_clientToken);

    root["comm_type"] = comm_type;
    root["client_token"] = client_token;
    if (move == Tetromino::left) {
        Json::Value moveV ("left");
        root["move"] = moveV;
    }
    else if (move == Tetromino::right) {
        Json::Value moveV ("right");
        root["move"] = moveV;
    }
    else if (move == Tetromino::down) {
        Json::Value moveV ("down");
        root["move"] = moveV;
    }
    else if (move == Tetromino::lrotate) {
        Json::Value moveV ("lrotate");
        root["move"] = moveV;
    }
    else if (move == Tetromino::rrotate) {
        Json::Value moveV ("rrotate");
        root["move"] = moveV;
    }
    else if (move == Tetromino::drop) {
        Json::Value moveV ("drop");
        root["move"] = moveV;
    }

    Json::Value number (pieceId);
    root["piece_number"] = number;

    std::string const* serialized = new std::string(writer.write(root));
    return serialized;
}
开发者ID:ahelwer,项目名称:pason2012,代码行数:40,代码来源:message_factory.cpp

示例15: to_json

// register obj
std::string CmdRegister::to_json()
{
    std::string jstr;

    Json::Features::all();
    Json::Value root;
    // Json::StyledWriter jwriter;
    Json::FastWriter fjwriter;

    root["cmd_id"] = cmd_id;
    root["cmd_seq"] = cmd_seq;
    root["display_name"] = display_name;
    root["user_name"] = user_name;
    root["password"] = password;
    root["sip_server"] = sip_server;
    root["acc_id"] = acc_id;
    root["unregister"] = unregister;

    jstr = fjwriter.write(root);

    return jstr;
}
开发者ID:baisoo,项目名称:kitphone,代码行数:23,代码来源:intermessage.cpp


注:本文中的json::FastWriter::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。