virtual bool InitFilter() = 0;
Called to filter a chunk of data. Expected usage is as follows:
A. Read input data from |data_in| and set |data_in_read| to the number of
bytes that were read up to a maximum of |data_in_size|. |data_in| will
be NULL if |data_in_size| is zero.
B. Write filtered output data to |data_out| and set |data_out_written| to
the number of bytes that were written up to a maximum of
|data_out_size|. If no output data was written then all data must be
read from |data_in| (user must set |data_in_read| = |data_in_size|).
C. Return RESPONSE_FILTER_DONE if all output data was written or
RESPONSE_FILTER_NEED_MORE_DATA if output data is still pending.
To be honest - this description is completely unclear.
See, if you follow these instructions, the code will be as follows:
A. Read input data from |data_in| and set |data_in_read| to the number of bytes that were read up to a maximum of |data_in_size|. |data_in| will be NULL if |data_in_size| is zero.
Well I do this:
- Code: Select all
class my_filter : public CefResponseFilter
{
public:
CefResponseFilter::FilterStatus Filter(void* data_in, size_t data_in_size, size_t& data_in_read, void* data_out, size_t data_out_size, size_t& data_out_written)
{
data_in_read = data_in_size;
}
}
Next:
B. Write filtered output data to |data_out| and set |data_out_written| to the number of bytes that were written up to a maximum of |data_out_size|. If no output data was written then all data must be read from |data_in| (user must set |data_in_read| = |data_in_size|).
Well I do this again:
- Code: Select all
class my_filter : public CefResponseFilter
{
public:
CefResponseFilter::FilterStatus Filter(void* data_in, size_t data_in_size, size_t& data_in_read, void* data_out, size_t data_out_size, size_t& data_out_written)
{
data_in_read = data_in_size;
//----------------------------------
size_t my_min= std::min(data_out_size, data_in_read);
data_out_written = my_min;
memcpy(data_out, data_in, my_min);
//----------------------------------
}
}
However - this code will not work !!
Because point A is not written correctly.
The correct code for point A should be as follows:
- Code: Select all
class my_filter : public CefResponseFilter
{
public:
CefResponseFilter::FilterStatus Filter(void* data_in, size_t data_in_size, size_t& data_in_read, void* data_out, size_t data_out_size, size_t& data_out_written)
{
size_t my_min_ = std::min(data_out_size, data_in_size);
data_in_read = my_min_;
}
}