7 #include "Arp/System/Rsc/Services/Rsc.h"
8 #include "Arp/System/Rsc/Services/RscValueAdapter.hxx"
9 #include "Arp/System/Rsc/Services/RscStream.hpp"
10 #include "Arp/System/Rsc/Services/RemotingWriter.hpp"
12 #include <type_traits>
15 namespace CommonRemoting
20 namespace Arp {
namespace System {
namespace Rsc {
namespace Services
24 class RscClientContext;
25 class RscStreamAdapter;
34 RscWriter(BinaryWriter2& remotingWriter, RscClientContext* pClientContext =
nullptr);
74 template<
class T>
void Write(
const T& value);
82 template<
class T>
void Write(
const T& value,
bool writeTag);
96 template<
int N>
void WriteString(
const char(&value)[N]);
103 template<
class T>
void WriteObject(
const T& value);
124 template<
class T>
void WriteArray(
const std::vector<T>& values);
131 template<
class T>
void WriteArray(
const std::vector<std::vector<T>>& values);
139 template<
class T,
size_t N>
void WriteArray(
const std::array<T, N>& values);
147 template<
class T>
void BeginArray(
size_t size);
150 RemotingWriter remotingWriter;
157 : remotingWriter(remotingWriter, *this, pClientContextArg)
163 return this->remotingWriter;
168 this->remotingWriter.WriteConfirmation(flush);
179 RscValueAdapter<T> valueAdapter(value);
180 valueAdapter.Write(this->remotingWriter);
186 RscValueAdapter<T> valueAdapter(value);
187 valueAdapter.Write(this->remotingWriter, writetTag);
193 this->remotingWriter.WriteStringInternal(value, N);
199 this->remotingWriter.WriteStringInternal(value, N);
205 size_t length = values.size();
206 this->BeginArray<T>(length);
207 for (
size_t i = 0; i < length; ++i)
209 const T& value = values[i];
210 RscValueAdapter<T> valueAdapter(value);
211 valueAdapter.Write(this->remotingWriter,
false);
219 this->BeginArray<T>(values.size());
220 for(
const std::vector<T>& innerArray : values)
222 this->remotingWriter.WriteArrayLength(innerArray.size());
224 for(
const T& value : innerArray)
226 RscValueAdapter<T> valueAdapter(value);
227 valueAdapter.Write(this->remotingWriter,
false);
232 template<
class T,
size_t N>
235 this->BeginArray<T>(N);
236 for(
size_t i = 0; i < N; ++i)
238 const T& value = values[i];
239 RscValueAdapter<T> valueAdapter(value);
240 valueAdapter.Write(this->remotingWriter,
false);
245 inline void RscWriter::BeginArray(
size_t size)
247 RscType elementType = GetRscTypeFrom(T());
251 this->remotingWriter.WriteBeginStruct(StructInfo<T>().FieldCount);
255 this->remotingWriter.WriteTag(elementType);
257 this->remotingWriter.WriteArrayLength(size);
264 this->remotingWriter.WriteObjectType(GetRscTypeFrom(value));
271 this->remotingWriter.WriteObjectString(RscStringEncoding::Utf8, value);
277 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:20
Writes data to Rsc.
Definition: RscWriter.hpp:31
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:177
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:203
RscWriter & operator=(const RscWriter &arg)=default
Assignment operator.
void WriteConfirmation(bool flush=false)
Sends a confirmation message to remote station.
Definition: RscWriter.hpp:166
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:161
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:262
RscStream GetStream()
Creates an instance of RscStream initialized to write stream data.
Definition: RscWriter.hpp:171
void WriteObjectString(const String &value)
Writes a string in object format as Utf8 string.
Definition: RscWriter.hpp:269
RscWriter(BinaryWriter2 &remotingWriter, RscClientContext *pClientContext=nullptr)
Constructs an RscWriter instance.
Definition: RscWriter.hpp:156
void WriteString(const String &value)
Writes a string in format Utf-8.
Definition: RscWriter.hpp:191
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
@ Struct
Complex datatype with implements IRscSerializable
Root namespace for the PLCnext API