Skip to content

Commit f4480c7

Browse files
committed
Add check if the sequence is optional, if it is not persent encode null 0x80 and false in the presence map.
1 parent a74af23 commit f4480c7

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/mfast/coder/encoder/fast_encoder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ inline void fast_encoder_impl::visit(group_cref cref, int) {
124124

125125
inline void fast_encoder_impl::visit(sequence_cref cref, int) {
126126

127+
if (cref.instruction()->optional() && !cref.present()) {
128+
if (cref.instruction()->length_instruction()->pmap_size() > 0)
129+
this->current_->set_next_bit(false);
130+
if (cref.instruction()->length_instruction()->field_operator() != operator_constant &&
131+
cref.instruction()->length_instruction()->field_operator() != operator_default &&
132+
cref.instruction()->length_instruction()->field_operator() != operator_copy)
133+
strm_.encode_null();
134+
return;
135+
}
136+
127137
value_storage storage;
128138

129139
uint32_mref length_mref(nullptr, &storage,

src/mfast/coder/encoder_v2/fast_encoder_core.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ inline void fast_encoder_core::encode_field(const T &ext_ref, group_type_tag) {
259259
template <typename T>
260260
inline void fast_encoder_core::encode_field(const T &ext_ref,
261261
sequence_type_tag) {
262+
263+
if (ext_ref.get().instruction()->optional() && !ext_ref.present()) {
264+
if (T::length_type::has_pmap_type::value)
265+
this->current_->set_next_bit(false);
266+
if(!std::is_same<typename T::length_type::operator_category, constant_operator_tag>::value &&
267+
!std::is_same<typename T::length_type::operator_category, copy_operator_tag>::value &&
268+
!std::is_same<typename T::length_type::operator_category, default_operator_tag>::value )
269+
strm_.encode_null();
270+
return;
271+
}
272+
262273
value_storage storage;
263274

264275
typename T::length_type length = ext_ref.get_length(storage);

src/mfast/ext_ref.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class ext_cref<sequence_cref, LengthExtRef, ElementExtRef> {
167167
}
168168
std::size_t size() const { return base_.size(); }
169169

170+
bool present() const { return base_.present(); }
171+
170172
private:
171173
sequence_cref base_;
172174
};

0 commit comments

Comments
 (0)