8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Core/ByteConverter.hpp"
10#include "Arp/System/Rsc/Services/RscValueAdapter.hxx"
11#include "Arp/System/Rsc/Services/RscStream.hpp"
12#include "Arp/System/Rsc/Services/RemotingReader.hpp"
13#include "Arp/System/Rsc/Services/RscException.hpp"
16namespace Arp {
namespace System {
namespace Rsc {
namespace Services
20class RscClientContext;
21class RscStreamAdapter;
30 RscReader(BinaryReader2& binaryReader, RscClientContext* pClientContext =
nullptr);
64 template<
class T> T
Read(
void);
70 template<
class T>
void Read(T& result);
77 template<
class T>
void Read(T& result,
bool readTag);
91 template<
int N>
void ReadString(
char(&value)[N]);
105 template<
class T>
void ReadArray(std::vector<T>& result);
112 template<
class T>
void ReadArray(std::vector<std::vector<T>>& result);
120 template<
class T,
size_t N>
void ReadArray(std::array<T, N>& result);
128 template<
class T>
size_t BeginArray(
void);
131 RemotingReader remotingReader;
137 : remotingReader(binaryReader, *this, pClientContext)
148 return this->remotingReader;
154 RscValueAdapter<T> valueAdapter(result);
155 valueAdapter.Read(this->remotingReader);
161 RscValueAdapter<T> valueAdapter(result);
162 valueAdapter.Read(this->remotingReader, readTag);
177 this->ReadString<N>(buffer);
184 this->remotingReader.ReadStringInternal(result, N, RscStringEncoding::Utf8);
190 size_t length = this->BeginArray<T>();
191 result.reserve(length);
193 for (
size_t i = 0; i < length; ++i)
196 RscValueAdapter<T> valueAdapter(value);
197 valueAdapter.Read(this->remotingReader,
false);
198 result.push_back(value);
206 size_t outerArraySize = this->BeginArray<T>();
207 result.reserve(outerArraySize);
208 for(
size_t i = 0; i < outerArraySize; ++i)
210 size_t innerArraySize = this->remotingReader.ReadArrayLength();
211 std::vector<T> innerArray;
212 innerArray.reserve(innerArraySize);
214 for(
size_t j = 0; j < innerArraySize; ++j)
217 RscValueAdapter<T> valueAdapter(value);
218 valueAdapter.Read(this->remotingReader,
false);
219 innerArray.push_back(value);
221 result.push_back(std::move(innerArray));
225template<
class T,
size_t N>
228 size_t length = this->BeginArray<T>();
231 throw RscException((
int)RscErrors::InvalidData,
"Received Array doesn't contain {0} elements", N);
234 for(
size_t i = 0; i < N; ++i)
236 RscValueAdapter<T> valueAdapter(result[i]);
237 valueAdapter.Read(this->remotingReader,
false);
242inline size_t RscReader::BeginArray(
void)
244 RscType elementType = GetRscTypeFrom(T());
248 this->remotingReader.ReadBeginStruct(StructInfo<T>().FieldCount);
252 this->remotingReader.ReadTag(elementType);
254 return this->remotingReader.ReadArrayLength();
260 RscType type =
static_cast<RscType>(this->remotingReader.ReadObjectType());
266 encoding = RscStringEncoding::Utf8;
270 encoding = RscStringEncoding::Utf16;
277 if(encoding == RscStringEncoding::Utf16)
283 this->remotingReader.ReadStringInternal(result, N, encoding);
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
This exception is used when a method is not implemented yet.
Definition: NotImplementedException.hpp:15
Reads data from Rsc
Definition: RscReader.hpp:27
void ReadString(String &result)
Reads a string from Rsc. The String will be read in format Utf-8. The template parameter gives the ma...
Definition: RscReader.hpp:174
void ReadStream(RscStreamAdapter &stream)
Reads the data from remote into the supplied stream.
RemotingReader & GetRemotingReader(void)
Returns reference to RemotingReader
Definition: RscReader.hpp:146
void ReadObjectString(char(&value)[N])
Reads a string in object format from Rsc. The template parameter gives the maximum number of characte...
Definition: RscReader.hpp:258
RscReader(BinaryReader2 &binaryReader, RscClientContext *pClientContext=nullptr)
Constructs an RscReader instance.
Definition: RscReader.hpp:136
RscReader & operator=(const RscReader &arg)=default
Assignment operator.
~RscReader(void)=default
Destructs this instance and frees all resources.
void ReadArray(std::vector< T > &result)
Reads an array from Rsc. The read data is stored as std::vector.
Definition: RscReader.hpp:188
RscReader(const RscReader &arg)=default
Copy constructor.
T Read(void)
Reads an element of T from Rsc. With data tagging enabled RscType of T is validated.
Definition: RscReader.hpp:166
RscStream GetStream(void)
Creates an instance of RscStream initialized to read stream data.
Definition: RscReader.hpp:141
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
@ System
System components used by the System, Device, Plc or Io domains.
RscStringEncoding
Determines the encoding of a Rsc String. Values are identical to CommonRemoting::StringEncoding.
Definition: RscStringEncoding.hpp:18
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
@ Array
std::vector<T> or RSC enumerators
@ Struct
struct derived by IRscSerializable
@ Utf8String
Utf-8 string, Arp::System::Rsc::Services::RscString
@ Utf16String
Utf-16 string, not implemented in Rsc context
Root namespace for the PLCnext API