8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Rsc/Services/RscValueAdapter.hxx"
10#include "Arp/System/Rsc/Services/RscStream.hpp"
11#include "Arp/System/Rsc/Services/RemotingWriter.hpp"
16namespace CommonRemoting
21namespace Arp {
namespace System {
namespace Rsc {
namespace Services
25class RscClientContext;
26class RscStreamAdapter;
35 RscWriter(BinaryWriter2& remotingWriter, RscClientContext* pClientContext =
nullptr);
75 template<
class T>
void Write(
const T& value);
83 template<
class T>
void Write(
const T& value,
bool writeTag);
97 template<
int N>
void WriteString(
const char(&value)[N]);
104 template<
class T>
void WriteObject(
const T& value);
125 template<
class T>
void WriteArray(
const std::vector<T>& values);
132 template<
class T>
void WriteArray(
const std::vector<std::vector<T>>& values);
140 template<
class T,
size_t N>
void WriteArray(
const std::array<T, N>& values);
148 template<
class T>
void BeginArray(
size_t size);
151 RemotingWriter remotingWriter;
158 : remotingWriter(remotingWriter, *this, pClientContextArg)
164 return this->remotingWriter;
169 this->remotingWriter.WriteConfirmation(flush);
180 RscValueAdapter<T> valueAdapter(value);
181 valueAdapter.Write(this->remotingWriter);
187 RscValueAdapter<T> valueAdapter(value);
188 valueAdapter.Write(this->remotingWriter, writetTag);
194 this->remotingWriter.WriteStringInternal(value, N);
200 this->remotingWriter.WriteStringInternal(value, N);
206 size_t length = values.size();
207 this->BeginArray<T>(length);
208 for (
size_t i = 0; i < length; ++i)
210 const T& value = values[i];
211 RscValueAdapter<T> valueAdapter(value);
212 valueAdapter.Write(this->remotingWriter,
false);
220 this->BeginArray<T>(values.size());
221 for(
const std::vector<T>& innerArray : values)
223 this->remotingWriter.WriteArrayLength(innerArray.size());
225 for(
const T& value : innerArray)
227 RscValueAdapter<T> valueAdapter(value);
228 valueAdapter.Write(this->remotingWriter,
false);
233template<
class T,
size_t N>
236 this->BeginArray<T>(N);
237 for(
size_t i = 0; i < N; ++i)
239 const T& value = values[i];
240 RscValueAdapter<T> valueAdapter(value);
241 valueAdapter.Write(this->remotingWriter,
false);
246inline void RscWriter::BeginArray(
size_t size)
248 RscType elementType = GetRscTypeFrom(T());
252 this->remotingWriter.WriteBeginStruct(StructInfo<T>().FieldCount);
256 this->remotingWriter.WriteTag(elementType);
258 this->remotingWriter.WriteArrayLength(size);
265 this->remotingWriter.WriteObjectType(GetRscTypeFrom(value));
272 this->remotingWriter.WriteObjectString(RscStringEncoding::Utf8, value);
278 this->remotingWriter.WriteObjectString(RscStringEncoding::Utf8, value);
This class serves as adapter between Rsc streams and streams from Arp::System::Commons::Io,...
Definition: RscStreamAdapter.hpp:20
Enables Rsc services to marshal large data packets as stream.
Definition: RscStream.hpp:21
Writes data to Rsc.
Definition: RscWriter.hpp:32
void WriteStream(RscStreamAdapter &stream)
Writes the data from the supplied stream to remote stream.
void Write(const T &value)
Writes an element of T from Rsc. Datatag and format is determined deducted by type of T.
Definition: RscWriter.hpp:178
RscWriter & operator=(const RscWriter &arg)=default
Assignment operator.
void WriteArray(const std::vector< T > &values)
Writes an array to Rsc. The data to write has to be stored in a std::vector.
Definition: RscWriter.hpp:204
void WriteConfirmation(bool flush=false)
Sends a confirmation message to remote station.
Definition: RscWriter.hpp:167
RscWriter(const RscWriter &arg)=default
Copy constructor.
~RscWriter(void)=default
Destructs this instance and frees all resources.
RemotingWriter & GetRemotingWriter(void)
Returns reference to RemotingWriter
Definition: RscWriter.hpp:162
void WriteObject(const T &value)
Writes an object. Datatag and format is determined deducted by type of T. This method doesn't support...
Definition: RscWriter.hpp:263
RscStream GetStream()
Creates an instance of RscStream initialized to write stream data.
Definition: RscWriter.hpp:172
void WriteObjectString(const String &value)
Writes a string in object format as Utf8 string.
Definition: RscWriter.hpp:270
RscWriter(BinaryWriter2 &remotingWriter, RscClientContext *pClientContext=nullptr)
Constructs an RscWriter instance.
Definition: RscWriter.hpp:157
void WriteString(const String &value)
Writes a string in format Utf-8.
Definition: RscWriter.hpp:192
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
@ Array
std::vector<T> or RSC enumerators
@ Struct
struct derived by IRscSerializable
Root namespace for the PLCnext API