fix reading null structs

This commit is contained in:
Pavel Merzlyakov 2023-11-23 21:42:04 +03:00
parent aebe6bc644
commit a915af9640
2 changed files with 16 additions and 1 deletions

View File

@ -454,6 +454,7 @@ function default_value(\mtgMetaField $field)
$type = $field->getType();
$tokens = $field->getTokens();
$default = $field->getToken('default');
$is_virtual = $field->hasToken('virtual');
if($type instanceof \mtgBuiltinType)
{
@ -476,6 +477,14 @@ function default_value(\mtgMetaField $field)
}
else if($type instanceof \mtgMetaEnum)
return $default ? go_type($type, $tokens)."_".trim($tokens['default'], '"') : 0;
else if($type instanceof \mtgMetaStruct)
{
if(!empty($default) && $default != 'null')
{
throw new Exception("not supported default value for struct '{$field->getName()}' with type '$type'");
}
return ($is_virtual ? '&' : '').go_type($type).'{}';
}
else
throw new Exception("Unknown type '$type'");
}

View File

@ -616,9 +616,15 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error {
return err
}
} else {
if err := {{ fname }}.ReadFields(reader); err != nil {
size, err := reader.ContainerSize()
if err != nil {
return err
}
if size > 0 {
if err := {{ fname }}.ReadFields(reader); err != nil {
return err
}
}
if err := reader.EndContainer(); err != nil {
return err
}