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" 14 namespace Arp {
namespace System {
namespace Rsc {
namespace Services
18 class RscClientContext;
29 RscReader(BinaryReader2& binaryReader, RscClientContext* pClientContext =
nullptr);
58 template<
class T> T
Read(
void);
64 template<
class T>
void Read(T& result);
71 template<
class T>
void Read(T& result,
bool readTag);
85 template<
int N>
void ReadString(
char(&value)[N]);
99 template<
class T>
void ReadArray(std::vector<T>& result);
106 template<
class T>
void ReadArray(std::vector<std::vector<T>>& result);
114 template<
class T,
size_t N>
void ReadArray(std::array<T, N>& result);
122 template<
class T>
size_t BeginArray(
void);
125 RemotingReader remotingReader;
131 : remotingReader(binaryReader, *this, pClientContext)
142 return this->remotingReader;
148 RscValueAdapter<T> valueAdapter(result);
149 valueAdapter.Read(this->remotingReader);
155 RscValueAdapter<T> valueAdapter(result);
156 valueAdapter.Read(this->remotingReader, readTag);
171 this->ReadString<N>(buffer);
178 this->remotingReader.ReadStringInternal(result, N, RscStringEncoding::Utf8);
184 size_t length = this->BeginArray<T>();
185 result.reserve(length);
187 for (
size_t i = 0; i < length; ++i)
190 RscValueAdapter<T> valueAdapter(value);
191 valueAdapter.Read(this->remotingReader,
false);
192 result.push_back(value);
200 size_t outerArraySize = this->BeginArray<T>();
201 result.reserve(outerArraySize);
202 for(
size_t i = 0; i < outerArraySize; ++i)
204 size_t innerArraySize = this->remotingReader.ReadArrayLength();
205 std::vector<T> innerArray;
206 innerArray.reserve(innerArraySize);
208 for(
size_t j = 0; j < innerArraySize; ++j)
211 RscValueAdapter<T> valueAdapter(value);
212 valueAdapter.Read(this->remotingReader,
false);
213 innerArray.push_back(value);
215 result.push_back(std::move(innerArray));
219 template<
class T,
size_t N>
222 size_t length = this->BeginArray<T>();
225 throw RscException((
int)RscErrors::InvalidData,
"Received Array doesn't contain {0} elements", N);
228 for(
size_t i = 0; i < N; ++i)
230 RscValueAdapter<T> valueAdapter(result[i]);
231 valueAdapter.Read(this->remotingReader,
false);
236 inline size_t RscReader::BeginArray(
void)
238 RscType elementType = GetRscTypeFrom(T());
242 this->remotingReader.ReadBeginStruct(StructInfo<T>().FieldCount);
246 this->remotingReader.ReadTag(elementType);
248 return this->remotingReader.ReadArrayLength();
254 RscType type =
static_cast<RscType>(this->remotingReader.ReadObjectType());
260 encoding = RscStringEncoding::Utf8;
264 encoding = RscStringEncoding::Utf16;
271 if(encoding == RscStringEncoding::Utf16)
277 this->remotingReader.ReadStringInternal(result, N, encoding);
Reads data from Rsc
Definition: RscReader.hpp:23
RemotingReader & GetRemotingReader(void)
Returns reference to RemotingReader
Definition: RscReader.hpp:140
Complex datatype with implements IRscSerializable
RscReader(BinaryReader2 &binaryReader, RscClientContext *pClientContext=nullptr)
Constructs an RscReader instance.
Definition: RscReader.hpp:130
RscStream GetStream(void)
Creates an instance of RscStream initialized to read stream data.
Definition: RscReader.hpp:135
Utf-16 string, not implemented in Rsc context
This exception is used when a method is not implemented yet.
Definition: NotImplementedException.hpp:14
T Read(void)
Reads an element of T from Rsc. With data tagging enabled RscType of T is validated.
Definition: RscReader.hpp:160
RscType
Datatypes supported by Rsc. Values are identical with CommonRemoting::RemotingMarshalType. Only supported types of RemotingMarshalType are included.
Definition: RscType.hpp:27
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:14
Enables Rsc services to marshal large data packets as stream.
Definition: RscStream.hpp:17
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:168
Root namespace for the PLCnext API
void ReadArray(std::vector< T > &result)
Reads an array from Rsc. The read data is stored as std::vector.
Definition: RscReader.hpp:182
RscStringEncoding
Determines the encoding of a Rsc String. Values are identical to CommonRemoting::StringEncoding. Rsc only supports Utf8.
Definition: RscStringEncoding.hpp:16
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:252
System components used by the System, Device, Plc or Io domains.
~RscReader(void)=default
Destructs this instance and frees all resources.
RscReader & operator=(const RscReader &arg)=default
Assignment operator.