{{!

  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.

}}{{#type:typedef?}}{{!
    }}{{#type:isMapKey?}}{{#type:typedef_type}}{{type:setIsMapKey}}{{> WriteResponseType}}{{/type:typedef_type}}{{/type:isMapKey?}}{{!
    }}{{#type:isMapValue?}}{{#type:typedef_type}}{{type:setIsMapValue}}{{> WriteResponseType}}{{/type:typedef_type}}{{/type:isMapValue?}}{{!
    }}{{^type:isMapKey?}}{{^type:isMapValue?}}{{#type:typedef_type}}{{> WriteResponseType}}{{/type:typedef_type}}{{/type:isMapValue?}}{{/type:isMapKey?}}{{!
}}{{/type:typedef?}}{{!
}}{{^type:typedef?}}{{!
}}{{#type:set?}}{{^function:isNested?}}oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.SET_FIELD);{{/function:isNested?}}
      oprot.writeSetBegin(new TSet(TType.{{#type:set_elem_type}}{{> TType}}{{/type:set_elem_type}}, _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.size()));
        for ({{#type:set_elem_type}}{{> Type}}{{/type:set_elem_type}} _iter{{function:nestedDepth}} : _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}) {
          {{function:setIsNested}}{{type:setIsNotMap}}{{!
          }}{{#type:set_elem_type}}{{!
          }}{{#type:isContainer?}}{{!
          }}{{function:nestedDepth++}}{{> WriteResponseType}}{{function:nestedDepth--}}
          {{/type:isContainer?}}{{!
          }}{{^type:isContainer?}}{{> WriteResponseType}}
          {{/type:isContainer?}}{{/type:set_elem_type}}
        }
        oprot.writeSetEnd();{{!
}}{{/type:set?}}{{!

}}{{#type:list?}}{{!
}}{{^function:isNested?}}oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.LIST_FIELD);{{/function:isNested?}}
oprot.writeListBegin(new TList(TType.{{#type:list_elem_type}}{{> TType}}{{/type:list_elem_type}}, _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.size()));
        for ({{#type:list_elem_type}}{{> Type}}{{/type:list_elem_type}} _iter{{function:nestedDepth}} : _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}) {
          {{function:setIsNested}}{{type:setIsNotMap}}{{!
          }}{{#type:list_elem_type}}{{!
          }}{{#type:isContainer?}}{{!
          }}{{function:nestedDepth++}}{{> WriteResponseType}}{{function:nestedDepth--}}
          {{/type:isContainer?}}{{!
          }}{{^type:isContainer?}}{{> WriteResponseType}}
          {{/type:isContainer?}}{{/type:list_elem_type}}
        }
        oprot.writeListEnd();{{!
}}{{/type:list?}}{{!

}}{{#type:map?}}{{!
}}{{^function:isNested?}}oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.MAP_FIELD);{{/function:isNested?}}
oprot.writeMapBegin(new TMap(TType.{{#type:key_type}}{{> TType}}{{/type:key_type}}, TType.{{#type:value_type}}{{> TType}}{{/type:value_type}}, _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.size()));
        for (Map.Entry<{{#type:key_type}}{{> BoxedType}}{{/type:key_type}}, {{#type:value_type}}{{> BoxedType}}{{/type:value_type}}> _iter{{function:nestedDepth}} : _iter{{function:prevNestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.entrySet()) {
          {{function:setIsNested}}{{!

          }}{{#type:key_type}}{{type:setIsMapKey}}{{!
          }}{{#type:isContainer?}}{{!
          }}{{function:nestedDepth++}}{{> WriteResponseType}}{{function:nestedDepth--}}
          {{/type:isContainer?}}{{!
          }}{{^type:isContainer?}}{{> WriteResponseType}}
          {{/type:isContainer?}}{{/type:key_type}}{{!

          }}{{#type:value_type}}{{type:setIsMapValue}}{{!
          }}{{#type:isContainer?}}
          {{function:nestedDepth++}}{{> WriteResponseType}}{{function:nestedDepth--}}
          {{/type:isContainer?}}{{!
          }}{{^type:isContainer?}}{{> WriteResponseType}}{{!
          }}{{/type:isContainer?}}{{/type:value_type}}
        }
        oprot.writeMapEnd();{{!
}}{{/type:map?}}{{!

}}{{#type:struct?}}{{!
}}{{#function:isNested?}}_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.write0(oprot);
{{/function:isNested?}}{{!
}}{{^function:isNested?}}oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.STRUCT_FIELD);
{{^struct:isUnion?}}{{/struct:isUnion?}}_iter0.write0(oprot);{{/function:isNested?}}{{!
}}{{/type:struct?}}{{!

}}{{#type:enum?}}{{!
}}{{#function:isNested?}}oprot.writeI32(_iter{{function:nestedDepth}} == null ? 0 : _iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}.getValue());
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.I32_FIELD);
oprot.writeI32({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0 == null ? 0 : {{^struct:isUnion?}}{{/struct:isUnion?}}_iter0.getValue());{{/function:isNested?}}{{!
}}{{/type:enum?}}{{!

}}{{#type:binary?}}{{!
}}{{#function:isNested?}}oprot.writeBinary({{^type:javaType}}java.nio.ByteBuffer.wrap{{/type:javaType}}(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}}));
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.STRING_FIELD);
oprot.writeBinary({{^type:javaType}}java.nio.ByteBuffer.wrap{{/type:javaType}}({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0));{{/function:isNested?}}{{!
}}{{/type:binary?}}{{!

}}{{#type:string?}}{{!
}}{{#function:isNested?}}oprot.writeString(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.STRING_FIELD);
oprot.writeString({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:string?}}{{!

}}{{#type:bool?}}{{!
}}{{#function:isNested?}}oprot.writeBool(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.BOOL_FIELD);
oprot.writeBool({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:bool?}}{{!

}}{{#type:byte?}}{{!
}}{{#function:isNested?}}oprot.writeByte(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.BYTE_FIELD);
oprot.writeByte({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:byte?}}{{!

}}{{#type:i16?}}{{!
}}{{#function:isNested?}}oprot.writeI16(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.I16_FIELD);
oprot.writeI16({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:i16?}}{{!

}}{{#type:i32?}}{{!
}}{{#function:isNested?}}oprot.writeI32(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.I32_FIELD);
oprot.writeI32({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:i32?}}{{!

}}{{#type:i64?}}{{!
}}{{#function:isNested?}}oprot.writeI64(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.I64_FIELD);
oprot.writeI64({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:i64?}}{{!

}}{{#type:float?}}{{!
}}{{#function:isNested?}}oprot.writeFloat(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.FLOAT_FIELD);
oprot.writeFloat({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:float?}}{{!

}}{{#type:double?}}{{!
}}{{#function:isNested?}}oprot.writeDouble(_iter{{function:nestedDepth}}{{#type:isMapKey?}}.getKey(){{/type:isMapKey?}}{{#type:isMapValue?}}.getValue(){{/type:isMapValue?}});
{{/function:isNested?}}{{!
}}{{^function:isNested?}}
oprot.writeFieldBegin(com.facebook.thrift.util.RpcPayloadUtil.DOUBLE_FIELD);
oprot.writeDouble({{^struct:isUnion?}}{{/struct:isUnion?}}_iter0);{{/function:isNested?}}{{!
}}{{/type:double?}}{{!

}}{{/type:typedef?}}{{!
}}
