PLCnext API Documentation 23.0.2.9
RscStream.hpp
1
2//
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
12namespace Arp { namespace System { namespace Rsc { namespace Services
13{
14
15
20{
21public: // usings
23
24public: // 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
46public: // 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
69public: // 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
97
98public: // 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
125
126private: // fields
127 RemotingWriter* pWriter = nullptr;
128 RemotingReader* pReader = nullptr;
129 bool initialized = false;
130 int count = 0;
131 int remaining = 0;
132
133private: // 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
140inline RscStream::RscStream(RemotingWriter& writer)
141 : pWriter(&writer)
142{
143}
144
145inline RscStream::RscStream(RemotingReader& reader)
146 : pReader(&reader)
147{
148}
149
150inline bool RscStream::HasWriter()const
151{
152 return this->pWriter != nullptr;
153}
154
155inline bool RscStream::HasReader()const
156{
157 return this->pReader != nullptr;
158}
159
160inline void RscStream::SetWriter(RemotingWriter * value)
161{
162 this->pWriter = value;
163}
164
165inline 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