/*
{{copyright}} 
*/

/*
{{version}} 
*/

/*
{{license}} 
*/

#pragma once

#include <chrono>
#include <cstdint>
#include <span>

namespace sdi_uToolBox::generic
{
//--------------------------------------------------------------
class IStream
{
  public:
  IStream()                                    = default;     // Constructor
  virtual ~IStream()                           = default;     // Destructor
  IStream(const IStream &other)                = delete;      // Copy constructor
  IStream(IStream &&other) noexcept            = delete;      // Move constructor
  IStream &operator=(const IStream &other)     = delete;      // Copy assignment
  IStream &operator=(IStream &&other) noexcept = delete;      // Move assignment

  virtual size_t write(const std::span<const uint8_t> buffer) = 0;                              // Writes a block of data to the stream
  virtual size_t read(const std::span<uint8_t> buffer)        = 0;                              // Reads a block of data from the stream
  virtual size_t read(const std::span<uint8_t> buffer, const std::chrono::milliseconds ms);     // If available, wait for block of data from the stream

  virtual bool isDataAvailable() const = 0;     // Checks if the stream has data available for reading
};
//--------------------------------------------------------------

//--------------------------------------------------------------
/* If available, wait for block of data from the stream */
inline size_t IStream::read(const std::span<uint8_t> buffer, const std::chrono::milliseconds ms)
{
  return read(buffer);
}
//--------------------------------------------------------------
}     // namespace sdi_uToolBox::generic
