本文整理汇总了C++中TBuffer::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ TBuffer::ToString方法的具体用法?C++ TBuffer::ToString怎么用?C++ TBuffer::ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBuffer
的用法示例。
在下文中一共展示了TBuffer::ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnCaptcha
void OnCaptcha(const TBuffer& data) {
SaveFile("captcha.png", data.ToString());
cout << "input captcha.png text: ";
string captchaText;
string password;
cin >> captchaText;
cout << "input password: ";
cin >> password;
if (Status == ST_Registering) {
Client->Register(password,
"", // e-mail
captchaText);
} else if (Status == ST_Logining) {
Client->Login(password, captchaText);
} else {
cout << "wrong state\n";
_exit(42);
}
}
示例2: OnDataReceived
void OnDataReceived(const TBuffer& data, const TNetworkAddress& address) {
Buffer += data.ToString();
}
示例3: OnDataReceived
void TClient::OnDataReceived(const TBuffer& data) {
switch (CurrentState) {
case CS_Registering: {
Buffer += data.ToString();
string packetStr;
if (Deserialize(Buffer, packetStr)) {
packetStr = Decompress(packetStr);
TServerRegisterPacket packet;
if (!packet.ParseFromString(packetStr)) {
ForceDisconnect();
Config.RegisterResultCallback(RR_ConnectionFailure);
return;
}
string captcha = packet.captcha();
State.set_serverpublickey(packet.publickey());
Config.CaptchaAvailableCallback(captcha);
}
} break;
case CS_RegisteringConfirmWait: {
Buffer += data.ToString();
string packetStr;
if (Deserialize(Buffer, packetStr)) {
packetStr = Decompress(DecryptAsymmetrical(State.privatekey(), packetStr));
if (packetStr.size() != 1) {
ForceDisconnect();
Config.RegisterResultCallback(RR_ConnectionFailure);
return;
}
ERegisterResult registerResult;
registerResult = (ERegisterResult)packetStr[0];
if (registerResult == RR_Success) {
SaveState();
}
ForceDisconnect();
Config.RegisterResultCallback(registerResult);
return;
}
} break;
case CS_Logining: {
Buffer += data.ToString();
string packetStr;
if (Deserialize(Buffer, packetStr)) {
packetStr = Decompress(packetStr);
TServerLoginPacket packet;
if (!packet.ParseFromString(packetStr)) {
ForceDisconnect();
Config.LoginResultCallback(LR_ConnectionFail);
return;
}
string captcha = packet.captcha();
State.set_serverpublickey(packet.publickey());
Config.CaptchaAvailableCallback(captcha);
}
} break;
case CS_LoginingConfirmWait: {
Buffer += data.ToString();
string packetStr;
if (Deserialize(Buffer, packetStr)) {
packetStr = Decompress(packetStr);
TServerLoginConfirm packet;
if (!packet.ParseFromString(packetStr)) {
ForceDisconnect();
Config.LoginResultCallback(LR_ConnectionFail);
return;
}
if (packet.result() != LR_Success) {
ForceDisconnect();
Config.LoginResultCallback(packet.result());
} else {
assert(packet.has_publickey() && "no public key in packet");
assert(packet.has_encryptedprivatekey() && "no private key in packet");
assert(!Password.empty() && "no password");
State.set_publickey(packet.publickey());
State.set_privatekey(DecryptSymmetrical(GenerateKey(Password), packet.encryptedprivatekey()));
Password.clear();
SaveState();
ForceDisconnect();
Config.LoginResultCallback(packet.result());
}
ForceDisconnect();
}
} break;
case CS_Connecting: {
Buffer += data.ToString();
string packetStr;
if (Deserialize(Buffer, packetStr)) {
packetStr = Decompress(packetStr);
TServerAuthorizeRequest packet;
if (!packet.ParseFromString(packetStr)) {
ForceDisconnect();
Config.ConnectedCallback(false);
return;
}
if (!CheckSignature(State.serverpublickey(), packet.randomsequence(), packet.signature())) {
ForceDisconnect();
Config.ConnectedCallback(false);
return;
}
TClientAuthorizeRequest request;
assert(State.has_login() && "no login in state");
//.........这里部分代码省略.........