PL::Stream class

class Stream : public virtual PL::Lockable

Stream class.

Subclassed by PL::NetworkStream, PL::Uart

Public Functions

inline Stream()

Creates a stream.

virtual esp_err_t Read(void *dest, size_t size) = 0

Reads the data from the stream.

Parameters:
  • dest – destination (can be NULL)

  • size – number of bytes to read

Returns:

error code

esp_err_t Read(Buffer &dest, size_t offset, size_t size)

Reads the data from the stream to the buffer.

Parameters:
  • dest – destination buffer

  • offset – destination buffer offset

  • size – number of bytes to read

Returns:

error code

esp_err_t ReadUntil(void *dest, size_t maxSize, char termChar, size_t *size)

Reads the data from the stream up to the specified termination character.

Parameters:
  • dest – destination (can be NULL)

  • maxSize – maximum number of bytes to read

  • termChar – termination character

  • size – number of bytes read

Returns:

error code

esp_err_t ReadUntil(Buffer &dest, size_t offset, char termChar, size_t *size)

Reads the data from the stream to the buffer up to the specified termination character.

Parameters:
  • dest – destination buffer

  • offset – destination buffer offset

  • termChar – termination character

  • size – number of bytes read

Returns:

error code

esp_err_t ReadUntil(char termChar)

Reads the data from the stream up to the specified termination character.

Parameters:

termChar – termination character

Returns:

error code

virtual esp_err_t Write(const void *src, size_t size) = 0

Writes the data to the stream.

Parameters:
  • src – source

  • size – number of bytes to write

Returns:

error code

esp_err_t Write(Buffer &src, size_t offset, size_t size)

Writes the data from the buffer to the stream.

Parameters:
  • src – source buffer

  • offset – source buffer offset

  • size – number of bytes to write

Returns:

error code

esp_err_t Write(const std::string &src)

Writes the string to the stream.

Parameters:

src – source string

Returns:

error code

esp_err_t FlushReadBuffer(TickType_t time = 0)

Discards the data in the read buffer until no data is received for the specified period of time.

Parameters:

time – time

Returns:

error code

virtual size_t GetReadableSize() = 0

Gets the number of bytes that are available for reading from the stream.

Returns:

number of bytes

virtual TickType_t GetReadTimeout() = 0

Gets the read operation timeout.

Returns:

timeout in FreeRTOS ticks

virtual esp_err_t SetReadTimeout(TickType_t timeout) = 0

Sets the read operation timeout.

Parameters:

timeout – timeout in FreeRTOS ticks

Returns:

error code

virtual esp_err_t Lock(TickType_t timeout = portMAX_DELAY) = 0

Locks the object.

Parameters:

timeout – timeout in FreeRTOS ticks

Returns:

error code

virtual esp_err_t Unlock() = 0

Unlocks the object.

Returns:

error code