removing @optional support

This commit is contained in:
Pavel Merzlyakov 2023-07-26 17:47:56 +03:00
parent 56ae2f6620
commit 6bc05545b1
1 changed files with 4 additions and 16 deletions

View File

@ -645,14 +645,14 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
contSize--
}
if !use_mask || (use_mask && s.FieldChanged({{ loop.index0 }})) {
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias, has_token(f, 'optional')) }}
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias) }}
{% if has_token(s, 'table') %}
s.changedFields.SetChanged("{{ f|alias }}")
{% endif %}
}
{% else %}
contSize--
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias, has_token(f, 'optional')) }}
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias) }}
{% if has_token(s, 'table') %}
s.changedFields.SetChanged("{{ f|alias }}")
{% endif %}
@ -665,22 +665,14 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
{% endmacro meta_read %}
{% macro meta_read_field(type, fname, alias, optional) %}
{% macro meta_read_field(type, fname, alias) %}
{% if type is builtin %}
if err := reader.Read{{ type|builtin_type_suffix }}(&{{ fname }}, "{{ alias }}"); err != nil {
{% if optional %}
return nil
{% else %}
return err
{% endif %}
}
{% elseif type is enum %}
if err := reader.ReadInt32((*int32)(&{{ fname }}), "{{ alias }}"); err != nil {
{% if optional %}
return nil
{% else %}
return err
{% endif %}
}
if !{{ fname }}.IsValid() {
return errors.Errorf("bad enum value `%d` for `{{ alias }}`", {{ fname }})
@ -690,11 +682,7 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
return err
}
if err := {{ fname }}.ReadFields(reader); err != nil {
{% if optional %}
return nil
{% else %}
return err
{% endif %}
}
if err := reader.EndContainer(); err != nil {
return err
@ -1047,7 +1035,7 @@ func (s *{{ name|default(s.name) }}) readFieldsAssociative(reader meta.Reader) e
switch field {
{% for f in all_fields %}
case "{{ f|alias }}":
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias, has_token(f, 'optional')) }}
{{ _self.meta_read_field(f.type, 's.' ~ f|fname, f|alias) }}
{% endfor %}
default:
{# continue // do not return an error for nested structs #}