PLCnext API Documentation 23.6.0.37
RscStream.hpp
1
2//
3// Copyright PHOENIX CONTACT Electronics GmbH
4//
6#pragma once
8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Rsc/Services/RemotingReader.hpp"
10#include "Arp/System/Rsc/Services/RemotingWriter.hpp"
11#include "Arp/System/Commons/Io/Stream.hpp"
12
13namespace Arp { namespace System { namespace Rsc { namespace Services
14{
15
16
21{
22public: // usings
24
25public: // construction/destruction
27 RscStream(void) = default;
28
33 RscStream(RemotingWriter& writer);
34
39 RscStream(RemotingReader& reader);
40
42 RscStream(const RscStream& rscStream) = default;
43
45 ~RscStream(void) = default;
46
47public: // setter/getter
51 bool HasWriter(void)const;
52
56 bool HasReader(void)const;
57
62 void SetWriter(RemotingWriter* pValue);
63
68 void SetReader(RemotingReader* pValue);
69
70public: // Read operations (only allowed with RemotingReader set)
74 void BeginRead(void);
75
82 size_t Read(byte* pBuffer, size_t bufferSize);
83
87 void Skip(void);
88
92 void DeserializeTo(Stream& stream);
93
98
99public: // Write operations (only allowed if RemotingWriter is set)
103 void BeginWrite(void);
104
110 void Write(const byte* pBuffer, size_t bufferCount);
111
115 void Flush(void);
116
120 void SerializeFrom(Stream& stream);
121
126
127private: // fields
128 RemotingWriter* pWriter = nullptr;
129 RemotingReader* pReader = nullptr;
130 bool initialized = false;
131 int count = 0;
132 int remaining = 0;
133
134private: // static fields
135 static constexpr int MaxPacketSize = std::numeric_limits<int>::max();
136 static constexpr size_t BufferSize = 4096;
137};
138
140// inline methods of class RscStream
141inline RscStream::RscStream(RemotingWriter& writer)
142 : pWriter(&writer)
143{
144}
145
146inline RscStream::RscStream(RemotingReader& reader)
147 : pReader(&reader)
148{
149}
150
151inline bool RscStream::HasWriter()const
152{
153 return this->pWriter != nullptr;
154}
155
156inline bool RscStream::HasReader()const
157{
158 return this->pReader != nullptr;
159}
160
161inline void RscStream::SetWriter(RemotingWriter * value)
162{
163 this->pWriter = value;
164}
165
166inline void RscStream::SetReader(RemotingReader* value)
167{
168 this->pReader = value;
169}
170}}}} // 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:21
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:151
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:161
RscStream(const RscStream &rscStream)=default
Copy Constructor
bool HasReader(void) const
Determines if this instance is able to reade.
Definition: RscStream.hpp:156
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:166
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