7 #include "Arp/System/Rsc/Services/Rsc.h"
8 #include "Arp/System/Core/ByteConverter.hpp"
9 #include "Arp/System/Rsc/Services/RscValueAdapter.hxx"
10 #include "Arp/System/Rsc/Services/RscStream.hpp"
11 #include "Arp/System/Rsc/Services/RemotingReader.hpp"
12 #include "Arp/System/Rsc/Services/RscException.hpp"
15 namespace Arp {
namespace System {
namespace Rsc {
namespace Services
19 class RscClientContext;
20 class RscStreamAdapter;
29 RscReader(BinaryReader2& binaryReader, RscClientContext* pClientContext =
nullptr);
63 template<
class T> T
Read(
void);
69 template<
class T>
void Read(T& result);
76 template<
class T>
void Read(T& result,
bool readTag);
90 template<
int N>
void ReadString(
char(&value)[N]);
104 template<
class T>
void ReadArray(std::vector<T>& result);
111 template<
class T>
void ReadArray(std::vector<std::vector<T>>& result);
119 template<
class T,
size_t N>
void ReadArray(std::array<T, N>& result);
127 template<
class T>
size_t BeginArray(
void);
130 RemotingReader remotingReader;
136 : remotingReader(binaryReader, *this, pClientContext)
147 return this->remotingReader;
153 RscValueAdapter<T> valueAdapter(result);
154 valueAdapter.Read(this->remotingReader);
160 RscValueAdapter<T> valueAdapter(result);
161 valueAdapter.Read(this->remotingReader, readTag);
176 this->ReadString<N>(buffer);
183 this->remotingReader.ReadStringInternal(result, N, RscStringEncoding::Utf8);
189 size_t length = this->BeginArray<T>();
190 result.reserve(length);
192 for (
size_t i = 0; i < length; ++i)
195 RscValueAdapter<T> valueAdapter(value);
196 valueAdapter.Read(this->remotingReader,
false);
197 result.push_back(value);
205 size_t outerArraySize = this->BeginArray<T>();
206 result.reserve(outerArraySize);
207 for(
size_t i = 0; i < outerArraySize; ++i)
209 size_t innerArraySize = this->remotingReader.ReadArrayLength();
210 std::vector<T> innerArray;
211 innerArray.reserve(innerArraySize);
213 for(
size_t j = 0; j < innerArraySize; ++j)
216 RscValueAdapter<T> valueAdapter(value);
217 valueAdapter.Read(this->remotingReader,
false);
218 innerArray.push_back(value);
220 result.push_back(std::move(innerArray));
224 template<
class T,
size_t N>
227 size_t length = this->BeginArray<T>();
230 throw RscException((
int)RscErrors::InvalidData,
"Received Array doesn't contain {0} elements", N);
233 for(
size_t i = 0; i < N; ++i)
235 RscValueAdapter<T> valueAdapter(result[i]);
236 valueAdapter.Read(this->remotingReader,
false);
241 inline size_t RscReader::BeginArray(
void)
243 RscType elementType = GetRscTypeFrom(T());
247 this->remotingReader.ReadBeginStruct(StructInfo<T>().FieldCount);
251 this->remotingReader.ReadTag(elementType);
253 return this->remotingReader.ReadArrayLength();
259 RscType type =
static_cast<RscType>(this->remotingReader.ReadObjectType());
265 encoding = RscStringEncoding::Utf8;
269 encoding = RscStringEncoding::Utf16;
276 if(encoding == RscStringEncoding::Utf16)
282 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:26
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:173
void ReadStream(RscStreamAdapter &stream)
Reads the data from remote into the supplied stream.
RemotingReader & GetRemotingReader(void)
Returns reference to RemotingReader
Definition: RscReader.hpp:145
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:257
RscReader(BinaryReader2 &binaryReader, RscClientContext *pClientContext=nullptr)
Constructs an RscReader instance.
Definition: RscReader.hpp:135
~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:187
RscReader & operator=(const RscReader &arg)=default
Assignment operator.
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:165
RscStream GetStream(void)
Creates an instance of RscStream initialized to read stream data.
Definition: RscReader.hpp:140
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
@ 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
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType....
Definition: RscType.hpp:37
@ Struct
Complex datatype with implements IRscSerializable
@ Utf16String
Utf-16 string, not implemented in Rsc context
Root namespace for the PLCnext API