Google APIs Client Library for C++
DataWriter Class Reference

Interface for writing into synchronous binary data stream. More...

#include "client/data/data_writer.h"

List of all members.

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::Statusstatus () 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.
DataReaderNewUnmanagedDataReader ()
 Returns an unmanaged data reader that will read the content written to this writer's byte stream.
DataReaderNewManagedDataReader (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 DataReaderDoNewDataReader (Closure *closure)=0
 Factory method to create new reader specialized for the writer's byte stream implementation.

Detailed Description

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.

See also:
NewStringDataWriter
NewFileDataWriter TODO(ewiseblatt): 20130418 Consider adding << operator

Constructor & Destructor Documentation

virtual ~DataWriter ( ) [virtual]

Standard destructor.

DataWriter ( ) [protected]

Standard constructor.


Member Function Documentation

void Begin ( )

Notifies the writer that it is startimg to write a stream.

See also:
DoBegin
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.

Parameters:
[in]closureIf 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.

Parameters:
[in]bytesThe number of bytes in data to write.
[in]dataThe data to write into the byte stream.
Returns:
success if all the bytes could be written, or an error.
void End ( )

Notifies the writer that it has finished writing a stream.

See also:
DoEnd
DataReader* NewManagedDataReader ( Closure *  deleter)

Returns a managed data reader that will read this content.

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.

Returns:
true if no hard error has been set, false if an error.
See also:
error
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.

Parameters:
[in]statusAn 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.

Returns:
a successful status if the stream is ok, otherwise the error encounteredd.
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.

Parameters:
[in]sizeThe number of bytes to write.
[in]dataThe data to write.
See also:
DoWrite
util::Status Write ( const StringPiece &  data) [inline]

Synchronously write a fixed number of bytes into the stream.

Parameters:
[in]dataThe string piece encapsulates the size and data to write.
See also:
DoWrite

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines