PLCnext API Documentation  22.0.0.43
RscStream.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Rsc/Services/Rsc.h"
8 #include "Arp/System/Rsc/Services/RemotingReader.hpp"
9 #include "Arp/System/Rsc/Services/RemotingWriter.hpp"
10 #include "Arp/System/Commons/Io/Stream.hpp"
11 
12 namespace Arp { namespace System { namespace Rsc { namespace Services
13 {
14 
15 
19 class RscStream
20 {
21 public: // usings
23 
24 public: // construction/destruction
26  RscStream(void) = default;
27 
32  RscStream(RemotingWriter& writer);
33 
38  RscStream(RemotingReader& reader);
39 
41  RscStream(const RscStream& rscStream) = default;
42 
44  ~RscStream(void) = default;
45 
46 public: // setter/getter
50  bool HasWriter(void)const;
51 
55  bool HasReader(void)const;
56 
61  void SetWriter(RemotingWriter* pValue);
62 
67  void SetReader(RemotingReader* pValue);
68 
69 public: // Read operations (only allowed with RemotingReader set)
73  void BeginRead(void);
74 
81  size_t Read(byte* pBuffer, size_t bufferSize);
82 
86  void Skip(void);
87 
91  void DeserializeTo(Stream& stream);
92 
93 public: // Write operations (only allowed if RemotingWriter is set)
97  void BeginWrite(void);
98 
104  void Write(const byte* pBuffer, size_t bufferCount);
105 
109  void Flush(void);
110 
114  void SerializeFrom(Stream& stream);
115 
116 private: // fields
117  RemotingWriter* pWriter = nullptr;
118  RemotingReader* pReader = nullptr;
119  bool initialized = false;
120  int count = 0;
121  int remaining = 0;
122 
123 private: // static fields
124  static constexpr int MaxPacketSize = std::numeric_limits<int>::max();
125  static constexpr size_t BufferSize = 4096;
126 };
127 
129 // inline methods of class RscStream
130 inline RscStream::RscStream(RemotingWriter& writer)
131  : pWriter(&writer)
132 {
133 }
134 
135 inline RscStream::RscStream(RemotingReader& reader)
136  : pReader(&reader)
137 {
138 }
139 
140 inline bool RscStream::HasWriter()const
141 {
142  return this->pWriter != nullptr;
143 }
144 
145 inline bool RscStream::HasReader()const
146 {
147  return this->pReader != nullptr;
148 }
149 
150 inline void RscStream::SetWriter(RemotingWriter * value)
151 {
152  this->pWriter = value;
153 }
154 
155 inline void RscStream::SetReader(RemotingReader* value)
156 {
157  this->pReader = value;
158 }
159 }}}} // end of namespace Arp::System::Rsc::Services
RscStream(void)=default
Constructs an instance of RscStream
void BeginWrite(void)
Begins the write operation
void SetReader(RemotingReader *pValue)
Sets RemotingReader needed to read stream data
Definition: RscStream.hpp:155
void SetWriter(RemotingWriter *pValue)
Sets RemotingWriter needed to write stream data
Definition: RscStream.hpp:150
bool HasReader(void) const
Determines if this instance is able to reade.
Definition: RscStream.hpp:145
void Flush(void)
Ends the read writer operation and writes remaining internal buffered bytes
~RscStream(void)=default
Destructs this instance and frees all resources.
void DeserializeTo(Stream &stream)
Deserialize the stream data and copies it to the as agument passed stream
bool HasWriter(void) const
Determines if this instance is able to write.
Definition: RscStream.hpp:140
void Write(const byte *pBuffer, size_t bufferCount)
Writes data into stream
Provides a generic view of a sequence of bytes.
Definition: Stream.hpp:19
void Skip(void)
Skips the entire stream and disposes the read data
size_t Read(byte *pBuffer, size_t bufferSize)
Reads up to bufferSize byte into memory referenced by pBuffer
Enables Rsc services to marshal large data packets as stream.
Definition: RscStream.hpp:19
Root namespace for the PLCnext API
void SerializeFrom(Stream &stream)
Serialize the stream data from the as agument passed stream
System components used by the System, Device, Plc or Io domains.
void BeginRead(void)
Begins the read operation. Need pReader to be set.
unsigned char byte
The Arp character type.
Definition: PrimitiveTypes.hpp:23