Google APIs Client Library for C++
|
Interface for writing into synchronous binary data stream. More...
#include "client/data/data_writer.h"
Public Member Functions | |
virtual | ~DataWriter () |
Standard destructor. | |
int64 | size () const |
Returns the number of bytes written into the stream. | |
bool | ok () const |
Determine if we've encountered a hard error or not. | |
const util::Status & | status () const |
Returns details for the error on the stream, if any. | |
void | Clear () |
Clears any prior data writen into the stream so that it is empty. | |
void | Begin () |
Notifies the writer that it is startimg to write a stream. | |
util::Status | Write (int64 size, const char *data) |
Synchronously write a fixed number of bytes into the stream. | |
util::Status | Write (const StringPiece &data) |
Synchronously write a fixed number of bytes into the stream. | |
void | End () |
Notifies the writer that it has finished writing a stream. | |
DataReader * | NewUnmanagedDataReader () |
Returns an unmanaged data reader that will read the content written to this writer's byte stream. | |
DataReader * | NewManagedDataReader (Closure *deleter) |
Returns a managed data reader that will read this content. | |
Protected Member Functions | |
DataWriter () | |
Standard constructor. | |
void | set_status (util::Status status) |
Sets the status as a means to pass error details back to the caller. | |
virtual util::Status | DoBegin () |
Hook for specialized writers to respond to Begin. | |
virtual util::Status | DoEnd () |
Hook for specialized writes to respond to End. | |
virtual util::Status | DoClear () |
Hook for specialized writers to clear the byte stream. | |
virtual util::Status | DoWrite (int64 bytes, const char *data)=0 |
Hook for the specialied writers to write into their byte stream. | |
virtual DataReader * | DoNewDataReader (Closure *closure)=0 |
Factory method to create new reader specialized for the writer's byte stream implementation. |
Interface for writing into synchronous binary data stream.
The DataWriter is the base class for writing non-trivial data using a streaming-like interface. Writers can act as reader factories if you need to read-back what had been written from within the same process. For example streaming HTTP responses into files then reading them back to handle them.
virtual ~DataWriter | ( | ) | [virtual] |
Standard destructor.
DataWriter | ( | ) | [protected] |
Standard constructor.
void Clear | ( | ) |
Clears any prior data writen into the stream so that it is empty.
TODO(ewiseblatt): 20130306 I'm not sure what clear means yet. Should it delete files or any other side effects? This is needed to reset a response, such as when retrying.
virtual util::Status DoBegin | ( | ) | [protected, virtual] |
Hook for specialized writers to respond to Begin.
The base class just returns ok.
virtual util::Status DoClear | ( | ) | [protected, virtual] |
Hook for specialized writers to clear the byte stream.
The base class just returns ok.
virtual util::Status DoEnd | ( | ) | [protected, virtual] |
Hook for specialized writes to respond to End.
The base class just returns ok.
virtual DataReader* DoNewDataReader | ( | Closure * | closure | ) | [protected, pure virtual] |
Factory method to create new reader specialized for the writer's byte stream implementation.
[in] | closure | If non-NULL then create a managed reader with the closure. |
virtual util::Status DoWrite | ( | int64 | bytes, |
const char * | data | ||
) | [protected, pure virtual] |
Hook for the specialied writers to write into their byte stream.
[in] | bytes | The number of bytes in data to write. |
[in] | data | The data to write into the byte stream. |
DataReader* NewManagedDataReader | ( | Closure * | deleter | ) |
Returns a managed data reader that will read this content.
DataReader* NewUnmanagedDataReader | ( | ) | [inline] |
Returns an unmanaged data reader that will read the content written to this writer's byte stream.
Depending on the writer, this may only be valid over the lifetime of the writer. If you arent sure, use instead:
writer->NewManagedDataReader(DeletePointerClosure(writer))
That effectively transfers ownership of the writer to the reader so can only be requested once.
bool ok | ( | ) | const [inline] |
Determine if we've encountered a hard error or not.
void set_status | ( | util::Status | status | ) | [inline, protected] |
Sets the status as a means to pass error details back to the caller.
Setting an error implies setting done as well. However clearing an error by setting an ok status will not clear done. To clear the done state you must explicitly call set_done.
[in] | status | An error implies a hard failure and will mark the ader done. |
int64 size | ( | ) | const [inline] |
Returns the number of bytes written into the stream.
const util::Status& status | ( | ) | const [inline] |
Returns details for the error on the stream, if any.
util::Status Write | ( | int64 | size, |
const char * | data | ||
) |
Synchronously write a fixed number of bytes into the stream.
If Begin had not been called already then this will call Begin first.
[in] | size | The number of bytes to write. |
[in] | data | The data to write. |
util::Status Write | ( | const StringPiece & | data | ) | [inline] |
Synchronously write a fixed number of bytes into the stream.
[in] | data | The string piece encapsulates the size and data to write. |