C++ edjLibrary SDK
Loading...
Searching...
No Matches
stream.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5#include <vector>
6
7#include "error.hpp"
8
9namespace edjx {
10
12namespace stream {
13
17 class BaseStream {
18 public:
22 inline BaseStream() : initialized(false) {}
28 inline BaseStream(uint32_t sd) : sd(sd), initialized(true) {}
29
37 inline uint32_t get_sd() const {
38 return sd;
39 }
46 bool is_initialized() const {
47 return initialized;
48 }
58 protected:
60 uint32_t sd;
63 };
64
68 class WriteStream : public BaseStream {
69 public:
73 inline WriteStream() {}
79 inline WriteStream(uint32_t sd) : BaseStream(sd) {}
87 edjx::error::StreamError write_chunk(const std::string & text);
95 edjx::error::StreamError write_chunk(const std::vector<uint8_t> & bytes);
96
115 };
116
120 class ReadStream : public BaseStream {
121 public:
125 inline ReadStream() {}
131 inline ReadStream(uint32_t sd) : BaseStream(sd) {}
139 edjx::error::StreamError read_chunk(std::vector<uint8_t> & result);
140
152
162 edjx::error::StreamError read_all(std::vector<uint8_t> & result);
163 };
164
165}}
This is a base class for the streams.
Definition: stream.hpp:17
uint32_t get_sd() const
Get the stream descriptor of the stream.
Definition: stream.hpp:37
BaseStream()
Constructs a new empty Base Stream object.
Definition: stream.hpp:22
bool initialized
True if the stream is initialized, false if it is closed.
Definition: stream.hpp:62
BaseStream(uint32_t sd)
Constructs a new initilized Base Stream object.
Definition: stream.hpp:28
uint32_t sd
The stream descriptor.
Definition: stream.hpp:60
bool is_initialized() const
Check whether the stream object has been initialized or not.
Definition: stream.hpp:46
edjx::error::StreamError close()
Close the stream.
Read stream class.
Definition: stream.hpp:120
edjx::error::StreamError pipe_to(WriteStream &write_stream)
Pipes a read stream into a write stream.
edjx::error::StreamError read_all(std::vector< uint8_t > &result)
Reads and returns all data from the stream until the end of stream.
edjx::error::StreamError read_chunk(std::vector< uint8_t > &result)
Read a chunk of binary data from the stream.
ReadStream()
Constructs a new empty Read Stream object.
Definition: stream.hpp:125
ReadStream(uint32_t sd)
Constructs a new initilized Read Stream object.
Definition: stream.hpp:131
This class represents a write stream.
Definition: stream.hpp:68
edjx::error::StreamError write_chunk(const std::vector< uint8_t > &bytes)
Write a chunk of binary data into the write stream.
edjx::error::StreamError write_chunk(const std::string &text)
Write a chunk of text into the write stream.
edjx::error::StreamError abort()
Aborts sending data and closes the stream.
WriteStream()
Constructs a new empty Write Stream object.
Definition: stream.hpp:73
WriteStream(uint32_t sd)
Constructs a new initilized Write Stream object.
Definition: stream.hpp:79
StreamError
Enum that describes values returned by streaming functions.
Definition: error.hpp:243
Definition: error.hpp:5