{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

Included on Cython unions to retrieve the current value of the union and stick
it in the self.value variable.

}}{{^field:has_ref_api?}}{{!
}}{{#field:reference?}}{{!
}}if not deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().has_value():
    self.value = None
else:
{{#type:list?}}
    self.value = {{> types/container_from_cpp }}({{!
      }}deref(__get_union_field_value[{{> types/cython_cpp_type}}](deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref()))){{!
}}{{/type:list?}}{{^type:list?}}{{!
  }}{{! Use an aliasing constructor since the object we're returning is still
        managed by the top-level object, possible via a unique_ptr }}
    self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr({{!
      }}deref(__get_union_field_value[{{> types/cython_cpp_type}}](deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref())), self.{{> types/cpp_obj}})){{!
}}{{/type:list?}}{{!
}}{{/field:reference?}}{{!
}}{{^field:reference?}}{{!
}}{{#type:bool?}}{{!
  }}self.value = <bint>(deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value()){{!
}}{{/type:bool?}}{{!
}}{{#type:byte?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:byte?}}{{!
}}{{#type:i16?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:i16?}}{{!
}}{{#type:i32?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:i32?}}{{!
}}{{#type:i64?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:i64?}}{{!
}}{{#type:double?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:double?}}{{!
}}{{#type:float?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
}}{{/type:float?}}{{!
}}{{#type:string?}}{{!
  }}self.value = bytes(deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value()).decode('UTF-8'){{!
}}{{/type:string?}}{{!
}}{{#type:binary?}}{{!
  }}{{#type:iobuf?}}{{!
    }}self.value =  _fbthrift_iobuf.from_unique_ptr({{!
      }}deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value().clone()){{!
  }}{{/type:iobuf?}}{{!
  }}{{^type:iobuf?}}{{!
    }}self.value = deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value(){{!
  }}{{/type:iobuf?}}{{!
}}{{/type:binary?}}{{!
}}{{#type:enum}}{{!
  }}self.value = translate_cpp_enum_to_python({{!
    }}{{> types/python_type}}, {{!
    }}<int>deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value()){{!
}}{{/type:enum}}{{!
}}{{#type:struct?}}{{!
}}self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{!
  }}deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value())){{!
}}{{/type:struct?}}{{!
}}{{#type:list?}}{{!
}}self.value = {{> types/container_from_cpp }}({{!
  }}deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value()){{!
}}{{/type:list?}}{{!
}}{{#type:container?}}{{^type:list?}}{{!
}}self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{!
  }}deref(self.{{> types/cpp_obj}}).{{field:py_name}}_ref().value())){{!
}}{{/type:list?}}{{/type:container?}}{{!
}}{{/field:reference?}}{{!
}}{{/field:has_ref_api?}}{{!
}}{{#field:has_ref_api?}}{{!
}}{{#field:reference?}}{{!
}}if not deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}():
    self.value = None
else:
{{#type:list?}}
    self.value = {{> types/container_from_cpp }}({{!
      }}deref(deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}())){{!
}}{{/type:list?}}{{^type:list?}}{{!
  }}{{! Use an aliasing constructor since the object we're returning is still
        managed by the top-level object, possible via a unique_ptr }}
    self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE(__reference_shared_ptr({{!
      }}deref(deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}()), self.{{> types/cpp_obj}})){{!
}}{{/type:list?}}{{!
}}{{/field:reference?}}{{!
}}{{^field:reference?}}{{!
}}{{#type:bool?}}{{!
  }}self.value = <bint>(deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}()){{!
}}{{/type:bool?}}{{!
}}{{#type:byte?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:byte?}}{{!
}}{{#type:i16?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:i16?}}{{!
}}{{#type:i32?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:i32?}}{{!
}}{{#type:i64?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:i64?}}{{!
}}{{#type:double?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:double?}}{{!
}}{{#type:float?}}{{!
  }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
}}{{/type:float?}}{{!
}}{{#type:string?}}{{!
  }}self.value = bytes(deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}()).decode('UTF-8'){{!
}}{{/type:string?}}{{!
}}{{#type:binary?}}{{!
  }}{{#type:iobuf?}}{{!
    }}self.value =  _fbthrift_iobuf.from_unique_ptr({{!
      }}deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}().clone()){{!
  }}{{/type:iobuf?}}{{!
  }}{{^type:iobuf?}}{{!
    }}self.value = deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}(){{!
  }}{{/type:iobuf?}}{{!
}}{{/type:binary?}}{{!
}}{{#type:enum}}{{!
  }}self.value = translate_cpp_enum_to_python({{!
    }}{{> types/python_type}}, {{!
    }}<int>deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}()){{!
}}{{/type:enum}}{{!
}}{{#type:struct?}}{{!
}}self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{!
  }}deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}())){{!
}}{{/type:struct?}}{{!
}}{{#type:list?}}{{!
}}self.value = {{> types/container_from_cpp}}({{!
  }}deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}()){{!
}}{{/type:list?}}{{!
}}{{#type:container?}}{{^type:list?}}{{!
}}self.value = {{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{!
  }}deref(self.{{> types/cpp_obj}}).get_{{field:py_name}}())){{!
}}{{/type:list?}}{{/type:container?}}{{!
}}{{/field:reference?}}{{!
}}{{/field:has_ref_api?}}
