44
55#include " slave.hpp"
66
7+ #include < memory>
78#include < set>
89#include < unordered_map>
910#include < utility>
10- #include < memory>
1111
1212namespace fmilibcpp
1313{
@@ -116,6 +116,18 @@ class buffered_slave : public slave
116116 return true ;
117117 }
118118
119+ bool get_binary (const std::vector<value_ref>& vrs, std::vector<std::vector<uint8_t >>& values) override
120+ {
121+ for (unsigned i = 0 ; i < vrs.size (); i++) {
122+ const value_ref vr = vrs[i];
123+ if (std::ranges::find (bytesToFetch_, vr) == bytesToFetch_.end ()) {
124+ mark_for_reading (get_model_description ().get_by_vr <std::vector<uint8_t >>(vr)->name );
125+ }
126+ values[i] = bytesGetCache_.at (vr);
127+ }
128+ return true ;
129+ }
130+
119131 bool set_integer (const std::vector<value_ref>& vrs, const std::vector<int >& values) override
120132 {
121133 for (unsigned i = 0 ; i < vrs.size (); i++) {
@@ -152,6 +164,15 @@ class buffered_slave : public slave
152164 return true ;
153165 }
154166
167+ bool set_binary (const std::vector<value_ref>& vrs, const std::vector<std::vector<uint8_t >>& values) override
168+ {
169+ for (unsigned i = 0 ; i < vrs.size (); i++) {
170+ const value_ref vr = vrs[i];
171+ bytesSetCache_[vr] = values[i];
172+ }
173+ return true ;
174+ }
175+
155176 void transferCachedSets ()
156177 {
157178 if (!integerSetCache_.empty ()) {
@@ -194,6 +215,16 @@ class buffered_slave : public slave
194215 slave_->set_boolean (vrs, values);
195216 boolSetCache_.clear ();
196217 }
218+ if (!bytesSetCache_.empty ()) {
219+ std::vector<value_ref> vrs;
220+ std::vector<std::vector<uint8_t >> values;
221+ for (const auto & [vr, value] : bytesSetCache_) {
222+ vrs.emplace_back (vr);
223+ values.emplace_back (value);
224+ }
225+ slave_->set_binary (vrs, values);
226+ bytesSetCache_.clear ();
227+ }
197228 }
198229
199230 void receiveCachedGets ()
@@ -238,6 +269,16 @@ class buffered_slave : public slave
238269 booleanGetCache_[vr] = __booleanGetCache_[i];
239270 }
240271 }
272+ if (!bytesToFetch_.empty ()) {
273+ __bytesGetCache_.resize (bytesToFetch_.size ());
274+ slave_->get_binary (bytesToFetch_, __bytesGetCache_);
275+
276+ bytesGetCache_.clear ();
277+ for (unsigned i = 0 ; i < bytesToFetch_.size (); i++) {
278+ const value_ref vr = bytesToFetch_[i];
279+ bytesGetCache_[vr] = __bytesGetCache_[i];
280+ }
281+ }
241282 }
242283
243284 void mark_for_reading (const std::string& variableName)
@@ -260,6 +301,8 @@ class buffered_slave : public slave
260301 stringsToFetch_.emplace_back (vr);
261302 } else if (v->is_boolean ()) {
262303 booleansToFetch_.emplace_back (vr);
304+ } else if (v->is_binary ()) {
305+ bytesToFetch_.emplace_back (vr);
263306 }
264307
265308 marked_variables.insert (variableName);
@@ -273,6 +316,8 @@ class buffered_slave : public slave
273316 stringGetCache_[vr] = slave_->get_string (vr);
274317 } else if (v->is_boolean ()) {
275318 booleanGetCache_[vr] = slave_->get_boolean (vr);
319+ } else if (v->is_binary ()) {
320+ bytesGetCache_[vr] = slave_->get_binary (vr);
276321 }
277322 }
278323 }
@@ -289,21 +334,25 @@ class buffered_slave : public slave
289334 std::unordered_map<value_ref, double > realSetCache_;
290335 std::unordered_map<value_ref, std::string> stringSetCache_;
291336 std::unordered_map<value_ref, bool > boolSetCache_;
337+ std::unordered_map<value_ref, std::vector<uint8_t >> bytesSetCache_;
292338
293339 std::unordered_map<value_ref, int > integerGetCache_;
294340 std::unordered_map<value_ref, double > realGetCache_;
295341 std::unordered_map<value_ref, std::string> stringGetCache_;
296342 std::unordered_map<value_ref, bool > booleanGetCache_;
343+ std::unordered_map<value_ref, std::vector<uint8_t >> bytesGetCache_;
297344
298345 std::vector<int > __integerGetCache_;
299346 std::vector<double > __realGetCache_;
300347 std::vector<std::string> __stringGetCache_;
301348 std::vector<bool > __booleanGetCache_;
349+ std::vector<std::vector<uint8_t >> __bytesGetCache_;
302350
303351 std::vector<value_ref> integersToFetch_;
304352 std::vector<value_ref> realsToFetch_;
305353 std::vector<value_ref> stringsToFetch_;
306354 std::vector<value_ref> booleansToFetch_;
355+ std::vector<value_ref> bytesToFetch_;
307356
308357 std::set<std::string> marked_variables;
309358
0 commit comments