unique_ptr<HTTPArchive> HTTPArchive::fromFile(const string& filename) { unique_ptr<HTTPArchive> har = std::make_unique<HTTPArchive>(); auto buffer = readFileToIOBuf(filename); if (!buffer) { return nullptr; } folly::dynamic jsonObj = folly::parseJson((const char *)buffer->data()); auto entries = jsonObj["log"]["entries"]; // go over all the transactions for (size_t i = 0; i < entries.size(); i++) { HTTPMessage msg = extractMessage(entries[i]["request"], entries[i]["startedDateTime"].asString(), true); if (msg.getHeaders().size() != 0) { har->requests.push_back(msg); } msg = extractMessage(entries[i]["response"], "", false); if (msg.getHeaders().size() != 0) { har->responses.push_back(msg); } } return har; }
/* In the main method the arrays that will hold the integers and later the binary encoded messages are created. Other functions are called to perform the operations involved in changing an integer to an encoded binary number. */ int main(int argc, char *argv[]) { int maxnumbers = 500, codelength = 21, i, binlen; int numbers[maxnumbers]; readMessage(numbers, maxnumbers); binlen = LengthOfFile(numbers); char binary[binlen][codelength]; char encodedbinary[binlen][codelength]; puts("The inputs in the file have been encoded with the Hamming code technique."); for(i = 0; i < binlen; i++) { extractMessage(numbers[i], binary[i]); makeMessage(binary[i], encodedbinary[i], binlen, codelength); } }
void TcpRpcChannel::dataReceived(const boost::system::error_code& ec, std::size_t bytes_transferred) { if (ec) { GOOGLE_LOG(ERROR) << "fail to receive data from server"; startConnect(); return; } GOOGLE_LOG(INFO) << "received " << bytes_transferred << " bytes from server"; receivedMsg_.append(msgBuffer_, bytes_transferred); startRead(); string msg; while (extractMessage(msg)) { responseReceived(msg); } }