8 #include "Arp/System/Rsc/Services/Rsc.h"
9 #include "Arp/System/Rsc/Services/RscVariant.hxx"
10 #include "Arp/System/Rsc/Services/RscString.hxx"
11 #include "Arp/System/Rsc/Services/RscValue.hpp"
12 #include "Arp/System/Rsc/Services/RscException.hpp"
14 namespace Arp {
namespace System {
namespace Rsc {
namespace Services
23 template<
int MaxStringSize>
27 using ReadElementFunction = RscVariant<>::ReadElementFunction;
77 RemotingReader* pReader =
nullptr;
78 ReadElementFunction readFieldFunction;
87 template<
int MaxStringSize>
89 : structInformation(structVariant.GetStructInformation())
91 if(structVariant.typeInfo.pReader ==
nullptr)
93 this->readFieldFunction = *structVariant.typeInfo.pReadElementFunction;
97 this->readFieldFunction = [&](
RscType expectedType,
byte * pValue)
99 return this->ReadRemotingValue(expectedType, pValue);
101 if(structVariant.typeInfo.pReader ==
nullptr)
105 this->pReader = structVariant.typeInfo.pReader;
109 template<
int MaxStringSize>
112 return this->structInformation.FieldCount;
115 template<
int MaxStringSize>
120 if(value.ContainsTypeInformation())
122 value.InitComplexTypeInfo();
123 value.typeInfo.pReader = this->pReader;
124 if(this->pReader ==
nullptr)
126 value.typeInfo.pReadElementFunction = &this->readFieldFunction;
131 template<
int MaxStringSize>
135 RscType expectedType = GetRscTypeFrom(currentField);
136 if(!IsPrimitiveRscType(expectedType))
140 (void)this->readFieldFunction(expectedType,
reinterpret_cast<byte*
>(¤tField));
143 template<
int MaxStringSize>
149 template<
int MaxStringSize>
152 RscType valueType = this->pReader->ReadObjectType();
155 throw RscException((
int)RscErrors::InvalidData,
"{}: Expected data type '{}', but got '{}'", __FUNCTION__, expectedType, valueType);
160 arrayInformation = this->pReader->ReadArrayInformation();
166 nestedStructInformation.
FieldCount = this->pReader->ReadFieldCount();
169 RscValue::Read(*this->pReader, valueType, pValue, MaxStringSize);
This exception is used when an invalid argument occurs.
Definition: ArgumentException.hpp:15
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
Contains a static string with string lentgh up to N characters. The string has to be null terminated.
Definition: RscString.hxx:21
const char * CStr(void) const
Returns pointer to internal buffer.
Definition: RscString.hxx:111
Helper class to read a struct from an RscVariant. This class uses the struct information stored in Rs...
Definition: RscStructReader.hxx:25
RscStructReader & operator=(const RscStructReader &arg)=default
Assignment operator.
RscStructReader(const RscVariant< MaxStringSize > &structVariant)
Constructs an RscStructReader instance.
Definition: RscStructReader.hxx:88
~RscStructReader(void)=default
Destructs this instance and frees all resources.
RscStructReader(const RscStructReader &arg)=default
Copy constructor.
size_t GetFieldCount(void) const
Gets the field count of the struct;
Definition: RscStructReader.hxx:110
void ReadNextField(T ¤tField)
Reads the next field of current struct. This method if field is primitve and known.
Definition: RscStructReader.hxx:133
Rsc container class for primitive data type, strings or information about arrays or structs....
Definition: RscVariant.hxx:39
void SetType(RscType rscType)
Forces the internal RscType to be set to another RscType. This Method does no conversion or validatio...
Definition: RscVariant.hxx:526
const byte * GetDataAddress(void) const
Gets a raw pointer to internal data buffer. To read data prefer CopyTo and to write prefer assignment...
Definition: RscVariant.hxx:514
@ 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
@ Object
Object type handled by Rsc as RscVariant
@ Struct
Complex datatype with implements IRscSerializable
Root namespace for the PLCnext API