The cqg_api.Request message provides access to the new CQG data delivery system. Specific requests are defined in the cqg_api folder and protobuf package.
Each request in the cqg_api package has the request_type_id and request_protocol_version custom options.
message ExampleRequest
{
option (request_type_id) =
100;
option (request_protocol_version) = 1;
// Request
parameter
uint32 example_id = 1;
}
The values of the custom options must be used when filling the cqg_api.Request message:
WebAPI_2::ClientMsg client_msg;
cqg_api::Request* cqg_request = client_msg.add_cqg_requests();
cqg_request->set_request_id(1);
cqg_request->set_request_kind(cqg_api::Request::KIND_GET);
cqg_request->set_request_protocol_version(
cqg_api::ExampleRequest::GetDescriptor()->options().GetExtension(
cqg_api::request_protocol_version));
cqg_request->set_request_type_id(
cqg_api::ExampleRequest::GetDescriptor()->options().GetExtension(
cqg_api::request_type_id));
cqg_api::ExampleRequest
example_request;
example_request.set_example_id(123);
cqg_request->set_serialized_request(example_request.SerializeAsString());
Each report in the cqg_api package has the report_type_id custom option, which is always equal to the request_type_id of the corresponding request.
message ExampleReport
{
option (report_type_id) =
100;
Example example = 1;
}
The report_type_id value should be used when parsing a specific report in the cqg_api.Report message:
cqg_api::ExampleReport parse_example_report(const cqg_api::Report& cqg_report)
{
cqg_api::ExampleReport report;
if (cqg_report.has_serialized_report())
{
if (cqg_report.report_type_id() != cqg_api::ExampleReport::
GetDescriptor()->options().GetExtension(cqg_api::report_type_id))
{
throw std::runtime_error("Unexpected report type");
}
if (!report.ParseFromString(cqg_report.serialized_report()))
{
throw std::runtime_error("Failed to parse ExampleReport");
}
}
return report;
}
Client Message:
{
"cqg_requests": [
{
"request_id": 1,
"request_kind": 1,
"request_protocol_version": 1,
"request_type_id": 100,
"serialized_request (ExampleRequest)": {
"example_id": 123
}
}
]
}
Server Response:
{
"cqg_reports": [
{
"request_ids": [1],
"status_code": 5,
"report_type_id": 100,
"serialized_report (ExampleReport)": {
"example": {
"example_id": 123
}
}
}
]
}
In most cases, the request_ids field contains a single ID. Special cases involving multiple IDs are described in the comments of the corresponding request types.