Skip to content
Snippets Groups Projects
Commit b8823a0b authored by Michael Davis's avatar Michael Davis
Browse files

[ssi_af_ls] Constructs coded input stream directly from buffer

parent 065e101d
No related branches found
No related tags found
No related merge requests found
......@@ -54,21 +54,33 @@ void RequestCallback<cta::xrd::Alert>::operator()(const cta::xrd::Alert &alert)
template<>
void XrdSsiPbRequestType::DataCallback(XrdSsiRequest::PRD_Xeq &post_process, char *response_bufptr, int response_buflen)
{
google::protobuf::io::ArrayInputStream raw_stream(response_bufptr, response_buflen);
google::protobuf::io::CodedInputStream coded_stream(&raw_stream);
google::protobuf::io::CodedInputStream coded_stream(reinterpret_cast<const uint8_t*>(response_bufptr), response_buflen);
cta::admin::ArchiveFileLsItem line_item;
uint32_t bytesize;
int buf_len;
do {
do
{
const char *buf_ptr;
coded_stream.GetDirectBufferPointer(reinterpret_cast<const void**>(&buf_ptr), &buf_len);
std::cout << "buf_len = " << buf_len << std::endl;
if(buf_len < static_cast<int>(sizeof(uint32_t))) {
throw std::runtime_error("Not enough data to read size of next protobuf");
}
coded_stream.ReadLittleEndian32(&bytesize);
std::cout << "Bytesize = " << bytesize << std::endl;
const char *buf_ptr;
coded_stream.GetDirectBufferPointer(reinterpret_cast<const void**>(&buf_ptr), &buf_len);
std::cout << "buf_len = " << buf_len << std::endl;
if(buf_len < static_cast<int>(bytesize)) {
throw std::runtime_error("Not enough data in stream");
}
line_item.ParseFromArray(buf_ptr, bytesize);
coded_stream.Skip(bytesize);
......@@ -90,7 +102,7 @@ std::cout << "buf_len = " << buf_len << std::endl;
<< std::setfill(' ') << std::setw(13) << std::right << line_item.af().creation_time() << ' '
<< line_item.af().df().path() << std::endl;
}
while(static_cast<int>(bytesize) != buf_len);
while(buf_len != static_cast<int>(bytesize));
}
......
......@@ -40,11 +40,10 @@ namespace XrdSsiPb {
// Constants
const unsigned int DefaultResponseBufferSize = 1024; //!< Default size for the response buffer in bytes
const unsigned int DefaultResponseBufferSize = 89; //!< Default size for the response buffer in bytes
const unsigned int DefaultRequestTimeout = 15; //!< Default XRootD request timeout in secs
// Better to get the default from XRD_REQUESTTIMEOUT if it is not set explicitly?
// Decide on order of precedence for setting request timeout
// What about setting stream timeout?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment