{{!

  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.

}}{{!

Used in cases where we have a C++ object defined in Cython code and we need
to create or return a Python object. For complex objects, a Python wrapper
is initialized; for simple objects it can be returned directly. Strings need
to be converted from unicode to binary representation.

}}{{#type:iobuf?}}_fbthrift_iobuf.from_unique_ptr({{field:py_name}}.clone()){{/type:iobuf?}}{{!
}}{{#type:iobufRef?}}_fbthrift_iobuf.from_unique_ptr(move_iobuf({{field:py_name}})){{/type:iobufRef?}}{{!
}}{{#type:flexibleBinary?}}{{!
  }}(<const char*>{{field:py_name}}.data())[:{{field:py_name}}.size()]{{!
}}{{/type:flexibleBinary?}}{{!
}}{{^type:hasCustomTypeBehavior?}}{{!
}}{{#type:bool?}}{{field:py_name}}{{/type:bool?}}{{!
}}{{#type:byte?}}{{field:py_name}}{{/type:byte?}}{{!
}}{{#type:i16?}}{{field:py_name}}{{/type:i16?}}{{!
}}{{#type:i32?}}{{field:py_name}}{{/type:i32?}}{{!
}}{{#type:i64?}}{{field:py_name}}{{/type:i64?}}{{!
}}{{#type:double?}}{{field:py_name}}{{/type:double?}}{{!
}}{{#type:float?}}{{field:py_name}}{{/type:float?}}{{!
}}{{#type:string?}}{{field:py_name}}.data().decode('UTF-8'){{/type:string?}}{{!
}}{{#type:binary?}}{{field:py_name}}{{/type:binary?}}{{!
}}{{#type:struct?}}{{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{field:py_name}})){{!
}}{{/type:struct?}}{{!
}}{{#type:list?}}{{!
  }}{{> types/container_from_cpp}}({{field:py_name}}){{!
}}{{/type:list?}}{{!
}}{{#type:container?}}{{^type:list?}}{{!
  }}{{> types/cython_python_type}}._create_FBTHRIFT_ONLY_DO_NOT_USE({{!
  }}make_shared[{{> types/cython_cpp_type}}]({{field:py_name}})){{!
}}{{/type:list?}}{{/type:container?}}{{!
}}{{#type:enum?}}{{> types/python_type}}(<int> {{field:py_name}}){{/type:enum?}}{{!
}}{{/type:hasCustomTypeBehavior?}}
