Skip to content

Commit e8e06be

Browse files
committed
Correct the case of the constant or default length
1 parent 507f3fa commit e8e06be

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/mfast/ext_ref.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "decimal_ref.h"
1111
#include "nested_message_ref.h"
1212

13+
#include <type_traits>
14+
1315
namespace mfast {
1416
template <int V> struct fast_operator_tag : std::integral_constant<int, V> {};
1517

@@ -147,6 +149,13 @@ class ext_cref<sequence_cref, LengthExtRef, ElementExtRef> {
147149
explicit ext_cref(const field_cref &other) : base_(other) {}
148150
cref_type get() const { return base_; }
149151
length_type get_length(value_storage &storage) const {
152+
if (std::is_same<typename LengthExtRef::operator_category, constant_operator_tag>::value)
153+
storage = base_.instruction()->length_instruction()->initial_value();
154+
else if (std::is_same<typename LengthExtRef::operator_category, copy_operator_tag>::value)
155+
storage = base_.instruction()->length_instruction()->prev_value();
156+
else if (std::is_same<typename LengthExtRef::operator_category, default_operator_tag>::value)
157+
storage = base_.instruction()->length_instruction()->initial_or_default_value();
158+
150159
uint32_mref length_mref(nullptr, &storage,
151160
base_.instruction()->length_instruction());
152161
length_mref.as(base_.size());
@@ -327,6 +336,13 @@ class ext_mref<sequence_mref, LengthExtRef, ElementExtRef> {
327336
cref_type get() const { return base_; }
328337
is_optional_type optional() const { return is_optional_type(); }
329338
length_type set_length(value_storage &storage) const {
339+
if (std::is_same<typename LengthExtRef::operator_category, constant_operator_tag>::value)
340+
storage = base_.instruction()->length_instruction()->initial_value();
341+
else if (std::is_same<typename LengthExtRef::operator_category, copy_operator_tag>::value)
342+
storage = base_.instruction()->length_instruction()->prev_value();
343+
else if (std::is_same<typename LengthExtRef::operator_category, default_operator_tag>::value)
344+
storage = base_.instruction()->length_instruction()->initial_or_default_value();
345+
330346
field_mref_base length_mref(nullptr, &storage,
331347
base_.instruction()->length_instruction());
332348
return length_type(length_mref);

0 commit comments

Comments
 (0)