PLCnext API Documentation  22.9.0.33
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 
96  void DeserializeTo(RscStream stream);
97 
98 public: // Write operations (only allowed if RemotingWriter is set)
102  void BeginWrite(void);
103 
109  void Write(const byte* pBuffer, size_t bufferCount);
110 
114  void Flush(void);
115 
119  void SerializeFrom(Stream& stream);
120 
124  void SerializeFrom(RscStream stream);
125 
126 private: // fields
127  RemotingWriter* pWriter = nullptr;
128  RemotingReader* pReader = nullptr;
129  bool initialized = false;
130  int count = 0;
131  int remaining = 0;
132 
133 private: // static fields
134  static constexpr int MaxPacketSize = std::numeric_limits<int>::max();
135  static constexpr size_t BufferSize = 4096;
136 };
137 
139 // inline methods of class RscStream
140 inline RscStream::RscStream(RemotingWriter& writer)
141  : pWriter(&writer)
142 {
143 }
144 
145 inline RscStream::RscStream(RemotingReader& reader)
146  : pReader(&reader)
147 {
148 }
149 
150 inline bool RscStream::HasWriter()const
151 {
152  return this->pWriter != nullptr;
153 }
154 
155 inline bool RscStream::HasReader()const
156 {
157  return this->pReader != nullptr;
158 }
159 
160 inline void RscStream::SetWriter(RemotingWriter * value)
161 {
162  this->pWriter = value;
163 }
164 
165 inline void RscStream::SetReader(RemotingReader* value)
166 {
167  this->pReader = value;
168 }
169 }}}} // end of namespace Arp::System::Rsc::Services
Provides a generic view of a sequence of bytes.
Definition: Stream.hpp:20
Enables Rsc services to marshal large data packets as stream.
Definition: RscStream.hpp:20
void Flush(void)
Ends the read writer operation and writes remaining internal buffered bytes
void Skip(void)
Skips the entire stream and disposes the read data
bool HasWriter(void) const
Determines if this instance is able to write.
Definition: RscStream.hpp:150
void SerializeFrom(RscStream stream)
Serialize the stream data from the as agument passed stream
~RscStream(void)=default
Destructs this instance and frees all resources.
RscStream(void)=default
Constructs an instance of RscStream
size_t Read(byte *pBuffer, size_t bufferSize)
Reads up to bufferSize byte into memory referenced by pBuffer
void DeserializeTo(Stream &stream)
Deserialize the stream data and copies it to the as agument passed stream
void SetWriter(RemotingWriter *pValue)
Sets RemotingWriter needed to write stream data
Definition: RscStream.hpp:160
RscStream(const RscStream &rscStream)=default
Copy Constructor
bool HasReader(void) const
Determines if this instance is able to reade.
Definition: RscStream.hpp:155
void Write(const byte *pBuffer, size_t bufferCount)
Writes data into stream
void BeginRead(void)
Begins the read operation. Need pReader to be set.
void BeginWrite(void)
Begins the write operation
void SerializeFrom(Stream &stream)
Serialize the stream data from the as agument passed stream
void SetReader(RemotingReader *pValue)
Sets RemotingReader needed to read stream data
Definition: RscStream.hpp:165
void DeserializeTo(RscStream stream)
Deserialize the stream data and copies it to the as agument passed Rsc stream
@ System
System components used by the System, Device, Plc or Io domains.
Root namespace for the PLCnext API