7 #include "Arp/System/Rsc/Services/Rsc.h"
8 #include "Arp/System/Commons/Logging.h"
9 #include "Arp/System/Commons/Exceptions/Exceptions.h"
10 #include "Arp/System/Rsc/Services/RscException.hpp"
11 #include "Arp/System/Rsc/Services/IRscReadEnumerator.hxx"
12 #include "Arp/System/Rsc/Services/RscReader.hpp"
13 #include "Arp/System/Rsc/Services/RscArrayReader.hpp"
16 namespace Arp {
namespace System {
namespace Rsc {
namespace Services
43 RemotingReader& remotingReader;
44 size_t arrayLength = UndefinedArrayLength;
45 bool isArrayEnumerator;
48 size_t fieldCount = 0;
51 static constexpr
size_t UndefinedArrayLength = std::numeric_limits<size_t>::max();
58 : remotingReader(rscReader.GetRemotingReader())
59 , isArrayEnumerator(isArrayEnumeratorArg)
60 , rscType(GetRscTypeFrom(T()))
61 , fieldCount(StructInfo<T>().FieldCount)
70 Log::Error(
"Rsc Enumerating was not ended properly, call EndRead() method when reading was finished.");
77 if(this->isArrayEnumerator)
82 this->remotingReader.ReadBeginStruct(this->fieldCount);
86 this->remotingReader.ReadTag(this->rscType);
88 this->arrayLength = this->remotingReader.ReadArrayLength();
94 return this->arrayLength;
100 if(this->isArrayEnumerator)
102 if(this->arrayLength == 0)
115 RscType currentTypeCode = this->remotingReader.ReadEnumeratorTag(this->ended);
121 if(currentTypeCode != this->rscType)
123 throw RscException((
int)RscErrors::ProtocolViolation,
"Read false enumerator Tag: expected '{0}', received '{1}'", this->rscType, currentTypeCode);
127 size_t readFieldCount = this->remotingReader.ReadFieldCount();
128 if(readFieldCount != this->fieldCount)
130 throw RscException((
int)RscErrors::ProtocolViolation,
"Read false struct field count: expected '{0}', received '{1}'", this->fieldCount, readFieldCount);
134 RscValueAdapter<T> valueAdapter(current);
135 valueAdapter.Read(this->remotingReader,
false);
142 if (this->arrayLength == 0)
148 RscType elementType = this->remotingReader.ReadTag();
149 size_t arraySize = this->remotingReader.ReadArrayLength();
150 current =
RscArrayReader(arraySize, elementType, this->remotingReader);
157 if(this->isArrayEnumerator)
159 if(this->arrayLength != 0)
This exception is used when a method call is invalid for object's current state.
Definition: InvalidOperationException.hpp:15
Interface for reading an array or an enumerator. For regular enumerators UndefinedArrayLength is used...
Definition: IRscReadEnumerator.hxx:21
Helper class to read an array of primtive types from an RscVariant. This class uses the array informa...
Definition: RscArrayReader.hpp:23
Implementation of IRscReadEnumerator used on client side.
Definition: RscReadEnumerator.hxx:24
void EndRead(void) override
Ends the operation to read the enumerator. All enumerator elements had to be already been read.
Definition: RscReadEnumerator.hxx:155
size_t BeginRead(void) override
Begins the operation to read the enumerator.
Definition: RscReadEnumerator.hxx:75
bool ReadNext(T ¤t) override
Reads the next enumerator element.
Definition: RscReadEnumerator.hxx:98
RscReadEnumerator(RscReader &rscReader, bool isArrayEnumerator)
Constructs an RscEnumeratorBase instance.
Definition: RscReadEnumerator.hxx:57
RscReadEnumerator(const RscReadEnumerator &arg)=default
Copy constructor.
~RscReadEnumerator(void)
Destructs this instance and frees all resources.
Definition: RscReadEnumerator.hxx:66
Reads data from Rsc
Definition: RscReader.hpp:26
@ 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
@ Enumerator
Enumerator type, handled by Rsc with IRscReadEnumerator and IRscWriteEnumerator
@ Struct
Complex datatype with implements IRscSerializable
Root namespace for the PLCnext API