36 #define S3_TRACKING_CONTEXT "cloudydap"
41 size_t chunk_header_callback(
char *buffer,
size_t size,
size_t nitems,
void *data);
42 size_t chunk_write_data(
void *buffer,
size_t size,
size_t nmemb,
void *data);
52 std::string d_data_url;
53 std::string d_query_marker;
54 std::string d_byte_order;
55 unsigned long long d_size;
56 unsigned long long d_offset;
58 std::vector<unsigned int> d_chunk_position_in_array;
80 bool d_read_buffer_is_mine;
81 unsigned long long d_bytes_read;
83 unsigned long long d_read_buffer_size;
86 std::string d_response_content_type;
90 friend class ChunkTest;
91 friend class DmrppCommonTest;
92 friend class MockChunk;
96 void _duplicate(
const Chunk &bs)
99 d_read_buffer_is_mine =
true;
101 d_read_buffer =
nullptr;
102 d_read_buffer_size = 0;
104 d_is_inflated =
false;
107 d_offset = bs.d_offset;
108 d_data_url = bs.d_data_url;
109 d_byte_order = bs.d_byte_order;
110 d_query_marker = bs.d_query_marker;
111 d_chunk_position_in_array = bs.d_chunk_position_in_array;
126 d_data_url(
""), d_query_marker(
""), d_byte_order(
""), d_size(0), d_offset(0),
127 d_read_buffer_is_mine(true), d_bytes_read(0), d_read_buffer(nullptr),
128 d_read_buffer_size(0), d_is_read(false), d_is_inflated(false)
142 Chunk(std::string data_url, std::string order,
unsigned long long size,
unsigned long long offset,
143 const std::string &pia_str =
"") :
144 d_data_url(std::move(data_url)), d_query_marker(
""),
145 d_byte_order(std::move(order)), d_size(size), d_offset(offset),
146 d_read_buffer_is_mine(true), d_bytes_read(0), d_read_buffer(nullptr),
147 d_read_buffer_size(0), d_is_read(false), d_is_inflated(false)
163 Chunk(std::string data_url, std::string order,
unsigned long long size,
164 unsigned long long offset,
const std::vector<unsigned int> &pia_vec) :
165 d_data_url(std::move(data_url)), d_query_marker(
""), d_byte_order(std::move(order)), d_size(size), d_offset(offset),
166 d_read_buffer_is_mine(true), d_bytes_read(0), d_read_buffer(nullptr),
167 d_read_buffer_size(0), d_is_read(false), d_is_inflated(false)
180 if(d_read_buffer_is_mine)
181 delete[] d_read_buffer;
182 d_read_buffer =
nullptr;
191 if (
this == &rhs)
return *
this;
233 d_data_url = data_url;
250 d_bytes_read = bytes_read;
269 if(d_read_buffer_is_mine)
270 delete[] d_read_buffer;
272 d_read_buffer =
new char[d_size];
273 d_read_buffer_size = d_size;
274 d_read_buffer_is_mine =
true;
284 return d_read_buffer;
301 virtual void set_rbuf(char *buf, unsigned int buf_size)
303 if(d_read_buffer_is_mine)
304 delete[] d_read_buffer;
307 d_read_buffer_size = buf_size;
326 unsigned long long buf_size,
327 unsigned long long bytes_read = 0,
328 bool assume_ownership =
true ){
330 if(d_read_buffer_is_mine)
331 delete[] d_read_buffer;
333 d_read_buffer_is_mine = assume_ownership;
335 d_read_buffer_size = buf_size;
345 return d_read_buffer_size;
353 return d_chunk_position_in_array;
363 virtual void inflate_chunk(
bool deflate,
bool shuffle,
unsigned int chunk_size,
unsigned int elem_width);
365 virtual bool get_is_read() {
return d_is_read; }
366 virtual void set_is_read(
bool state) { d_is_read = state; }
373 static void parse_chunk_position_in_array_string(
const std::string &pia, std::vector<unsigned int> &pia_vect);
375 virtual void dump(std::ostream & strm)
const;
377 virtual std::string to_string()
const;
382 struct inflate_chunk_args {
386 unsigned int chunk_size;
387 unsigned int elem_width;
389 inflate_chunk_args(Chunk *c,
bool d,
bool s,
unsigned int c_size,
unsigned int e_size):
390 chunk(c), deflate(d), shuffle(s), chunk_size(c_size), elem_width(e_size) {}
393 void *inflate_chunk(
void *args);
virtual void set_bytes_read(unsigned long long bytes_read)
Set the size of this Chunk's data block.
virtual void dump(std::ostream &strm) const
Chunk(std::string data_url, std::string order, unsigned long long size, unsigned long long offset, const std::vector< unsigned int > &pia_vec)
Get a chunk initialized with values.
virtual void set_data_url(const std::string &data_url)
Set the data url string for this Chunk's data block.
virtual void read_chunk()
void add_tracking_query_param()
Modify this chunk's data URL so that it includes tracking info.
virtual std::string get_response_content_type()
Get the response type of the last response.
virtual std::string get_byte_order()
Get the chunk byte order.
virtual void inflate_chunk(bool deflate, bool shuffle, unsigned int chunk_size, unsigned int elem_width)
Decompress data in the chunk, managing the Chunk's data buffers.
virtual std::string get_curl_range_arg_string()
Returns a curl range argument. The libcurl requires a string argument for range-ge activitys,...
Chunk(std::string data_url, std::string order, unsigned long long size, unsigned long long offset, const std::string &pia_str="")
Get a chunk initialized with values.
virtual std::string get_data_url() const
Get the data url string for this Chunk's data block.
Chunk & operator=(const Chunk &rhs)
Chunk()
Get an empty chunk.
virtual const std::vector< unsigned int > & get_position_in_array() const
virtual void set_rbuf_to_size()
Allocates the internal read buffer to be d_size bytes.
virtual unsigned long long get_offset() const
Get the offset to this Chunk's data block.
virtual unsigned long long get_bytes_read() const
Get the number of bytes read so far for this Chunk.
void set_position_in_array(const std::string &pia)
parse the chunk position string
virtual unsigned long long get_rbuf_size() const
virtual unsigned long long get_size() const
Get the size of this Chunk's data block on disk.
virtual char * get_rbuf()
void set_read_buffer(char *buf, unsigned long long buf_size, unsigned long long bytes_read=0, bool assume_ownership=true)
Set the target read buffer for this chunk.
void set_response_content_type(const std::string &ct)
Set the response type of the last response.