8#include "Arp/System/Rsc/Services/Rsc.h"
9#include "Arp/System/Commons/Logging.h"
10#include "Arp/System/Commons/Exceptions/Exceptions.h"
11#include "Arp/System/Rsc/Services/RscException.hpp"
12#include "Arp/System/Rsc/Services/IRscReadEnumerator.hxx"
13#include "Arp/System/Rsc/Services/RscReader.hpp"
14#include "Arp/System/Rsc/Services/RscArrayReader.hpp"
17namespace Arp {
namespace System {
namespace Rsc {
namespace Services
44 RemotingReader& remotingReader;
45 size_t arrayLength = UndefinedArrayLength;
46 bool isArrayEnumerator;
49 size_t fieldCount = 0;
52 static constexpr size_t UndefinedArrayLength = std::numeric_limits<size_t>::max();
59 : remotingReader(rscReader.GetRemotingReader())
60 , isArrayEnumerator(isArrayEnumeratorArg)
61 , rscType(GetRscTypeFrom(T()))
62 , fieldCount(StructInfo<T>().FieldCount)
71 Log::Error(
"Rsc Enumerating was not ended properly, call EndRead() method when reading was finished.");
78 if(this->isArrayEnumerator)
83 this->remotingReader.ReadBeginStruct(this->fieldCount);
87 this->remotingReader.ReadTag(this->rscType);
89 this->arrayLength = this->remotingReader.ReadArrayLength();
95 return this->arrayLength;
101 if(this->isArrayEnumerator)
103 if(this->arrayLength == 0)
116 RscType currentTypeCode = this->remotingReader.ReadEnumeratorTag(this->ended);
122 if(currentTypeCode != this->rscType)
124 throw RscException((
int)RscErrors::ProtocolViolation,
"Read false enumerator Tag: expected '{0}', received '{1}'", this->rscType, currentTypeCode);
128 size_t readFieldCount = this->remotingReader.ReadFieldCount();
129 if(readFieldCount != this->fieldCount)
131 throw RscException((
int)RscErrors::ProtocolViolation,
"Read false struct field count: expected '{0}', received '{1}'", this->fieldCount, readFieldCount);
135 RscValueAdapter<T> valueAdapter(current);
136 valueAdapter.Read(this->remotingReader,
false);
143 if (this->arrayLength == 0)
149 RscType elementType = this->remotingReader.ReadTag();
150 size_t arraySize = this->remotingReader.ReadArrayLength();
151 current =
RscArrayReader(arraySize, elementType, this->remotingReader);
158 if(this->isArrayEnumerator)
160 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:25
void EndRead(void) override
Ends the operation to read the enumerator. All enumerator elements had to be already been read.
Definition: RscReadEnumerator.hxx:156
size_t BeginRead(void) override
Begins the operation to read the enumerator.
Definition: RscReadEnumerator.hxx:76
bool ReadNext(T ¤t) override
Reads the next enumerator element.
Definition: RscReadEnumerator.hxx:99
RscReadEnumerator(RscReader &rscReader, bool isArrayEnumerator)
Constructs an RscEnumeratorBase instance.
Definition: RscReadEnumerator.hxx:58
RscReadEnumerator(const RscReadEnumerator &arg)=default
Copy constructor.
~RscReadEnumerator(void)
Destructs this instance and frees all resources.
Definition: RscReadEnumerator.hxx:67
Reads data from Rsc
Definition: RscReader.hpp:27
@ System
System components used by the System, Device, Plc or Io domains.
RscType
Data types supported by RSC.
Definition: RscType.hpp:36
@ Enumerator
Enumerator type implemented as IRscReadEnumerator or IRscWriteEnumerator
@ Array
std::vector<T> or RSC enumerators
@ Struct
struct derived by IRscSerializable
Root namespace for the PLCnext API