skip reading field if not found

This commit is contained in:
Pavel Merzlyakov 2023-07-27 09:20:44 +03:00
parent f20ab00a7b
commit 00bb2d96dd
1 changed files with 28 additions and 22 deletions

View File

@ -688,11 +688,11 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
{% macro meta_read_field(type, fname, alias) %}
{% if type is builtin %}
if err := reader.Read{{ type|builtin_type_suffix }}(&{{ fname }}, "{{ alias }}"); err != nil {
if err := reader.Read{{ type|builtin_type_suffix }}(&{{ fname }}, "{{ alias }}"); err != nil && err != meta.FieldNotFound {
return err
}
{% elseif type is enum %}
if err := reader.ReadInt32((*int32)(&{{ fname }}), "{{ alias }}"); err != nil {
if err := reader.ReadInt32((*int32)(&{{ fname }}), "{{ alias }}"); err != nil && err != meta.FieldNotFound {
return err
}
if !{{ fname }}.IsValid() {
@ -700,32 +700,38 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
}
{% elseif type is struct %}
if err := reader.BeginContainer("{{ alias }}"); err != nil {
return err
}
if err := {{ fname }}.ReadFields(reader); err != nil {
return err
}
if err := reader.EndContainer(); err != nil {
return err
if err != meta.FieldNotFound {
return err
}
} else {
if err := {{ fname }}.ReadFields(reader); err != nil {
return err
}
if err := reader.EndContainer(); err != nil {
return err
}
}
{% elseif type is array %}
{% set name = fname|split('.')|last %}
{% set size_var = name|lcfirst ~ 'Size' %}
{% set tmp_var = 'tmp' ~ name %}
if err := reader.BeginContainer("{{ alias }}"); err != nil {
return err
}
{{ size_var }}, err := reader.ContainerSize()
if err != nil {
return err
}
for ; {{ size_var }} > 0; {{ size_var }}-- {
var {{ tmp_var }} {{ type.value|go_type }}
{{ _self.meta_read_field(type.value, tmp_var) }}
{{ fname }} = append({{ fname }}, {{ tmp_var }})
}
if err := reader.EndContainer(); err != nil {
return err
if err != meta.FieldNotFound {
return err
}
} else {
{{ size_var }}, err := reader.ContainerSize()
if err != nil {
return err
}
for ; {{ size_var }} > 0; {{ size_var }}-- {
var {{ tmp_var }} {{ type.value|go_type }}
{{ _self.meta_read_field(type.value, tmp_var) }}
{{ fname }} = append({{ fname }}, {{ tmp_var }})
}
if err := reader.EndContainer(); err != nil {
return err
}
}
{% else %}
{{ Error('unkown type ' ~ type) }}