Google APIs Client Library for C++
|
A helper class for implementing CodecReaders. More...
#include "client/data/codec.h"
Public Member Functions | |
CodecReader (DataReader *source, Closure *deleter, int64 chunk_size, int64 buffer_size, bool encoding) | |
Standard constructor. | |
virtual | ~CodecReader () |
Standard destructor. | |
virtual util::Status | Init () |
Called when resetting readers (seeking to start) | |
Protected Member Functions | |
bool | encoding () const |
Returns whether the reader was constructed for encoding or decoding. | |
virtual int64 | DoReadToBuffer (int64 max_bytes, char *storage) |
Reads from internal transformed buffer, replentishing it as necessary. | |
virtual int64 | DoSetOffset (int64 to_offset) |
Implements seeking through the transformed stream. | |
virtual util::Status | EncodeChunk (const StringPiece &from, bool final, char *to, int64 *to_len)=0 |
Hook for codecs to encode a chunk. | |
virtual util::Status | DecodeChunk (const StringPiece &from, bool final, char *to, int64 *to_len)=0 |
Hook for codecs to decode a chunk. |
A helper class for implementing CodecReaders.
This class assumes bounded transformation sizes for a given input size.
CodecReader | ( | DataReader * | source, |
Closure * | deleter, | ||
int64 | chunk_size, | ||
int64 | buffer_size, | ||
bool | encoding | ||
) |
Standard constructor.
[in] | source | The untarnsformed stream the codec is processing. |
[in] | deleter | The deleter if this is to be a managed stream. |
[in] | chunk_size | The size of source data to accumulate for each transform (until the very last one) |
[in] | buffer_size | The size to allocate for transformed data. |
[in] | encoding | Whether this reader is encoding or decoding determines whether we'll EncodeChunk or DecodeChunk. |
virtual ~CodecReader | ( | ) | [virtual] |
Standard destructor.
virtual util::Status DecodeChunk | ( | const StringPiece & | from, |
bool | final, | ||
char * | to, | ||
int64 * | to_len | ||
) | [protected, pure virtual] |
Hook for codecs to decode a chunk.
[in] | from | The raw chunk from the source stream. |
[in] | final | True if this is the final chunk. |
[in] | to | The target buffer must be allocated big enough. |
[in,out] | to_len | The size of the 'to' buffer on input. The amount of data written into 'to' on output. |
virtual int64 DoReadToBuffer | ( | int64 | max_bytes, |
char * | storage | ||
) | [protected, virtual] |
Reads from internal transformed buffer, replentishing it as necessary.
This method is compliant with the base DataReader::DoReadToBuffer semantics. In particular, results are never non-negative and 0 does not have any special meaning with regard to errors or being done.
[in] | max_bytes | Max bytes to copy from buffer. |
[in] | storage | The storage to read into. |
Implements DataReader.
virtual int64 DoSetOffset | ( | int64 | to_offset | ) | [protected, virtual] |
Implements seeking through the transformed stream.
This method is compliant with the base DataReader::DoSetOffset semantics.
Reimplemented from DataReader.
virtual util::Status EncodeChunk | ( | const StringPiece & | from, |
bool | final, | ||
char * | to, | ||
int64 * | to_len | ||
) | [protected, pure virtual] |
Hook for codecs to encode a chunk.
[in] | from | The raw chunk from the source stream. |
[in] | final | True if this is the final chunk. |
[in] | to | The target buffer must be allocated big enough. |
[in,out] | to_len | The size of the 'to' buffer on input. The amount of data written into 'to' on output. |
bool encoding | ( | ) | const [inline, protected] |
Returns whether the reader was constructed for encoding or decoding.
virtual util::Status Init | ( | ) | [virtual] |
Called when resetting readers (seeking to start)