From 6bc05545b1fc9d3110e9842925320aa2541d39ee Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Wed, 26 Jul 2023 17:47:56 +0300 Subject: [PATCH] removing @optional support --- tpl/macros_struct.twig | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index 48eb1c1..7a485c8 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -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 #}