Stream.hpp

This File On Github
Ask A Question

API: latest
module: oatpp
#include "oatpp/core/data/stream/Stream.hpp"

IOMode

Stream I/O mode.

namespace oatpp { namespace data { namespace stream { 
  enum IOMode : v_int32;
}}}

IOMode::BLOCKING

Blocking stream I/O mode.

BLOCKING = 0

IOMode::NON_BLOCKING

Non-blocking stream I/O mode.

NON_BLOCKING = 1

OutputStream

Output Stream.

namespace oatpp { namespace data { namespace stream { 
  class OutputStream {}
}}}

Methods

Return Type Name Summary
[none] ~OutputStream Default virtual destructor.
data::v_io_size write Multiple implementations:
  1. Write data to stream up to count bytes, and return number of bytes actually written.
  2. Same as write((p_char8)data, std::strlen(data));.
  3. Same as write(str->getData(), str->getSize());
oatpp::async::Action suggestOutputStreamAction Implementation of OutputStream must suggest async actions for I/O results.
void setOutputStreamIOMode Set stream I/O mode.
IOMode getOutputStreamIOMode Get stream I/O mode.
data::v_io_size writeChar Same as write(c, 1);.

OutputStream::~OutputStream

Default virtual destructor.

virtual ~OutputStream() = default

OutputStream::write

  1. Write data to stream up to count bytes, and return number of bytes actually written.
    It is a legal case if return result < count. Caller should handle this!
    • @param data - data to write.
    • @param count - number of bytes to write.
    • @return - actual number of bytes written. oatpp::data::v_io_size.
    virtual data::v_io_size write(const void *data, data::v_io_size count) = 0
    
  2. Same as write((p_char8)data, std::strlen(data));.
    data::v_io_size write(const char* data)
    
  3. Same as write(str->getData(), str->getSize());
    data::v_io_size write(const oatpp::String& str)
    

OutputStream::suggestOutputStreamAction

Implementation of OutputStream must suggest async actions for I/O results.
Suggested Action is used for scheduling coroutines in async::Executor.
Stream MUST always give the same file-handle if applicable

virtual oatpp::async::Action suggestOutputStreamAction(data::v_io_size ioResult) = 0

OutputStream::setOutputStreamIOMode

Set stream I/O mode.

  • @throws

virtual void setOutputStreamIOMode(IOMode ioMode) = 0

OutputStream::getOutputStreamIOMode

Get stream I/O mode.

  • @return

virtual IOMode getOutputStreamIOMode() = 0

OutputStream::writeChar

Same as write(c, 1);.

data::v_io_size writeChar(v_char8 c)

InputStream

Input Stream.

namespace oatpp { namespace data { namespace stream { 
  class InputStream {}
}}}

Methods

Return Type Name Summary
[none] ~InputStream Default virtual destructor.
data::v_io_size read Read data from stream up to count bytes, and return number of bytes actually read.
oatpp::async::Action suggestInputStreamAction Implementation of InputStream must suggest async actions for I/O results.
void setInputStreamIOMode Set stream I/O mode.
IOMode getInputStreamIOMode Get stream I/O mode.

InputStream::~InputStream

Default virtual destructor.

virtual ~InputStream() = default

InputStream::read

Read data from stream up to count bytes, and return number of bytes actually read.
It is a legal case if return result < count. Caller should handle this!

  • @param data - buffer to read dat to.
  • @param count - size of the buffer.
  • @return - actual number of bytes read.

virtual data::v_io_size read(void *data, data::v_io_size count) = 0

InputStream::suggestInputStreamAction

Implementation of InputStream must suggest async actions for I/O results.
Suggested Action is used for scheduling coroutines in async::Executor.
Stream MUST always give the same file-handle if applicable

virtual oatpp::async::Action suggestInputStreamAction(data::v_io_size ioResult) = 0

InputStream::setInputStreamIOMode

Set stream I/O mode.

  • @throws

virtual void setInputStreamIOMode(IOMode ioMode) = 0

InputStream::getInputStreamIOMode

Get stream I/O mode.

  • @return

virtual IOMode getInputStreamIOMode() = 0

IOStream

I/O Stream.

namespace oatpp { namespace data { namespace stream { 
  class IOStream : public InputStream, public OutputStream {}
}}}

ConsistentOutputStream

Streams that guarantee data to be written in exact amount as specified in call to OutputStream::write() should extend this class.

namespace oatpp { namespace data { namespace stream { 
  class ConsistentOutputStream : public OutputStream {}
}}}

Methods

Return Type Name Summary
oatpp::async::Action suggestOutputStreamAction This should never be called. Call to implementation of this particular method will throw std::runtime_error.
data::v_io_size writeAsString Multiple implementations:
  1. Convert value to string and write to stream.
  2. Convert value to string and write to stream.
  3. Convert value to string and write to stream.
  4. Convert value to string and write to stream.
  5. Convert value to string and write to stream.

ConsistentOutputStream::suggestOutputStreamAction

This should never be called. Call to implementation of this particular method will throw std::runtime_error.
No suggestions for ConsistentOutputStream async I/O operations are needed.
ConsistentOutputStream always fully satisfies call to write() method.

  • @param ioResult - result of call to write() method.
  • @return - oatpp::async::Action.
  • @throws - std::runtime_error

oatpp::async::Action suggestOutputStreamAction(data::v_io_size ioResult) override

ConsistentOutputStream::writeAsString

  1. Convert value to string and write to stream.
    data::v_io_size writeAsString(v_int32 value)
    
  2. Convert value to string and write to stream.
    data::v_io_size writeAsString(v_int64 value)
    
  3. Convert value to string and write to stream.
    data::v_io_size writeAsString(v_float32 value)
    
  4. Convert value to string and write to stream.
    data::v_io_size writeAsString(v_float64 value)
    
  5. Convert value to string and write to stream.
    data::v_io_size writeAsString(bool value)
    

transfer

Namespace: oatpp::data::stream

Read bytes from fromStream" and write to toStream" using buffer of size bufferSize transfer up to transferSize or until error if transferSize == 0 throws in case readCount != writeCount

oatpp::data::v_io_size transfer(const std::shared_ptr<InputStream>& fromStream,
                                const std::shared_ptr<OutputStream>& toStream,
                                oatpp::data::v_io_size transferSize,
                                void* buffer,
                                oatpp::data::v_io_size bufferSize)

transferAsync

Namespace: oatpp::data::stream

Same as transfer but asynchronous

oatpp::async::CoroutineStarter transferAsync(const std::shared_ptr<InputStream>& fromStream,
                                             const std::shared_ptr<OutputStream>& toStream,
                                             oatpp::data::v_io_size transferSize,
                                             const std::shared_ptr<oatpp::data::buffer::IOBuffer>& buffer)

readExactSizeData

Namespace: oatpp::data::stream

Read exact amount of bytes to stream returns exact amount of bytes was read. return result can be < size only in case of some disaster like connection reset by peer

oatpp::data::v_io_size readExactSizeData(oatpp::data::stream::InputStream* stream, void* data, data::v_io_size size)

writeExactSizeData

Namespace: oatpp::data::stream

Write exact amount of bytes to stream. returns exact amount of bytes was written. return result can be < size only in case of some disaster like broken pipe

oatpp::data::v_io_size writeExactSizeData(oatpp::data::stream::OutputStream* stream, const void* data, data::v_io_size size)