summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. King III <jking@apache.org>2019-01-13 23:19:18 -0500
committerJames E. King III <jking@apache.org>2019-01-14 08:13:52 -0500
commit234fb47229dad47842e97a599614dbbd81b7c4a2 (patch)
treee1c75e2200041c4ef67b0ed2d1a5ac877012412f
parentf3ec277e7e2c147342831ecec590bc2f71b07761 (diff)
downloadthrift-234fb47229dad47842e97a599614dbbd81b7c4a2.tar.gz
THRIFT-4719: remove cocoa
-rw-r--r--Thrift-swift3.podspec16
-rw-r--r--Thrift.podspec10
-rw-r--r--build/docker/README.md1
-rwxr-xr-xbuild/veralign.sh3
-rw-r--r--compiler/cpp/CMakeLists.txt1
-rw-r--r--compiler/cpp/Makefile.am45
-rw-r--r--compiler/cpp/compiler.vcxproj10
-rw-r--r--compiler/cpp/src/thrift/generate/t_cocoa_generator.cc3309
-rw-r--r--compiler/cpp/src/thrift/thriftl.ll5
-rw-r--r--compiler/cpp/tests/CMakeLists.txt40
-rw-r--r--contrib/thrift.spec4
-rw-r--r--debian/copyright1
-rwxr-xr-xdoap.rdf3
-rw-r--r--doc/specs/idl.md32
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/cocoa/README.md21
-rw-r--r--lib/cocoa/coding_standards.md1
-rw-r--r--lib/cocoa/src/TApplicationError.h55
-rw-r--r--lib/cocoa/src/TApplicationError.m231
-rw-r--r--lib/cocoa/src/TBaseClient.h27
-rw-r--r--lib/cocoa/src/TBaseClient.m51
-rw-r--r--lib/cocoa/src/TBinary.swift122
-rw-r--r--lib/cocoa/src/TEnum.swift31
-rw-r--r--lib/cocoa/src/TError.h23
-rw-r--r--lib/cocoa/src/TError.m23
-rw-r--r--lib/cocoa/src/TList.swift148
-rw-r--r--lib/cocoa/src/TMap.swift158
-rw-r--r--lib/cocoa/src/TProcessor.h35
-rw-r--r--lib/cocoa/src/TProcessorFactory.h33
-rw-r--r--lib/cocoa/src/TProtocol.swift190
-rw-r--r--lib/cocoa/src/TSerializable.swift178
-rw-r--r--lib/cocoa/src/TSet.swift161
-rw-r--r--lib/cocoa/src/TSharedProcessorFactory.h28
-rw-r--r--lib/cocoa/src/TSharedProcessorFactory.m49
-rw-r--r--lib/cocoa/src/TStruct.swift31
-rw-r--r--lib/cocoa/src/Thrift.h20
-rw-r--r--lib/cocoa/src/protocol/TBase.h46
-rw-r--r--lib/cocoa/src/protocol/TBinaryProtocol.h49
-rw-r--r--lib/cocoa/src/protocol/TBinaryProtocol.m740
-rw-r--r--lib/cocoa/src/protocol/TCompactProtocol.h42
-rw-r--r--lib/cocoa/src/protocol/TCompactProtocol.m983
-rw-r--r--lib/cocoa/src/protocol/TMultiplexedProtocol.h38
-rw-r--r--lib/cocoa/src/protocol/TMultiplexedProtocol.m66
-rw-r--r--lib/cocoa/src/protocol/TProtocol.h164
-rw-r--r--lib/cocoa/src/protocol/TProtocolDecorator.h34
-rw-r--r--lib/cocoa/src/protocol/TProtocolDecorator.m295
-rw-r--r--lib/cocoa/src/protocol/TProtocolError.h76
-rw-r--r--lib/cocoa/src/protocol/TProtocolError.m33
-rw-r--r--lib/cocoa/src/protocol/TProtocolFactory.h36
-rw-r--r--lib/cocoa/src/protocol/TProtocolUtil.h33
-rw-r--r--lib/cocoa/src/protocol/TProtocolUtil.m171
-rw-r--r--lib/cocoa/src/server/TSocketServer.h51
-rw-r--r--lib/cocoa/src/server/TSocketServer.m239
-rw-r--r--lib/cocoa/src/transport/TAsyncTransport.h46
-rw-r--r--lib/cocoa/src/transport/TFramedTransport.h33
-rw-r--r--lib/cocoa/src/transport/TFramedTransport.m180
-rw-r--r--lib/cocoa/src/transport/THTTPSessionTransport.h47
-rw-r--r--lib/cocoa/src/transport/THTTPSessionTransport.m268
-rw-r--r--lib/cocoa/src/transport/THTTPTransport.h39
-rw-r--r--lib/cocoa/src/transport/THTTPTransport.m182
-rw-r--r--lib/cocoa/src/transport/TMemoryBuffer.h37
-rw-r--r--lib/cocoa/src/transport/TMemoryBuffer.m121
-rw-r--r--lib/cocoa/src/transport/TNSFileHandleTransport.h38
-rw-r--r--lib/cocoa/src/transport/TNSFileHandleTransport.m118
-rw-r--r--lib/cocoa/src/transport/TNSStreamTransport.h43
-rw-r--r--lib/cocoa/src/transport/TNSStreamTransport.m153
-rw-r--r--lib/cocoa/src/transport/TSSLSocketTransport.h37
-rw-r--r--lib/cocoa/src/transport/TSSLSocketTransport.m304
-rw-r--r--lib/cocoa/src/transport/TSSLSocketTransportError.h30
-rw-r--r--lib/cocoa/src/transport/TSSLSocketTransportError.m23
-rw-r--r--lib/cocoa/src/transport/TSocketTransport.h36
-rw-r--r--lib/cocoa/src/transport/TSocketTransport.m131
-rw-r--r--lib/cocoa/src/transport/TTransport.h48
-rw-r--r--lib/cocoa/src/transport/TTransportError.h43
-rw-r--r--lib/cocoa/src/transport/TTransportError.m27
-rw-r--r--lib/cpp/test/OneWayTest.thrift1
-rw-r--r--test/ThriftTest.thrift19
77 files changed, 71 insertions, 10126 deletions
diff --git a/Thrift-swift3.podspec b/Thrift-swift3.podspec
deleted file mode 100644
index 126c00b24..000000000
--- a/Thrift-swift3.podspec
+++ /dev/null
@@ -1,16 +0,0 @@
-Pod::Spec.new do |s|
- s.name = "Thrift-swift3"
- s.version = "1.0.0"
- s.summary = "Apache Thrift is a lightweight, language-independent software stack with an associated code generation mechanism for RPC."
- s.description = <<-DESC
-The Apache Thrift scalable cross-language software framework for networked services development combines a software stack with a code generation engine to build services that work efficiently and seamlessly between many programming languages.
- DESC
- s.homepage = "http://thrift.apache.org"
- s.license = { :type => 'Apache License, Version 2.0', :url => 'https://www.apache.org/licenses/LICENSE-2.0' }
- s.author = { "Apache Thrift Developers" => "dev@thrift.apache.org" }
- s.ios.deployment_target = '9.0'
- s.osx.deployment_target = '10.10'
- s.requires_arc = true
- s.source = { :git => "https://github.com/apache/thrift.git", :tag => "v1.0.0" }
- s.source_files = "lib/swift/Sources/*.swift"
-end
diff --git a/Thrift.podspec b/Thrift.podspec
index a406eec23..126c00b24 100644
--- a/Thrift.podspec
+++ b/Thrift.podspec
@@ -1,5 +1,5 @@
Pod::Spec.new do |s|
- s.name = "Thrift"
+ s.name = "Thrift-swift3"
s.version = "1.0.0"
s.summary = "Apache Thrift is a lightweight, language-independent software stack with an associated code generation mechanism for RPC."
s.description = <<-DESC
@@ -8,11 +8,9 @@ The Apache Thrift scalable cross-language software framework for networked servi
s.homepage = "http://thrift.apache.org"
s.license = { :type => 'Apache License, Version 2.0', :url => 'https://www.apache.org/licenses/LICENSE-2.0' }
s.author = { "Apache Thrift Developers" => "dev@thrift.apache.org" }
+ s.ios.deployment_target = '9.0'
+ s.osx.deployment_target = '10.10'
s.requires_arc = true
- s.ios.deployment_target = '7.0'
- s.osx.deployment_target = '10.8'
- s.ios.framework = 'CFNetwork'
- s.osx.framework = 'CoreServices'
s.source = { :git => "https://github.com/apache/thrift.git", :tag => "v1.0.0" }
- s.source_files = 'lib/cocoa/src/**/*.{h,m,swift}'
+ s.source_files = "lib/swift/Sources/*.swift"
end
diff --git a/build/docker/README.md b/build/docker/README.md
index 966d690c9..d00f87d66 100644
--- a/build/docker/README.md
+++ b/build/docker/README.md
@@ -174,7 +174,6 @@ Last updated: October 1, 2017
| C# (mono) | 4.2.1.0 | 4.6.2.7 | |
| c_glib | 2.48.2 | 2.56.0 | |
| cl (sbcl) | | 1.4.15 | |
-| cocoa | | | Not in CI |
| d | 2.075.1 | 2.083.1 | |
| dart | 1.22.1 | 1.24.3 | |
| delphi | | | Not in CI |
diff --git a/build/veralign.sh b/build/veralign.sh
index 4ed7c5174..c54de538b 100755
--- a/build/veralign.sh
+++ b/build/veralign.sh
@@ -50,13 +50,12 @@ FILES[doap.rdf]=manual
# These files can be updated automatically:
FILES[ApacheThrift.nuspec]=simpleReplace
FILES[CMakeLists.txt]=simpleReplace
-FILES[Thrift-swift3.podspec]=simpleReplace
FILES[Thrift.podspec]=simpleReplace
FILES[appveyor.yml]=simpleReplace
FILES[bower.json]=jsonReplace
FILES[configure.ac]=configureReplace
FILES[contrib/thrift.spec]=simpleReplace
-FILES[lib/cocoa/src/Thrift.h]=simpleReplace
+FILES[doc/specs/idl.md]=simpleReplace
FILES[lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs]=simpleReplace
FILES[lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj]=simpleReplace
FILES[lib/csharp/src/Properties/AssemblyInfo.cs]=simpleReplace
diff --git a/compiler/cpp/CMakeLists.txt b/compiler/cpp/CMakeLists.txt
index 96efe65ab..372cbab75 100644
--- a/compiler/cpp/CMakeLists.txt
+++ b/compiler/cpp/CMakeLists.txt
@@ -74,7 +74,6 @@ endmacro()
THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" ON)
-THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
diff --git a/compiler/cpp/Makefile.am b/compiler/cpp/Makefile.am
index 0b8ef2e7e..087f6bdbd 100644
--- a/compiler/cpp/Makefile.am
+++ b/compiler/cpp/Makefile.am
@@ -79,38 +79,37 @@ thrift_SOURCES = src/thrift/main.h \
src/thrift/audit/t_audit.h
# Specific client generator source
-thrift_SOURCES += src/thrift/generate/t_c_glib_generator.cc \
+thrift_SOURCES += src/thrift/generate/t_as3_generator.cc \
+ src/thrift/generate/t_c_glib_generator.cc \
+ src/thrift/generate/t_cl_generator.cc \
src/thrift/generate/t_cpp_generator.cc \
- src/thrift/generate/t_java_generator.cc \
- src/thrift/generate/t_json_generator.cc \
- src/thrift/generate/t_as3_generator.cc \
+ src/thrift/generate/t_csharp_generator.cc \
+ src/thrift/generate/t_d_generator.cc \
src/thrift/generate/t_dart_generator.cc \
+ src/thrift/generate/t_delphi_generator.cc \
+ src/thrift/generate/t_erl_generator.cc \
+ src/thrift/generate/t_go_generator.cc \
+ src/thrift/generate/t_gv_generator.cc \
src/thrift/generate/t_haxe_generator.cc \
- src/thrift/generate/t_csharp_generator.cc \
+ src/thrift/generate/t_hs_generator.cc \
+ src/thrift/generate/t_html_generator.cc \
+ src/thrift/generate/t_java_generator.cc \
+ src/thrift/generate/t_javame_generator.cc \
+ src/thrift/generate/t_js_generator.cc \
+ src/thrift/generate/t_json_generator.cc \
+ src/thrift/generate/t_lua_generator.cc \
src/thrift/generate/t_netcore_generator.cc \
src/thrift/generate/t_netcore_generator.h \
- src/thrift/generate/t_py_generator.cc \
- src/thrift/generate/t_rb_generator.cc \
+ src/thrift/generate/t_ocaml_generator.cc \
src/thrift/generate/t_perl_generator.cc \
src/thrift/generate/t_php_generator.cc \
- src/thrift/generate/t_erl_generator.cc \
- src/thrift/generate/t_cocoa_generator.cc \
- src/thrift/generate/t_swift_generator.cc \
+ src/thrift/generate/t_py_generator.cc \
+ src/thrift/generate/t_rb_generator.cc \
+ src/thrift/generate/t_rs_generator.cc \
src/thrift/generate/t_st_generator.cc \
- src/thrift/generate/t_ocaml_generator.cc \
- src/thrift/generate/t_hs_generator.cc \
- src/thrift/generate/t_xsd_generator.cc \
+ src/thrift/generate/t_swift_generator.cc \
src/thrift/generate/t_xml_generator.cc \
- src/thrift/generate/t_html_generator.cc \
- src/thrift/generate/t_js_generator.cc \
- src/thrift/generate/t_javame_generator.cc \
- src/thrift/generate/t_delphi_generator.cc \
- src/thrift/generate/t_go_generator.cc \
- src/thrift/generate/t_gv_generator.cc \
- src/thrift/generate/t_d_generator.cc \
- src/thrift/generate/t_lua_generator.cc \
- src/thrift/generate/t_rs_generator.cc \
- src/thrift/generate/t_cl_generator.cc
+ src/thrift/generate/t_xsd_generator.cc
thrift_CPPFLAGS = -I$(srcdir)/src
thrift_CXXFLAGS = -Wall -Wextra -pedantic -Werror
diff --git a/compiler/cpp/compiler.vcxproj b/compiler/cpp/compiler.vcxproj
index 0628b54c8..3b597280b 100644
--- a/compiler/cpp/compiler.vcxproj
+++ b/compiler/cpp/compiler.vcxproj
@@ -54,11 +54,10 @@
<ClCompile Include="src\thrift\audit\t_audit.cpp" />
<ClCompile Include="src\thrift\common.cc" />
<ClCompile Include="src\thrift\generate\t_as3_generator.cc" />
- <ClCompile Include="src\thrift\generate\t_cocoa_generator.cc" />
+ <ClCompile Include="src\thrift\generate\t_c_glib_generator.cc" />
+ <ClCompile Include="src\thrift\generate\t_cl_generator.cc" />
<ClCompile Include="src\thrift\generate\t_cpp_generator.cc" />
<ClCompile Include="src\thrift\generate\t_csharp_generator.cc" />
- <ClCompile Include="src\thrift\generate\t_netcore_generator.cc" />
- <ClCompile Include="src\thrift\generate\t_c_glib_generator.cc" />
<ClCompile Include="src\thrift\generate\t_d_generator.cc" />
<ClCompile Include="src\thrift\generate\t_dart_generator.cc" />
<ClCompile Include="src\thrift\generate\t_delphi_generator.cc" />
@@ -69,11 +68,12 @@
<ClCompile Include="src\thrift\generate\t_haxe_generator.cc" />
<ClCompile Include="src\thrift\generate\t_hs_generator.cc" />
<ClCompile Include="src\thrift\generate\t_html_generator.cc" />
- <ClCompile Include="src\thrift\generate\t_javame_generator.cc" />
<ClCompile Include="src\thrift\generate\t_java_generator.cc" />
+ <ClCompile Include="src\thrift\generate\t_javame_generator.cc" />
<ClCompile Include="src\thrift\generate\t_js_generator.cc" />
<ClCompile Include="src\thrift\generate\t_json_generator.cc" />
<ClCompile Include="src\thrift\generate\t_lua_generator.cc" />
+ <ClCompile Include="src\thrift\generate\t_netcore_generator.cc" />
<ClCompile Include="src\thrift\generate\t_ocaml_generator.cc" />
<ClCompile Include="src\thrift\generate\t_perl_generator.cc" />
<ClCompile Include="src\thrift\generate\t_php_generator.cc" />
@@ -247,4 +247,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc b/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc
deleted file mode 100644
index ac644f5c5..000000000
--- a/compiler/cpp/src/thrift/generate/t_cocoa_generator.cc
+++ /dev/null
@@ -1,3309 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <vector>
-
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sstream>
-#include "thrift/platform.h"
-#include "thrift/generate/t_oop_generator.h"
-
-using std::map;
-using std::ostream;
-using std::ofstream;
-using std::ostringstream;
-using std::string;
-using std::stringstream;
-using std::vector;
-
-static const string endl = "\n"; // avoid ostream << std::endl flushes
-
-/**
- * Objective-C code generator.
- *
- * mostly copy/pasting/tweaking from mcslee's work.
- */
-class t_cocoa_generator : public t_oop_generator {
-public:
- t_cocoa_generator(t_program* program,
- const std::map<std::string, std::string>& parsed_options,
- const std::string& option_string)
- : t_oop_generator(program) {
- (void)option_string;
- std::map<std::string, std::string>::const_iterator iter;
-
- log_unexpected_ = false;
- validate_required_ = false;
- async_clients_ = false;
- promise_kit_ = false;
- debug_descriptions_ = false;
- pods_ = false;
- for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
- if( iter->first.compare("log_unexpected") == 0) {
- log_unexpected_ = true;
- } else if( iter->first.compare("validate_required") == 0) {
- validate_required_ = true;
- } else if( iter->first.compare("async_clients") == 0) {
- async_clients_ = true;
- } else if( iter->first.compare("promise_kit") == 0) {
- promise_kit_ = true;
- } else if( iter->first.compare("debug_descriptions") == 0) {
- debug_descriptions_ = true;
- } else if( iter->first.compare("pods") == 0) {
- pods_ = true;
- } else {
- throw "unknown option cocoa:" + iter->first;
- }
- }
-
- out_dir_base_ = "gen-cocoa";
- }
-
- /**
- * Init and close methods
- */
-
- void init_generator();
- void close_generator();
-
- void generate_consts(std::vector<t_const*> consts);
-
- /**
- * Program-level generation functions
- */
-
- void generate_typedef(t_typedef* ttypedef);
- void generate_enum(t_enum* tenum);
- void generate_struct(t_struct* tstruct);
- void generate_xception(t_struct* txception);
- void generate_service(t_service* tservice);
-
- void print_const_value(ostream& out,
- string name,
- t_type* type,
- t_const_value* value,
- bool defval = false);
- std::string render_const_value(ostream& out,
- t_type* type,
- t_const_value* value,
- bool box_it = false);
-
- void generate_cocoa_struct(t_struct* tstruct, bool is_exception);
- void generate_cocoa_struct_interface(std::ostream& out,
- t_struct* tstruct,
- bool is_xception = false);
- void generate_cocoa_struct_implementation(std::ostream& out,
- t_struct* tstruct,
- bool is_xception = false,
- bool is_result = false);
- void generate_cocoa_struct_initializer_signature(std::ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_init_with_coder_method(ostream& out,
- t_struct* tstruct,
- bool is_exception);
- void generate_cocoa_struct_encode_with_coder_method(ostream& out,
- t_struct* tstruct,
- bool is_exception);
- void generate_cocoa_struct_copy_method(ostream& out,
- t_struct* tstruct,
- bool is_exception);
- void generate_cocoa_struct_hash_method(ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_is_equal_method(ostream& out,
- t_struct* tstruct,
- bool is_exception);
- void generate_cocoa_struct_field_accessor_implementations(std::ostream& out,
- t_struct* tstruct,
- bool is_exception);
- void generate_cocoa_struct_reader(std::ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_result_writer(std::ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_writer(std::ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_validator(std::ostream& out, t_struct* tstruct);
- void generate_cocoa_struct_description(std::ostream& out, t_struct* tstruct);
-
- std::string function_result_helper_struct_type(t_service *tservice, t_function* tfunction);
- std::string function_args_helper_struct_type(t_service* tservice, t_function* tfunction);
- void generate_function_helpers(t_service *tservice, t_function* tfunction);
-
- /**
- * Service-level generation functions
- */
-
- void generate_cocoa_service_protocol(std::ostream& out, t_service* tservice);
- void generate_cocoa_service_async_protocol(std::ostream& out, t_service* tservice);
-
- void generate_cocoa_service_client_interface(std::ostream& out, t_service* tservice);
- void generate_cocoa_service_client_async_interface(std::ostream& out, t_service* tservice);
-
- void generate_cocoa_service_client_send_function_implementation(ostream& out,
- t_service* tservice,
- t_function* tfunction,
- bool needs_protocol);
- void generate_cocoa_service_client_send_function_invocation(ostream& out, t_function* tfunction);
- void generate_cocoa_service_client_send_async_function_invocation(ostream& out,
- t_function* tfunction,
- string failureBlockName);
- void generate_cocoa_service_client_recv_function_implementation(ostream& out,
- t_service* tservice,
- t_function* tfunction,
- bool needs_protocol);
- void generate_cocoa_service_client_implementation(std::ostream& out, t_service* tservice);
- void generate_cocoa_service_client_async_implementation(std::ostream& out, t_service* tservice);
-
- void generate_cocoa_service_server_interface(std::ostream& out, t_service* tservice);
- void generate_cocoa_service_server_implementation(std::ostream& out, t_service* tservice);
- void generate_cocoa_service_helpers(t_service* tservice);
- void generate_service_client(t_service* tservice);
- void generate_service_server(t_service* tservice);
- void generate_process_function(t_service* tservice, t_function* tfunction);
-
- /**
- * Serialization constructs
- */
-
- void generate_deserialize_field(std::ostream& out, t_field* tfield, std::string fieldName);
-
- void generate_deserialize_struct(std::ostream& out, t_struct* tstruct, std::string prefix = "");
-
- void generate_deserialize_container(std::ostream& out, t_type* ttype, std::string prefix = "");
-
- void generate_deserialize_set_element(std::ostream& out, t_set* tset, std::string prefix = "");
-
- void generate_deserialize_map_element(std::ostream& out, t_map* tmap, std::string prefix = "");
-
- void generate_deserialize_list_element(std::ostream& out,
- t_list* tlist,
- std::string prefix = "");
-
- void generate_serialize_field(std::ostream& out, t_field* tfield, std::string prefix = "");
-
- void generate_serialize_struct(std::ostream& out, t_struct* tstruct, std::string fieldName = "");
-
- void generate_serialize_container(std::ostream& out, t_type* ttype, std::string prefix = "");
-
- void generate_serialize_map_element(std::ostream& out,
- t_map* tmap,
- std::string iter,
- std::string map);
-
- void generate_serialize_set_element(std::ostream& out, t_set* tmap, std::string iter);
-
- void generate_serialize_list_element(std::ostream& out,
- t_list* tlist,
- std::string index,
- std::string listName);
-
- /**
- * Helper rendering functions
- */
-
- std::string cocoa_prefix();
- std::string cocoa_imports();
- std::string cocoa_thrift_imports();
- std::string type_name(t_type* ttype, bool class_ref = false, bool needs_mutable = false);
- std::string element_type_name(t_type* ttype);
- std::string base_type_name(t_base_type* tbase);
- std::string declare_property(t_field* tfield);
- std::string declare_property_isset(t_field* tfield);
- std::string declare_property_unset(t_field* tfield);
- std::string invalid_return_statement(t_function* tfunction);
- std::string function_signature(t_function* tfunction, bool include_error);
- std::string async_function_signature(t_function* tfunction, bool include_error);
- std::string promise_function_signature(t_function* tfunction);
- std::string argument_list(t_struct* tstruct, string protocol_name, bool include_error);
- std::string type_to_enum(t_type* ttype);
- std::string format_string_for_type(t_type* type);
- std::string format_cast_for_type(t_type* type);
- std::string call_field_setter(t_field* tfield, std::string fieldName);
- std::string box(t_type *ttype, std::string field_name);
- std::string unbox(t_type* ttype, std::string field_name);
- std::string getter_name(string field_name);
- std::string setter_name(string field_name);
-
- bool type_can_be_copy(t_type* ttype) {
- ttype = get_true_type(ttype);
-
- return ttype->is_string();
- }
-
- bool type_can_be_null(t_type* ttype) {
- ttype = get_true_type(ttype);
-
- return ttype->is_container() || ttype->is_struct() || ttype->is_xception()
- || ttype->is_string();
- }
-
-private:
- std::string cocoa_prefix_;
- std::string constants_declarations_;
- int error_constant_;
-
- /**
- * File streams
- */
-
- ofstream_with_content_based_conditional_update f_header_;
- ofstream_with_content_based_conditional_update f_impl_;
-
- bool log_unexpected_;
- bool validate_required_;
- bool async_clients_;
- bool promise_kit_;
- bool debug_descriptions_;
- bool pods_;
-};
-
-/**
- * Prepares for file generation by opening up the necessary file output
- * streams.
- */
-void t_cocoa_generator::init_generator() {
- // Make output directory
- MKDIR(get_out_dir().c_str());
- cocoa_prefix_ = program_->get_namespace("cocoa");
-
- // we have a .h header file...
- string f_header_name = cocoa_prefix_ + capitalize(program_name_) + ".h";
- string f_header_fullname = get_out_dir() + f_header_name;
- f_header_.open(f_header_fullname.c_str());
-
- f_header_ << autogen_comment() << endl;
-
- f_header_ << cocoa_imports() << cocoa_thrift_imports();
-
- // ...and a .m implementation file
- string f_impl_name = cocoa_prefix_ + capitalize(program_name_) + ".m";
- string f_impl_fullname = get_out_dir() + f_impl_name;
- f_impl_.open(f_impl_fullname.c_str());
-
- f_impl_ << autogen_comment() << endl;
-
- f_impl_ << cocoa_imports() << cocoa_thrift_imports() << "#import \"" << f_header_name << "\""
- << endl << endl;
-
- error_constant_ = 60000;
-}
-
-/**
- * Prints standard Cocoa imports
- *
- * @return List of imports for Cocoa libraries
- */
-string t_cocoa_generator::cocoa_imports() {
- return string() + "#import <Foundation/Foundation.h>\n" + "\n";
-}
-
-/**
- * Prints thrift runtime imports
- *
- * @return List of imports necessary for thrift runtime
- */
-string t_cocoa_generator::cocoa_thrift_imports() {
-
- vector<string> includes_list;
- includes_list.push_back("TProtocol.h");
- includes_list.push_back("TProtocolFactory.h");
- includes_list.push_back("TApplicationError.h");
- includes_list.push_back("TProtocolError.h");
- includes_list.push_back("TProtocolUtil.h");
- includes_list.push_back("TProcessor.h");
- includes_list.push_back("TBase.h");
- includes_list.push_back("TAsyncTransport.h");
- includes_list.push_back("TBaseClient.h");
-
- std::ostringstream includes;
-
- vector<string>::const_iterator i_iter;
- for (i_iter=includes_list.begin(); i_iter!=includes_list.end(); ++i_iter) {
- includes << "#import ";
- if (pods_) {
- includes << "<Thrift/" << *i_iter << ">";
- } else {
- includes << "\"" << *i_iter << "\"";
- }
- includes << endl;
- }
-
- includes << endl;
-
- if (promise_kit_) {
- includes << "#import ";
- if (pods_) {
- includes << "<PromiseKit/PromiseKit.h>";
- } else {
- includes << "\"PromiseKit.h\"";
- }
- includes << endl;
- }
-
- // Include other Thrift includes
- const vector<t_program*>& other_includes = program_->get_includes();
- for (size_t i = 0; i < other_includes.size(); ++i) {
- includes << "#import \""
- << other_includes[i]->get_namespace("cocoa")
- << capitalize(other_includes[i]->get_name())
- << ".h\"" << endl;
- }
-
- includes << endl;
-
- return includes.str();
-}
-
-/**
- * Finish up generation.
- */
-void t_cocoa_generator::close_generator() {
- // stick our constants declarations at the end of the header file
- // since they refer to things we are defining.
- f_header_ << constants_declarations_ << endl;
-}
-
-/**
- * Generates a typedef. This is just a simple 1-liner in objective-c
- *
- * @param ttypedef The type definition
- */
-void t_cocoa_generator::generate_typedef(t_typedef* ttypedef) {
- if (ttypedef->get_type()->is_map()) {
- t_map *map = (t_map *)ttypedef->get_type();
- if (map->get_key_type()->is_struct()) {
- f_header_ << indent() << "@class " << type_name(map->get_key_type(), true) << ";" << endl;
- }
- if (map->get_val_type()->is_struct()) {
- f_header_ << indent() << "@class " << type_name(map->get_val_type(), true) << ";" << endl;
- }
- }
- else if (ttypedef->get_type()->is_set()) {
- t_set *set = (t_set *)ttypedef->get_type();
- if (set->get_elem_type()->is_struct()) {
- f_header_ << indent() << "@class " << type_name(set->get_elem_type(), true) << ";" << endl;
- }
- }
- else if (ttypedef->get_type()->is_list()) {
- t_list *list = (t_list *)ttypedef->get_type();
- if (list->get_elem_type()->is_struct()) {
- f_header_ << indent() << "@class " << type_name(list->get_elem_type(), true) << ";" << endl;
- }
- }
- f_header_ << indent() << "typedef " << type_name(ttypedef->get_type()) << " " << cocoa_prefix_
- << ttypedef->get_symbolic() << ";" << endl << endl;
- if (ttypedef->get_type()->is_container()) {
- f_header_ << indent() << "typedef " << type_name(ttypedef->get_type(), false, true) << " " << cocoa_prefix_
- << "Mutable" << ttypedef->get_symbolic() << ";" << endl << endl;
- }
-}
-
-/**
- * Generates code for an enumerated type. In Objective-C, this is
- * essentially the same as the thrift definition itself, instead using
- * NS_ENUM keyword in Objective-C. For namespace purposes, the name of
- * the enum is prefixed to each element in keeping with Cocoa & Swift
- * standards.
- *
- * @param tenum The enumeration
- */
-void t_cocoa_generator::generate_enum(t_enum* tenum) {
- f_header_ << indent() << "typedef NS_ENUM(SInt32, " << cocoa_prefix_ << tenum->get_name() << ") {" << endl;
- indent_up();
-
- vector<t_enum_value*> constants = tenum->get_constants();
- vector<t_enum_value*>::iterator c_iter;
- bool first = true;
- for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
- if (first) {
- first = false;
- } else {
- f_header_ << "," << endl;
- }
- f_header_ << indent() << cocoa_prefix_ << tenum->get_name() << (*c_iter)->get_name();
- f_header_ << " = " << (*c_iter)->get_value();
- }
-
- indent_down();
- f_header_ << endl << "};" << endl << endl;
-}
-
-/**
- * Generates a class that holds all the constants.
- */
-void t_cocoa_generator::generate_consts(std::vector<t_const*> consts) {
- std::ostringstream const_interface;
-
- const_interface << "FOUNDATION_EXPORT NSString *" << cocoa_prefix_ << capitalize(program_name_) << "ErrorDomain;" << endl
- << endl;
-
-
- bool needs_class = false;
-
- // Public constants for base types & strings
- vector<t_const*>::iterator c_iter;
- for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- t_type* type = (*c_iter)->get_type()->get_true_type();
- if (!type->is_container() && !type->is_struct()) {
- const_interface << "FOUNDATION_EXPORT " << type_name(type) << " "
- << cocoa_prefix_ << capitalize((*c_iter)->get_name()) << ";" << endl;
- }
- else {
- needs_class = true;
- }
- }
-
-
- string constants_class_name = cocoa_prefix_ + capitalize(program_name_) + "Constants";
-
- if (needs_class) {
-
- const_interface << endl;
-
- const_interface << "@interface " << constants_class_name << " : NSObject ";
- scope_up(const_interface);
- scope_down(const_interface);
-
- // getter method for each constant defined.
- for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- string name = (*c_iter)->get_name();
- t_type* type = (*c_iter)->get_type()->get_true_type();
- if (type->is_container() || type->is_struct()) {
- t_type* type = (*c_iter)->get_type();
- const_interface << endl << "+ (" << type_name(type) << ") " << name << ";" << endl;
- }
- }
-
- const_interface << endl << "@end";
- }
-
- // this gets spit into the header file in ::close_generator
- constants_declarations_ = const_interface.str();
-
- f_impl_ << "NSString *" << cocoa_prefix_ << capitalize(program_name_) << "ErrorDomain = "
- << "@\"" << cocoa_prefix_ << capitalize(program_name_) << "ErrorDomain\";" << endl << endl;
-
- // variables in the .m hold all simple constant values
- for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- string name = (*c_iter)->get_name();
- t_type* type = (*c_iter)->get_type();
- f_impl_ << type_name(type) << " " << cocoa_prefix_ << name;
- t_type* ttype = type->get_true_type();
- if (!ttype->is_container() && !ttype->is_struct()) {
- f_impl_ << " = " << render_const_value(f_impl_, type, (*c_iter)->get_value());
- }
- f_impl_ << ";" << endl;
- }
- f_impl_ << endl;
-
- if (needs_class) {
-
- f_impl_ << "@implementation " << constants_class_name << endl << endl;
-
- // initialize complex constants when the class is loaded
- f_impl_ << "+ (void) initialize ";
- scope_up(f_impl_);
-
- for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- t_type* ttype = (*c_iter)->get_type()->get_true_type();
- if (ttype->is_container() || ttype->is_struct()) {
- f_impl_ << endl;
- print_const_value(f_impl_,
- cocoa_prefix_ + (*c_iter)->get_name(),
- (*c_iter)->get_type(),
- (*c_iter)->get_value(),
- false);
- f_impl_ << ";" << endl;
- }
- }
- scope_down(f_impl_);
-
- // getter method for each constant
- for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
- string name = (*c_iter)->get_name();
- t_type* type = (*c_iter)->get_type()->get_true_type();
- if (type->is_container() || type->is_struct()) {
- f_impl_ << endl << "+ (" << type_name(type) << ") " << name << " ";
- scope_up(f_impl_);
- indent(f_impl_) << "return " << cocoa_prefix_ << name << ";" << endl;
- scope_down(f_impl_);
- }
- }
-
- f_impl_ << "@end" << endl << endl;
- }
-}
-
-/**
- * Generates a struct definition for a thrift data type. This is a class
- * with protected data members, read(), write(), and getters and setters.
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_struct(t_struct* tstruct) {
- generate_cocoa_struct_interface(f_header_, tstruct, false);
- generate_cocoa_struct_implementation(f_impl_, tstruct, false);
-}
-
-/**
- * Exceptions are structs, but they inherit from NSException
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_xception(t_struct* txception) {
- generate_cocoa_struct_interface(f_header_, txception, true);
- generate_cocoa_struct_implementation(f_impl_, txception, true);
-}
-
-/**
- * Generate the interface for a struct
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_interface(ostream& out,
- t_struct* tstruct,
- bool is_exception) {
-
- if (is_exception) {
- out << "enum {" << endl
- << " " << cocoa_prefix_ << capitalize(program_name_) << "Error" << tstruct->get_name() << " = -" << error_constant_++ << endl
- << "};" << endl
- << endl;
- }
-
- out << "@interface " << cocoa_prefix_ << tstruct->get_name() << " : ";
-
- if (is_exception) {
- out << "NSError ";
- } else {
- out << "NSObject ";
- }
- out << "<TBase, NSCoding, NSCopying> " << endl;
-
- out << endl;
-
- // properties
- const vector<t_field*>& members = tstruct->get_members();
- if (members.size() > 0) {
- vector<t_field*>::const_iterator m_iter;
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- out << indent() << declare_property(*m_iter) << endl;
- out << indent() << declare_property_isset(*m_iter) << endl;
- out << indent() << declare_property_unset(*m_iter) << endl;
- out << endl;
- }
- }
-
- out << endl;
-
- // initializer for all fields
- if (!members.empty()) {
- generate_cocoa_struct_initializer_signature(out, tstruct);
- out << ";" << endl;
- }
- out << endl;
-
- out << "@end" << endl << endl;
-}
-
-/**
- * Generate signature for initializer of struct with a parameter for
- * each field.
- */
-void t_cocoa_generator::generate_cocoa_struct_initializer_signature(ostream& out,
- t_struct* tstruct) {
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
- indent(out) << "- (instancetype) initWith";
- for (m_iter = members.begin(); m_iter != members.end();) {
- if (m_iter == members.begin()) {
- out << capitalize((*m_iter)->get_name());
- } else {
- out << (*m_iter)->get_name();
- }
- out << ": (" << type_name((*m_iter)->get_type()) << ") " << (*m_iter)->get_name();
- ++m_iter;
- if (m_iter != members.end()) {
- out << " ";
- }
- }
-}
-
-/**
- * Generate the initWithCoder method for this struct so it's compatible with
- * the NSCoding protocol
- */
-void t_cocoa_generator::generate_cocoa_struct_init_with_coder_method(ostream& out,
- t_struct* tstruct,
- bool is_exception) {
-
- indent(out) << "- (instancetype) initWithCoder: (NSCoder *) decoder" << endl;
- scope_up(out);
-
- if (is_exception) {
- // NSExceptions conform to NSCoding, so we can call super
- indent(out) << "self = [super initWithCoder: decoder];" << endl;
- } else {
- indent(out) << "self = [super init];" << endl;
- }
-
- indent(out) << "if (self) ";
- scope_up(out);
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- out << indent() << "if ([decoder containsValueForKey: @\"" << (*m_iter)->get_name() << "\"])"
- << endl;
- scope_up(out);
- out << indent() << "_" << (*m_iter)->get_name() << " = ";
- if (type_can_be_null(t)) {
- out << "[decoder decodeObjectForKey: @\"" << (*m_iter)->get_name() << "\"];"
- << endl;
- } else if (t->is_enum()) {
- out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- } else {
- t_base_type::t_base tbase = ((t_base_type*)t)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_BOOL:
- out << "[decoder decodeBoolForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I8:
- out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I16:
- out << "[decoder decodeIntForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I32:
- out << "[decoder decodeInt32ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I64:
- out << "[decoder decodeInt64ForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_DOUBLE:
- out << "[decoder decodeDoubleForKey: @\"" << (*m_iter)->get_name() << "\"];" << endl;
- break;
- default:
- throw "compiler error: don't know how to decode thrift type: "
- + t_base_type::t_base_name(tbase);
- }
- }
- out << indent() << "_" << (*m_iter)->get_name() << "IsSet = YES;" << endl;
- scope_down(out);
- }
-
- scope_down(out);
-
- out << indent() << "return self;" << endl;
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generate the encodeWithCoder method for this struct so it's compatible with
- * the NSCoding protocol
- */
-void t_cocoa_generator::generate_cocoa_struct_encode_with_coder_method(ostream& out,
- t_struct* tstruct,
- bool is_exception) {
-
- indent(out) << "- (void) encodeWithCoder: (NSCoder *) encoder" << endl;
- scope_up(out);
-
- if (is_exception) {
- // NSExceptions conform to NSCoding, so we can call super
- out << indent() << "[super encodeWithCoder: encoder];" << endl;
- }
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- out << indent() << "if (_" << (*m_iter)->get_name() << "IsSet)" << endl;
- scope_up(out);
- if (type_can_be_null(t)) {
- out << indent() << "[encoder encodeObject: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- } else if (t->is_enum()) {
- out << indent() << "[encoder encodeInt: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- } else {
- t_base_type::t_base tbase = ((t_base_type*)t)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_BOOL:
- out << indent() << "[encoder encodeBool: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I8:
- out << indent() << "[encoder encodeInt: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I16:
- out << indent() << "[encoder encodeInt: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I32:
- out << indent() << "[encoder encodeInt32: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_I64:
- out << indent() << "[encoder encodeInt64: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- case t_base_type::TYPE_DOUBLE:
- out << indent() << "[encoder encodeDouble: _" << (*m_iter)->get_name() << " forKey: @\""
- << (*m_iter)->get_name() << "\"];" << endl;
- break;
- default:
- throw "compiler error: don't know how to encode thrift type: "
- + t_base_type::t_base_name(tbase);
- }
- }
- scope_down(out);
- }
-
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generate the copy method for this struct
- */
-void t_cocoa_generator::generate_cocoa_struct_copy_method(ostream& out, t_struct* tstruct, bool is_exception) {
- out << indent() << "- (instancetype) copyWithZone:(NSZone *)zone" << endl;
- scope_up(out);
-
- if (is_exception) {
- out << indent() << type_name(tstruct) << " val = [" << cocoa_prefix_ << tstruct->get_name() << " errorWithDomain: self.domain code: self.code userInfo: self.userInfo];" << endl;
- } else {
- out << indent() << type_name(tstruct) << " val = [" << cocoa_prefix_ << tstruct->get_name() << " new];" << endl;
- }
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- out << indent() << "if (_" << (*m_iter)->get_name() << "IsSet)" << endl;
- scope_up(out);
- if (type_can_be_null(t)) {
- out << indent() << "val." << (*m_iter)->get_name() << " = [self." << (*m_iter)->get_name() << " copy];";
- } else {
- out << indent() << "val." << (*m_iter)->get_name() << " = self." << (*m_iter)->get_name() << ";";
- }
- out << endl;
- scope_down(out);
- }
-
- out << indent() << "return val;" << endl;
-
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generate the hash method for this struct
- */
-void t_cocoa_generator::generate_cocoa_struct_hash_method(ostream& out, t_struct* tstruct) {
- indent(out) << "- (NSUInteger) hash" << endl;
- scope_up(out);
- out << indent() << "NSUInteger hash = 17;" << endl;
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- out << indent() << "hash = (hash * 31) ^ _" << (*m_iter)->get_name()
- << "IsSet ? 2654435761 : 0;" << endl;
- out << indent() << "if (_" << (*m_iter)->get_name() << "IsSet)" << endl;
- scope_up(out);
- if (type_can_be_null(t)) {
- out << indent() << "hash = (hash * 31) ^ [_" << (*m_iter)->get_name() << " hash];" << endl;
- } else {
- out << indent() << "hash = (hash * 31) ^ [@(_" << (*m_iter)->get_name() << ") hash];"
- << endl;
- }
- scope_down(out);
- }
-
- out << indent() << "return hash;" << endl;
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generate the isEqual method for this struct
- */
-void t_cocoa_generator::generate_cocoa_struct_is_equal_method(ostream& out, t_struct* tstruct, bool is_exception) {
- indent(out) << "- (BOOL) isEqual: (id) anObject" << endl;
- scope_up(out);
-
- indent(out) << "if (self == anObject) {" << endl;
- indent_up();
- indent(out) << "return YES;" << endl;
- indent_down();
- indent(out) << "}" << endl;
-
- string class_name = cocoa_prefix_ + tstruct->get_name();
-
- if (is_exception) {
- indent(out) << "if (![super isEqual:anObject]) {" << endl;
- indent_up();
- indent(out) << "return NO;" << endl;
- indent_down();
- indent(out) << "}" << endl << endl;
- }
- else {
- indent(out) << "if (![anObject isKindOfClass:[" << class_name << " class]]) {" << endl;
- indent_up();
- indent(out) << "return NO;" << endl;
- indent_down();
- indent(out) << "}" << endl;
- }
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- if (!members.empty()) {
- indent(out) << class_name << " *other = (" << class_name << " *)anObject;" << endl;
-
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- string name = (*m_iter)->get_name();
- if (type_can_be_null(t)) {
- out << indent() << "if ((_" << name << "IsSet != other->_" << name << "IsSet) ||" << endl
- << indent() << " "
- << "(_" << name << "IsSet && "
- << "((_" << name << " || other->_" << name << ") && "
- << "![_" << name << " isEqual:other->_" << name << "]))) {" << endl;
- } else {
- out << indent() << "if ((_" << name << "IsSet != other->_" << name << "IsSet) ||" << endl
- << indent() << " "
- << "(_" << name << "IsSet && "
- << "(_" << name << " != other->_" << name << "))) {" << endl;
- }
- indent_up();
- indent(out) << "return NO;" << endl;
- indent_down();
- indent(out) << "}" << endl;
- }
- }
-
- out << indent() << "return YES;" << endl;
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generate struct implementation.
- *
- * @param tstruct The struct definition
- * @param is_exception Is this an exception?
- * @param is_result If this is a result it needs a different writer
- */
-void t_cocoa_generator::generate_cocoa_struct_implementation(ostream& out,
- t_struct* tstruct,
- bool is_exception,
- bool is_result) {
- indent(out) << "@implementation " << cocoa_prefix_ << tstruct->get_name() << endl << endl;
-
- const vector<t_field*>& members = tstruct->get_members();
- vector<t_field*>::const_iterator m_iter;
-
- // exceptions need to call the designated initializer on NSException
- if (is_exception) {
- out << indent() << "- (instancetype) init" << endl;
- scope_up(out);
- out << indent() << "return [super initWithDomain: " << cocoa_prefix_ << capitalize(program_name_) << "ErrorDomain" << endl
- << indent() << " code: " << cocoa_prefix_ << capitalize(program_name_) << "Error" << tstruct->get_name() << endl
- << indent() << " userInfo: nil];" << endl;
- scope_down(out);
- out << endl;
- } else {
- // struct
-
- // default initializer
- // setup instance variables with default values
- indent(out) << "- (instancetype) init" << endl;
- scope_up(out);
- indent(out) << "self = [super init];" << endl;
- indent(out) << "if (self)";
- scope_up(out);
- if (members.size() > 0) {
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- t_type* t = get_true_type((*m_iter)->get_type());
- if ((*m_iter)->get_value() != NULL) {
- print_const_value(out,
- "self." + (*m_iter)->get_name(),
- t,
- (*m_iter)->get_value(),
- false);
- }
- }
- }
- scope_down(out);
- indent(out) << "return self;" << endl;
- scope_down(out);
- out << endl;
- }
-
- // initializer with all fields as params
- if (!members.empty()) {
- generate_cocoa_struct_initializer_signature(out, tstruct);
- out << endl;
- scope_up(out);
- if (is_exception) {
- out << indent() << "self = [self init];" << endl;
- } else {
- out << indent() << "self = [super init];" << endl;
- }
-
- indent(out) << "if (self)";
- scope_up(out);
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- out << indent() << "_" << (*m_iter)->get_name() << " = ";
- if (get_true_type((*m_iter)->get_type())->is_container()) {
- out << "[" << (*m_iter)->get_name() << " mutableCopy];" << endl;
- } else {
- out << (*m_iter)->get_name() << ";" << endl;
- }
- out << indent() << "_" << (*m_iter)->get_name() << "IsSet = YES;" << endl;
- }
- scope_down(out);
-
- out << indent() << "return self;" << endl;
- scope_down(out);
- out << endl;
- }
-
- // initWithCoder for NSCoding
- generate_cocoa_struct_init_with_coder_method(out, tstruct, is_exception);
- // encodeWithCoder for NSCoding
- generate_cocoa_struct_encode_with_coder_method(out, tstruct, is_exception);
- // hash and isEqual for NSObject
- generate_cocoa_struct_hash_method(out, tstruct);
- generate_cocoa_struct_is_equal_method(out, tstruct, is_exception);
- // copy for NSObject
- generate_cocoa_struct_copy_method(out, tstruct, is_exception);
-
- // the rest of the methods
- generate_cocoa_struct_field_accessor_implementations(out, tstruct, is_exception);
- generate_cocoa_struct_reader(out, tstruct);
- if (is_result) {
- generate_cocoa_struct_result_writer(out, tstruct);
- } else {
- generate_cocoa_struct_writer(out, tstruct);
- }
- generate_cocoa_struct_validator(out, tstruct);
- generate_cocoa_struct_description(out, tstruct);
-
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a function to read all the fields of the struct.
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_reader(ostream& out, t_struct* tstruct) {
- out << "- (BOOL) read: (id <TProtocol>) inProtocol error: (NSError *__autoreleasing *)__thriftError" << endl;
- scope_up(out);
-
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
-
- // Declare stack tmp variables
- indent(out) << "NSString * fieldName;" << endl;
- indent(out) << "SInt32 fieldType;" << endl;
- indent(out) << "SInt32 fieldID;" << endl;
- out << endl;
-
- indent(out) << "if (![inProtocol readStructBeginReturningName: NULL error: __thriftError]) return NO;" << endl;
-
- // Loop over reading in fields
- indent(out) << "while (true)" << endl;
- scope_up(out);
-
- // Read beginning field marker
- indent(out)
- << "if (![inProtocol readFieldBeginReturningName: &fieldName type: &fieldType fieldID: &fieldID error: __thriftError]) return NO;"
- << endl;
-
- // Check for field STOP marker and break
- indent(out) << "if (fieldType == TTypeSTOP) { " << endl;
- indent_up();
- indent(out) << "break;" << endl;
- indent_down();
- indent(out) << "}" << endl;
-
- // Switch statement on the field we are reading
- indent(out) << "switch (fieldID)" << endl;
-
- scope_up(out);
-
- // Generate deserialization code for known cases
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- indent(out) << "case " << (*f_iter)->get_key() << ":" << endl;
- indent_up();
- indent(out) << "if (fieldType == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
- indent_up();
-
- generate_deserialize_field(out, *f_iter, "fieldValue");
- indent(out) << call_field_setter(*f_iter, "fieldValue") << endl;
-
- indent_down();
- out << indent() << "} else { " << endl;
- if (log_unexpected_) {
- out << indent() << " NSLog(@\"%s: field ID %i has unexpected type %i. Skipping.\", "
- "__PRETTY_FUNCTION__, (int)fieldID, (int)fieldType);" << endl;
- }
-
- out << indent() << " if (![TProtocolUtil skipType: fieldType onProtocol: inProtocol error: __thriftError]) return NO;" << endl;
- out << indent() << "}" << endl << indent() << "break;" << endl;
- indent_down();
- }
-
- // In the default case we skip the field
- out << indent() << "default:" << endl;
- if (log_unexpected_) {
- out << indent() << " NSLog(@\"%s: unexpected field ID %i with type %i. Skipping.\", "
- "__PRETTY_FUNCTION__, (int)fieldID, (int)fieldType);" << endl;
- }
-
- out << indent() << " if (![TProtocolUtil skipType: fieldType onProtocol: inProtocol error: __thriftError]) return NO;" << endl;
-
- out << indent() << " break;" << endl;
-
- scope_down(out);
-
- // Read field end marker
- indent(out) << "if (![inProtocol readFieldEnd: __thriftError]) return NO;" << endl;
-
- scope_down(out);
-
- out << indent() << "if (![inProtocol readStructEnd: __thriftError]) return NO;" << endl;
-
- // performs various checks (e.g. check that all required fields are set)
- if (validate_required_) {
- out << indent() << "if (![self validate: __thriftError]) return NO;" << endl;
- }
-
- indent(out) << "return YES;" << endl;
-
- indent_down();
- out << indent() << "}" << endl << endl;
-}
-
-/**
- * Generates a function to write all the fields of the struct
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_writer(ostream& out, t_struct* tstruct) {
- out << indent() << "- (BOOL) write: (id <TProtocol>) outProtocol error: (NSError *__autoreleasing *)__thriftError {" << endl;
- indent_up();
-
- string name = tstruct->get_name();
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
-
- out << indent() << "if (![outProtocol writeStructBeginWithName: @\"" << name << "\" error: __thriftError]) return NO;" << endl;
-
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- out << indent() << "if (_" << (*f_iter)->get_name() << "IsSet) {" << endl;
- indent_up();
- bool null_allowed = type_can_be_null((*f_iter)->get_type());
- if (null_allowed) {
- out << indent() << "if (_" << (*f_iter)->get_name() << " != nil) {" << endl;
- indent_up();
- }
-
- indent(out) << "if (![outProtocol writeFieldBeginWithName: @\"" << (*f_iter)->get_name()
- << "\" type: " << type_to_enum((*f_iter)->get_type())
- << " fieldID: " << (*f_iter)->get_key() << " error: __thriftError]) return NO;" << endl;
-
- // Write field contents
- generate_serialize_field(out, *f_iter, "_" + (*f_iter)->get_name());
-
- // Write field closer
- indent(out) << "if (![outProtocol writeFieldEnd: __thriftError]) return NO;" << endl;
-
- if (null_allowed) {
- scope_down(out);
- }
- scope_down(out);
- }
- // Write the struct map
- out << indent() << "if (![outProtocol writeFieldStop: __thriftError]) return NO;" << endl
- << indent() << "if (![outProtocol writeStructEnd: __thriftError]) return NO;" << endl;
-
- indent(out) << "return YES;" << endl;
-
- indent_down();
- out << indent() << "}" << endl << endl;
-}
-
-/**
- * Generates a function to write all the fields of the struct, which
- * is a function result. These fields are only written if they are
- * set, and only one of them can be set at a time.
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_result_writer(ostream& out, t_struct* tstruct) {
- out << indent() << "- (BOOL) write: (id <TProtocol>) outProtocol error: (NSError *__autoreleasing *)__thriftError {" << endl;
- indent_up();
-
- string name = tstruct->get_name();
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
-
- out << indent() << "if (![outProtocol writeStructBeginWithName: @\"" << name << "\" error: __thriftError]) return NO;" << endl;
-
- bool first = true;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if (first) {
- first = false;
- out << endl << indent() << "if ";
- } else {
- out << " else if ";
- }
-
- out << "(_" << (*f_iter)->get_name() << "IsSet) {" << endl;
- indent_up();
-
- bool null_allowed = type_can_be_null((*f_iter)->get_type());
- if (null_allowed) {
- out << indent() << "if (_" << (*f_iter)->get_name() << " != nil) {" << endl;
- indent_up();
- }
-
- indent(out) << "if (![outProtocol writeFieldBeginWithName: @\"" << (*f_iter)->get_name()
- << "\" type: " << type_to_enum((*f_iter)->get_type())
- << " fieldID: " << (*f_iter)->get_key() << " error: __thriftError]) return NO;" << endl;
-
- // Write field contents
- generate_serialize_field(out, *f_iter, "_" + (*f_iter)->get_name());
-
- // Write field closer
- indent(out) << "if (![outProtocol writeFieldEnd: __thriftError]) return NO;" << endl;
-
- if (null_allowed) {
- indent_down();
- indent(out) << "}" << endl;
- }
-
- indent_down();
- indent(out) << "}";
- }
- // Write the struct map
- out << endl << indent() << "if (![outProtocol writeFieldStop: __thriftError]) return NO;"
- << endl << indent() << "if (![outProtocol writeStructEnd: __thriftError]) return NO;"
- << endl;
-
- indent(out) << "return YES;" << endl;
-
- indent_down();
- out << indent() << "}" << endl << endl;
-}
-
-/**
- * Generates a function to perform various checks
- * (e.g. check that all required fields are set)
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_validator(ostream& out, t_struct* tstruct) {
- out << indent() << "- (BOOL) validate: (NSError *__autoreleasing *)__thriftError {" << endl;
- indent_up();
-
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
-
- out << indent() << "// check for required fields" << endl;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- t_field* field = (*f_iter);
- if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
- out << indent() << "if (!_" << field->get_name() << "IsSet) ";
- scope_up(out);
- indent(out) << "if (__thriftError) ";
- scope_up(out);
- out << indent() << "*__thriftError = [NSError errorWithDomain: TProtocolErrorDomain" << endl
- << indent() << " code: TProtocolErrorUnknown" << endl
- << indent() << " userInfo: @{TProtocolErrorExtendedErrorKey: @(TProtocolExtendedErrorMissingRequiredField)," << endl
- << indent() << " TProtocolErrorFieldNameKey: @\"" << (*f_iter)->get_name() << "\"}];" << endl;
- scope_down(out);
- scope_down(out);
- }
- }
- indent(out) << "return YES;" << endl;
- indent_down();
- out << indent() << "}" << endl << endl;
-}
-
-/**
- * Generate property accessor methods for all fields in the struct.
- * getter, setter, isset getter.
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_field_accessor_implementations(ostream& out,
- t_struct* tstruct,
- bool is_exception) {
- (void)is_exception;
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- t_field* field = *f_iter;
- t_type* type = get_true_type(field->get_type());
- std::string field_name = field->get_name();
- std::string cap_name = field_name;
- cap_name[0] = toupper(cap_name[0]);
-
- // Simple setter
- indent(out) << "- (void) set" << cap_name << ": (" << type_name(type, false, true) << ") " << field_name
- << " {" << endl;
- indent_up();
- indent(out) << "_" << field_name << " = " << field_name << ";" << endl;
- indent(out) << "_" << field_name << "IsSet = YES;" << endl;
- indent_down();
- indent(out) << "}" << endl << endl;
-
- // Unsetter - do we need this?
- indent(out) << "- (void) unset" << cap_name << " {" << endl;
- indent_up();
- if (type_can_be_null(type)) {
- indent(out) << "_" << field_name << " = nil;" << endl;
- }
- indent(out) << "_" << field_name << "IsSet = NO;" << endl;
- indent_down();
- indent(out) << "}" << endl << endl;
- }
-}
-
-/**
- * Generates a description method for the given struct
- *
- * @param tstruct The struct definition
- */
-void t_cocoa_generator::generate_cocoa_struct_description(ostream& out, t_struct* tstruct) {
-
- // Allow use of debugDescription so the app can add description via a cateogory/extension
- if (debug_descriptions_) {
- out << indent() << "- (NSString *) debugDescription {" << endl;
- }
- else {
- out << indent() << "- (NSString *) description {" << endl;
- }
- indent_up();
-
- out << indent() << "NSMutableString * ms = [NSMutableString stringWithString: @\""
- << cocoa_prefix_ << tstruct->get_name() << "(\"];" << endl;
-
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
- bool first = true;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if (first) {
- first = false;
- indent(out) << "[ms appendString: @\"" << (*f_iter)->get_name() << ":\"];" << endl;
- } else {
- indent(out) << "[ms appendString: @\"," << (*f_iter)->get_name() << ":\"];" << endl;
- }
- t_type* ttype = (*f_iter)->get_type();
- indent(out) << "[ms appendFormat: @\"" << format_string_for_type(ttype) << "\", "
- << format_cast_for_type(ttype) << "_" << (*f_iter)->get_name() << "];" << endl;
- }
- out << indent() << "[ms appendString: @\")\"];" << endl << indent()
- << "return [NSString stringWithString: ms];" << endl;
-
- indent_down();
- indent(out) << "}" << endl << endl;
-}
-
-/**
- * Generates a thrift service. In Objective-C this consists of a
- * protocol definition, a client interface and a client implementation.
- *
- * @param tservice The service definition
- */
-void t_cocoa_generator::generate_service(t_service* tservice) {
- generate_cocoa_service_protocol(f_header_, tservice);
- generate_cocoa_service_client_interface(f_header_, tservice);
- generate_cocoa_service_server_interface(f_header_, tservice);
- generate_cocoa_service_helpers(tservice);
- generate_cocoa_service_client_implementation(f_impl_, tservice);
- generate_cocoa_service_server_implementation(f_impl_, tservice);
- if (async_clients_) {
- generate_cocoa_service_async_protocol(f_header_, tservice);
- generate_cocoa_service_client_async_interface(f_header_, tservice);
- generate_cocoa_service_client_async_implementation(f_impl_, tservice);
- }
-}
-
-/**
- * Generates structs for all the service return types
- *
- * @param tservice The service
- */
-void t_cocoa_generator::generate_cocoa_service_helpers(t_service* tservice) {
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
-
- t_struct* ts = (*f_iter)->get_arglist();
-
- string qname = function_args_helper_struct_type(tservice, *f_iter);
-
- t_struct qname_ts = t_struct(ts->get_program(), qname);
-
- const vector<t_field*>& members = ts->get_members();
- vector<t_field*>::const_iterator m_iter;
- for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
- qname_ts.append(*m_iter);
- }
-
- generate_cocoa_struct_interface(f_impl_, &qname_ts, false);
- generate_cocoa_struct_implementation(f_impl_, &qname_ts, false, false);
- generate_function_helpers(tservice, *f_iter);
- }
-}
-
-string t_cocoa_generator::function_result_helper_struct_type(t_service *tservice, t_function* tfunction) {
- if (tfunction->is_oneway()) {
- return tservice->get_name() + "_" + tfunction->get_name();
- } else {
- return tservice->get_name() + "_" + tfunction->get_name() + "_result";
- }
-}
-
-string t_cocoa_generator::function_args_helper_struct_type(t_service *tservice, t_function* tfunction) {
- return tservice->get_name() + "_" + tfunction->get_name() + "_args";
-}
-
-/**
- * Generates a struct and helpers for a function.
- *
- * @param tfunction The function
- */
-void t_cocoa_generator::generate_function_helpers(t_service *tservice, t_function* tfunction) {
- if (tfunction->is_oneway()) {
- return;
- }
-
- // create a result struct with a success field of the return type,
- // and a field for each type of exception thrown
- t_struct result(program_, function_result_helper_struct_type(tservice, tfunction));
- t_field success(tfunction->get_returntype(), "success", 0);
- if (!tfunction->get_returntype()->is_void()) {
- result.append(&success);
- }
-
- t_struct* xs = tfunction->get_xceptions();
- const vector<t_field*>& fields = xs->get_members();
- vector<t_field*>::const_iterator f_iter;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- result.append(*f_iter);
- }
-
- // generate the result struct
- generate_cocoa_struct_interface(f_impl_, &result, false);
- generate_cocoa_struct_implementation(f_impl_, &result, false, true);
-}
-
-/**
- * Generates a service protocol definition.
- *
- * @param tservice The service to generate a protocol definition for
- */
-void t_cocoa_generator::generate_cocoa_service_protocol(ostream& out, t_service* tservice) {
- out << "@protocol " << cocoa_prefix_ << tservice->get_name() << " <NSObject>" << endl;
-
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- out << "- " << function_signature(*f_iter, true) << ";"
- << " // throws ";
- t_struct* xs = (*f_iter)->get_xceptions();
- const std::vector<t_field*>& xceptions = xs->get_members();
- vector<t_field*>::const_iterator x_iter;
- for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- out << type_name((*x_iter)->get_type()) + ", ";
- }
- out << "TException" << endl;
- }
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates an asynchronous service protocol definition.
- *
- * @param tservice The service to generate a protocol definition for
- */
-void t_cocoa_generator::generate_cocoa_service_async_protocol(ostream& out, t_service* tservice) {
- out << "@protocol " << cocoa_prefix_ << tservice->get_name() << "Async"
- << " <NSObject>" << endl;
-
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- out << "- " << async_function_signature(*f_iter, false) << ";" << endl;
- if (promise_kit_) {
- out << "- " << promise_function_signature(*f_iter) << ";" << endl;
- }
- }
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a service client interface definition.
- *
- * @param tservice The service to generate a client interface definition for
- */
-void t_cocoa_generator::generate_cocoa_service_client_interface(ostream& out,
- t_service* tservice) {
- out << "@interface " << cocoa_prefix_ << tservice->get_name() << "Client : TBaseClient <"
- << cocoa_prefix_ << tservice->get_name() << "> " << endl;
-
- out << "- (id) initWithProtocol: (id <TProtocol>) protocol;" << endl;
- out << "- (id) initWithInProtocol: (id <TProtocol>) inProtocol outProtocol: (id <TProtocol>) "
- "outProtocol;" << endl;
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a service client interface definition.
- *
- * @param tservice The service to generate a client interface definition for
- */
-void t_cocoa_generator::generate_cocoa_service_client_async_interface(ostream& out,
- t_service* tservice) {
- out << "@interface " << cocoa_prefix_ << tservice->get_name() << "ClientAsync : TBaseClient <"
- << cocoa_prefix_ << tservice->get_name() << "Async> " << endl
- << endl;
-
- out << "- (id) initWithProtocolFactory: (id <TProtocolFactory>) protocolFactory "
- << "transportFactory: (id <TAsyncTransportFactory>) transportFactory;" << endl;
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a service server interface definition. In other words, the TProcess implementation for
- *the
- * service definition.
- *
- * @param tservice The service to generate a client interface definition for
- */
-void t_cocoa_generator::generate_cocoa_service_server_interface(ostream& out,
- t_service* tservice) {
- out << "@interface " << cocoa_prefix_ << tservice->get_name()
- << "Processor : NSObject <TProcessor> " << endl;
-
- out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_
- << tservice->get_name() << ">) service;" << endl;
- out << "- (id<" << cocoa_prefix_ << tservice->get_name() << ">) service;" << endl;
-
- out << "@end" << endl << endl;
-}
-
-void t_cocoa_generator::generate_cocoa_service_client_send_function_implementation(
- ostream& out,
- t_service *tservice,
- t_function* tfunction,
- bool needs_protocol) {
- string funname = tfunction->get_name();
-
- t_function send_function(g_type_bool,
- string("send_") + tfunction->get_name(),
- tfunction->get_arglist());
-
- string argsname = function_args_helper_struct_type(tservice, tfunction);
-
- // Open function
- indent(out) << "- (BOOL) send_" << tfunction->get_name() << argument_list(tfunction->get_arglist(), needs_protocol ? "outProtocol" : "", true) << endl;
- scope_up(out);
-
- // Serialize the request
- out << indent() << "if (![outProtocol writeMessageBeginWithName: @\"" << funname << "\""
- << (tfunction->is_oneway() ? " type: TMessageTypeONEWAY" : " type: TMessageTypeCALL")
- << " sequenceID: 0 error: __thriftError]) return NO;" << endl;
-
- out << indent() << "if (![outProtocol writeStructBeginWithName: @\"" << argsname
- << "\" error: __thriftError]) return NO;" << endl;
-
- // write out function parameters
- t_struct* arg_struct = tfunction->get_arglist();
- const vector<t_field*>& fields = arg_struct->get_members();
- vector<t_field*>::const_iterator fld_iter;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- string fieldName = (*fld_iter)->get_name();
- if (type_can_be_null((*fld_iter)->get_type())) {
- out << indent() << "if (" << fieldName << " != nil)";
- scope_up(out);
- }
- out << indent() << "if (![outProtocol writeFieldBeginWithName: @\"" << fieldName
- << "\""
- " type: " << type_to_enum((*fld_iter)->get_type())
- << " fieldID: " << (*fld_iter)->get_key() << " error: __thriftError]) return NO;" << endl;
-
- generate_serialize_field(out, *fld_iter, fieldName);
-
- out << indent() << "if (![outProtocol writeFieldEnd: __thriftError]) return NO;" << endl;
-
- if (type_can_be_null((*fld_iter)->get_type())) {
- indent_down();
- out << indent() << "}" << endl;
- }
- }
-
- out << indent() << "if (![outProtocol writeFieldStop: __thriftError]) return NO;" << endl;
- out << indent() << "if (![outProtocol writeStructEnd: __thriftError]) return NO;" << endl;
- out << indent() << "if (![outProtocol writeMessageEnd: __thriftError]) return NO;" << endl;
- out << indent() << "return YES;" << endl;
- scope_down(out);
- out << endl;
-}
-
-void t_cocoa_generator::generate_cocoa_service_client_recv_function_implementation(
- ostream& out,
- t_service* tservice,
- t_function* tfunction,
- bool needs_protocol) {
-
-
- // Open function
- indent(out) << "- (BOOL) recv_" << tfunction->get_name();
- if (!tfunction->get_returntype()->is_void()) {
- out << ": (" << type_name(tfunction->get_returntype(), false, true) << " *) result ";
- if (needs_protocol) {
- out << "protocol";
- } else {
- out << "error";
- }
- }
- if (needs_protocol) {
- out << ": (id<TProtocol>) inProtocol error";
- }
- out << ": (NSError *__autoreleasing *)__thriftError" << endl;
- scope_up(out);
-
- // TODO(mcslee): Message validation here, was the seqid etc ok?
-
- // check for an exception
- out << indent() << "NSError *incomingException = [self checkIncomingMessageException: inProtocol];" << endl
- << indent() << "if (incomingException)";
- scope_up(out);
- out << indent() << "if (__thriftError)";
- scope_up(out);
- out << indent() << "*__thriftError = incomingException;" << endl;
- scope_down(out);
- out << indent() << "return NO;" << endl;
- scope_down(out);
-
- // FIXME - could optimize here to reduce creation of temporary objects.
- string resultname = function_result_helper_struct_type(tservice, tfunction);
- out << indent() << cocoa_prefix_ << resultname << " * resulter = [" << cocoa_prefix_ << resultname << " new];" << endl;
- indent(out) << "if (![resulter read: inProtocol error: __thriftError]) return NO;" << endl;
- indent(out) << "if (![inProtocol readMessageEnd: __thriftError]) return NO;" << endl;
-
- // Careful, only return _result if not a void function
- if (!tfunction->get_returntype()->is_void()) {
- out << indent() << "if (resulter.successIsSet)";
- scope_up(out);
- out << indent() << "*result = resulter.success;" << endl;
- out << indent() << "return YES;" << endl;
- scope_down(out);
- }
-
- t_struct* xs = tfunction->get_xceptions();
- const std::vector<t_field*>& xceptions = xs->get_members();
- vector<t_field*>::const_iterator x_iter;
- for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
- out << indent() << "if (resulter." << (*x_iter)->get_name() << "IsSet)";
- scope_up(out);
- out << indent() << "if (__thriftError)";
- scope_up(out);
- out << indent() << "*__thriftError = [resulter " << (*x_iter)->get_name() << "];" << endl;
- scope_down(out);
- out << indent() << "return NO;" << endl;
- scope_down(out);
- }
-
- // If you get here it's an exception, unless a void function
- if (tfunction->get_returntype()->is_void()) {
- indent(out) << "return YES;" << endl;
- } else {
- out << indent() << "if (__thriftError)";
- scope_up(out);
- out << indent() << "*__thriftError = [NSError errorWithDomain: TApplicationErrorDomain" << endl
- << indent() << " code: TApplicationErrorMissingResult" << endl
- << indent() << " userInfo: @{TApplicationErrorMethodKey: @\""
- << tfunction->get_name() << "\"}];" << endl;
- scope_down(out);
- out << indent() << "return NO;" << endl;
- }
-
- // Close function
- scope_down(out);
- out << endl;
-}
-
-/**
- * Generates an invocation of a given 'send_' function.
- *
- * @param tfunction The service to generate an implementation for
- */
-void t_cocoa_generator::generate_cocoa_service_client_send_function_invocation(
- ostream& out,
- t_function* tfunction) {
-
- t_struct* arg_struct = tfunction->get_arglist();
- const vector<t_field*>& fields = arg_struct->get_members();
- vector<t_field*>::const_iterator fld_iter;
- out << indent() << "if (![self send_" << tfunction->get_name();
- bool first = true;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- string fieldName = (*fld_iter)->get_name();
- out << " ";
- if (first) {
- first = false;
- out << ": " << fieldName;
- } else {
- out << fieldName << ": " << fieldName;
- }
- }
- if (!fields.empty()) {
- out << " error";
- }
- out << ": __thriftError]) " << invalid_return_statement(tfunction) << endl;
-}
-
-/**
- * Generates an invocation of a given 'send_' function.
- *
- * @param tfunction The service to generate an implementation for
- */
-void t_cocoa_generator::generate_cocoa_service_client_send_async_function_invocation(
- ostream& out,
- t_function* tfunction,
- string failureBlockName) {
-
- t_struct* arg_struct = tfunction->get_arglist();
- const vector<t_field*>& fields = arg_struct->get_members();
- vector<t_field*>::const_iterator fld_iter;
- out << indent() << "if (![self send_" << tfunction->get_name();
- bool first = true;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- string fieldName = (*fld_iter)->get_name();
- out << " ";
- if (first) {
- first = false;
- out << ": " << fieldName;
- } else {
- out << fieldName << ": " << fieldName;
- }
- }
- if (!fields.empty()) {
- out << " protocol";
- }
- out << ": protocol error: &thriftError]) ";
- scope_up(out);
- out << indent() << failureBlockName << "(thriftError);" << endl
- << indent() << "return;" << endl;
- scope_down(out);
-}
-
-/**
- * Generates a service client implementation.
- *
- * @param tservice The service to generate an implementation for
- */
-void t_cocoa_generator::generate_cocoa_service_client_implementation(ostream& out,
- t_service* tservice) {
-
- string name = cocoa_prefix_ + tservice->get_name() + "Client";
-
- out << "@interface " << name << " () ";
- scope_up(out);
- out << endl;
- out << indent() << "id<TProtocol> inProtocol;" << endl;
- out << indent() << "id<TProtocol> outProtocol;" << endl;
- out << endl;
- scope_down(out);
- out << endl;
- out << "@end" << endl << endl;
-
- out << "@implementation " << name << endl;
-
- // initializers
- out << "- (id) initWithProtocol: (id <TProtocol>) protocol" << endl;
- scope_up(out);
- out << indent() << "return [self initWithInProtocol: protocol outProtocol: protocol];" << endl;
- scope_down(out);
- out << endl;
-
- out << "- (id) initWithInProtocol: (id <TProtocol>) anInProtocol outProtocol: (id <TProtocol>) "
- "anOutProtocol" << endl;
- scope_up(out);
- out << indent() << "self = [super init];" << endl;
- out << indent() << "if (self) ";
- scope_up(out);
- out << indent() << "inProtocol = anInProtocol;" << endl;
- out << indent() << "outProtocol = anOutProtocol;" << endl;
- scope_down(out);
- out << indent() << "return self;" << endl;
- scope_down(out);
- out << endl;
-
- // generate client method implementations
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::const_iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
-
- generate_cocoa_service_client_send_function_implementation(out, tservice, *f_iter, false);
-
- if (!(*f_iter)->is_oneway()) {
- generate_cocoa_service_client_recv_function_implementation(out, tservice, *f_iter, false);
- }
-
- // Open function
- indent(out) << "- " << function_signature(*f_iter, true) << endl;
- scope_up(out);
- generate_cocoa_service_client_send_function_invocation(out, *f_iter);
-
- out << indent() << "if (![[outProtocol transport] flush: __thriftError]) " << invalid_return_statement(*f_iter) << endl;
- if (!(*f_iter)->is_oneway()) {
- if ((*f_iter)->get_returntype()->is_void()) {
- out << indent() << "if (![self recv_" << (*f_iter)->get_name() << ": __thriftError]) return NO;" << endl;
- out << indent() << "return YES;" << endl;
- } else {
- out << indent() << type_name((*f_iter)->get_returntype(), false, true) << " __result;" << endl
- << indent() << "if (![self recv_" << (*f_iter)->get_name() << ": &__result error: __thriftError]) "
- << invalid_return_statement(*f_iter) << endl;
- if (type_can_be_null((*f_iter)->get_returntype())) {
- out << indent() << "return __result;" << endl;
- } else {
- out << indent() << "return @(__result);" << endl;
- }
- }
- }
- else {
- out << indent() << "return YES;" << endl;
- }
- scope_down(out);
- out << endl;
- }
-
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a service client implementation for its asynchronous interface.
- *
- * @param tservice The service to generate an implementation for
- */
-void t_cocoa_generator::generate_cocoa_service_client_async_implementation(ostream& out,
- t_service* tservice) {
-
- string name = cocoa_prefix_ + tservice->get_name() + "ClientAsync";
-
- out << "@interface " << name << " () ";
- scope_up(out);
- out << endl;
- out << indent() << "id<TProtocolFactory> protocolFactory;" << endl;
- out << indent() << "id<TAsyncTransportFactory> transportFactory;" << endl;
- out << endl;
- scope_down(out);
- out << endl;
- out << "@end" << endl << endl;
-
-
- out << "@implementation " << name << endl
- << endl << "- (id) initWithProtocolFactory: (id <TProtocolFactory>) aProtocolFactory "
- "transportFactory: (id <TAsyncTransportFactory>) aTransportFactory;" << endl;
-
- scope_up(out);
- out << indent() << "self = [super init];" << endl;
- out << indent() << "if (self) {" << endl;
- out << indent() << " protocolFactory = aProtocolFactory;" << endl;
- out << indent() << " transportFactory = aTransportFactory;" << endl;
- out << indent() << "}" << endl;
- out << indent() << "return self;" << endl;
- scope_down(out);
- out << endl;
-
- // generate client method implementations
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::const_iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
-
- generate_cocoa_service_client_send_function_implementation(out, tservice, *f_iter, true);
-
- if (!(*f_iter)->is_oneway()) {
- generate_cocoa_service_client_recv_function_implementation(out, tservice, *f_iter, true);
- }
-
- // Open function
- indent(out) << "- " << async_function_signature(*f_iter, false) << endl;
- scope_up(out);
-
- out << indent() << "NSError *thriftError;" << endl
- << indent() << "id<TAsyncTransport> transport = [transportFactory newTransport];" << endl
- << indent() << "id<TProtocol> protocol = [protocolFactory newProtocolOnTransport:transport];" << endl
- << endl;
-
- generate_cocoa_service_client_send_async_function_invocation(out, *f_iter, "failureBlock");
-
- out << indent() << "[transport flushWithCompletion:^{" << endl;
- indent_up();
-
- if (!(*f_iter)->is_oneway()) {
- out << indent() << "NSError *thriftError;" << endl;
-
- if (!(*f_iter)->get_returntype()->is_void()) {
- out << indent() << type_name((*f_iter)->get_returntype()) << " result;" << endl;
- }
- out << indent() << "if (![self recv_" << (*f_iter)->get_name();
- if (!(*f_iter)->get_returntype()->is_void()) {
- out << ": &result protocol";
- }
- out << ": protocol error: &thriftError]) ";
- scope_up(out);
- out << indent() << "failureBlock(thriftError);" << endl
- << indent() << "return;" << endl;
- scope_down(out);
- }
-
- out << indent() << "responseBlock(";
- if (!(*f_iter)->is_oneway() && !(*f_iter)->get_returntype()->is_void()) {
- out << "result";
- }
- out << ");" << endl;
-
- indent_down();
-
- out << indent() << "} failure:failureBlock];" << endl;
-
- scope_down(out);
-
- out << endl;
-
- // Promise function
- if (promise_kit_) {
-
- indent(out) << "- " << promise_function_signature(*f_iter) << endl;
- scope_up(out);
-
- out << indent() << "return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolver) {" << endl;
- indent_up();
-
- out << indent() << "NSError *thriftError;" << endl
- << indent() << "id<TAsyncTransport> transport = [transportFactory newTransport];" << endl
- << indent() << "id<TProtocol> protocol = [protocolFactory newProtocolOnTransport:transport];" << endl
- << endl;
-
- generate_cocoa_service_client_send_async_function_invocation(out, *f_iter, "resolver");
-
- out << indent() << "[transport flushWithCompletion:^{" << endl;
- indent_up();
-
- if (!(*f_iter)->is_oneway()) {
- out << indent() << "NSError *thriftError;" << endl;
-
- if (!(*f_iter)->get_returntype()->is_void()) {
- out << indent() << type_name((*f_iter)->get_returntype()) << " result;" << endl;
- }
- out << indent() << "if (![self recv_" << (*f_iter)->get_name();
- if (!(*f_iter)->get_returntype()->is_void()) {
- out << ": &result protocol";
- }
- out << ": protocol error: &thriftError]) ";
- scope_up(out);
- out << indent() << "resolver(thriftError);" << endl
- << indent() << "return;" << endl;
- scope_down(out);
- }
-
- out << indent() << "resolver(";
- if ((*f_iter)->is_oneway() || (*f_iter)->get_returntype()->is_void()) {
- out << "@YES";
- } else if (type_can_be_null((*f_iter)->get_returntype())) {
- out << "result";
- } else {
- out << "@(result)";
- }
- out << ");" << endl;
-
- indent_down();
-
- out << indent() << "} failure:^(NSError *error) {" << endl;
- indent_up();
- out << indent() << "resolver(error);" << endl;
- indent_down();
- out << indent() << "}];" << endl;
-
- indent_down();
- out << indent() << "}];" << endl;
-
- scope_down(out);
-
- out << endl;
-
- }
-
- }
-
- out << "@end" << endl << endl;
-}
-
-/**
- * Generates a service server implementation. In other words the actual TProcessor implementation
- * for the service.
- *
- * @param tservice The service to generate an implementation for
- */
-void t_cocoa_generator::generate_cocoa_service_server_implementation(ostream& out,
- t_service* tservice) {
-
- string name = cocoa_prefix_ + tservice->get_name() + "Processor";
-
- out << "@interface " << name << " () ";
-
- scope_up(out);
- out << indent() << "id <" << cocoa_prefix_ << tservice->get_name() << "> service;" << endl;
- out << indent() << "NSDictionary * methodMap;" << endl;
- scope_down(out);
-
- out << "@end" << endl << endl;
-
- out << "@implementation " << name << endl;
-
- // initializer
- out << endl;
- out << "- (id) initWith" << tservice->get_name() << ": (id <" << cocoa_prefix_ << tservice->get_name() << ">) aService" << endl;
- scope_up(out);
- out << indent() << "self = [super init];" << endl;
- out << indent() << "if (self) ";
- scope_up(out);
- out << indent() << "service = aService;" << endl;
- out << indent() << "methodMap = [NSMutableDictionary dictionary];" << endl;
-
- // generate method map for routing incoming calls
- vector<t_function*> functions = tservice->get_functions();
- vector<t_function*>::const_iterator f_iter;
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- string funname = (*f_iter)->get_name();
- scope_up(out);
- out << indent() << "SEL s = @selector(process_" << funname << "_withSequenceID:inProtocol:outProtocol:error:);" << endl;
- out << indent() << "NSMethodSignature * sig = [self methodSignatureForSelector: s];" << endl;
- out << indent() << "NSInvocation * invocation = [NSInvocation invocationWithMethodSignature: sig];" << endl;
- out << indent() << "[invocation setSelector: s];" << endl;
- out << indent() << "[invocation retainArguments];" << endl;
- out << indent() << "[methodMap setValue: invocation forKey: @\"" << funname << "\"];" << endl;
- scope_down(out);
- }
- scope_down(out);
- out << indent() << "return self;" << endl;
- scope_down(out);
-
- // implementation of the 'service' method which returns the service associated with this
- // processor
- out << endl;
- out << indent() << "- (id<" << cocoa_prefix_ << tservice->get_name() << ">) service" << endl;
- out << indent() << "{" << endl;
- out << indent() << " return service;" << endl;
- out << indent() << "}" << endl;
-
- // implementation of the TProcess method, which dispatches the incoming call using the method map
- out << endl;
- out << indent() << "- (BOOL) processOnInputProtocol: (id <TProtocol>) inProtocol" << endl;
- out << indent() << " outputProtocol: (id <TProtocol>) outProtocol" << endl;
- out << indent() << " error: (NSError *__autoreleasing *)__thriftError" << endl;
- out << indent() << "{" << endl;
- out << indent() << " NSString * messageName;" << endl;
- out << indent() << " SInt32 messageType;" << endl;
- out << indent() << " SInt32 seqID;" << endl;
- out << indent() << " if (![inProtocol readMessageBeginReturningName: &messageName" << endl;
- out << indent() << " type: &messageType" << endl;
- out << indent() << " sequenceID: &seqID" << endl;
- out << indent() << " error: __thriftError]) return NO;" << endl;
- out << indent() << " NSInvocation * invocation = [methodMap valueForKey: messageName];" << endl;
- out << indent() << " if (invocation == nil) {" << endl;
- out << indent() << " if (![TProtocolUtil skipType: TTypeSTRUCT onProtocol: inProtocol error: __thriftError]) return NO;" << endl;
- out << indent() << " if (![inProtocol readMessageEnd: __thriftError]) return NO;" << endl;
- out << indent() << " NSError * x = [NSError errorWithDomain: TApplicationErrorDomain" << endl;
- out << indent() << " code: TApplicationErrorUnknownMethod" << endl;
- out << indent() << " userInfo: @{TApplicationErrorMethodKey: messageName}];" << endl;
- out << indent() << " if (![outProtocol writeMessageBeginWithName: messageName" << endl;
- out << indent() << " type: TMessageTypeEXCEPTION" << endl;
- out << indent() << " sequenceID: seqID" << endl;
- out << indent() << " error: __thriftError]) return NO;" << endl;
- out << indent() << " if (![x write: outProtocol error: __thriftError]) return NO;" << endl;
- out << indent() << " if (![outProtocol writeMessageEnd: __thriftError]) return NO;" << endl;
- out << indent() << " if (![[outProtocol transport] flush: __thriftError]) return NO;" << endl;
- out << indent() << " return YES;" << endl;
- out << indent() << " }" << endl;
- out << indent() << " // NSInvocation does not conform to NSCopying protocol" << endl;
- out << indent() << " NSInvocation * i = [NSInvocation invocationWithMethodSignature: "
- "[invocation methodSignature]];" << endl;
- out << indent() << " [i setSelector: [invocation selector]];" << endl;
- out << indent() << " [i setArgument: &seqID atIndex: 2];" << endl;
- out << indent() << " [i setArgument: &inProtocol atIndex: 3];" << endl;
- out << indent() << " [i setArgument: &outProtocol atIndex: 4];" << endl;
- out << indent() << " [i setArgument: &__thriftError atIndex: 5];" << endl;
- out << indent() << " [i setTarget: self];" << endl;
- out << indent() << " [i invoke];" << endl;
- out << indent() << " return YES;" << endl;
- out << indent() << "}" << endl;
-
- // generate a process_XXXX method for each service function, which reads args, calls the service,
- // and writes results
- functions = tservice->get_functions();
- for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
- out << endl;
- string funname = (*f_iter)->get_name();
- out << indent() << "- (BOOL) process_" << funname
- << "_withSequenceID: (SInt32) seqID inProtocol: (id<TProtocol>) inProtocol outProtocol: "
- "(id<TProtocol>) outProtocol error:(NSError *__autoreleasing *)__thriftError" << endl;
- scope_up(out);
- string argstype = cocoa_prefix_ + function_args_helper_struct_type(tservice, *f_iter);
- out << indent() << argstype << " * args = [" << argstype << " new];" << endl;
- out << indent() << "if (![args read: inProtocol error: __thriftError]) return NO;" << endl;
- out << indent() << "if (![inProtocol readMessageEnd: __thriftError]) return NO;" << endl;
-
- // prepare the result if not oneway
- if (!(*f_iter)->is_oneway()) {
- string resulttype = cocoa_prefix_ + function_result_helper_struct_type(tservice, *f_iter);
- out << indent() << resulttype << " * result = [" << resulttype << " new];" << endl;
- }
-
- // make the call to the actual service object
- out << indent();
- if ((*f_iter)->get_returntype()->is_void()) {
- out << "BOOL";
- } else if (type_can_be_null((*f_iter)->get_returntype())) {
- out << type_name((*f_iter)->get_returntype(), false, true);
- } else {
- out << "NSNumber *";
- }
- out << " serviceResult = ";
- if ((*f_iter)->get_returntype()->get_true_type()->is_container()) {
- out << "(" << type_name((*f_iter)->get_returntype(), false, true) << ")";
- }
- out << "[service " << funname;
- // supplying arguments
- t_struct* arg_struct = (*f_iter)->get_arglist();
- const vector<t_field*>& fields = arg_struct->get_members();
- vector<t_field*>::const_iterator fld_iter;
- bool first = true;
- for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
- string fieldName = (*fld_iter)->get_name();
- if (first) {
- first = false;
- out << ": [args " << fieldName << "]";
- } else {
- out << " " << fieldName << ": [args " << fieldName << "]";
- }
- }
- if (!fields.empty()) {
- out << " error";
- }
- out << ": __thriftError];" << endl;
- out << indent() << "if (!serviceResult) return NO;" << endl;
- if (!(*f_iter)->get_returntype()->is_void()) {
- out << indent() << "[result setSuccess: " << unbox((*f_iter)->get_returntype(), "serviceResult") << "];" << endl;
- }
-
- // write out the result if not oneway
- if (!(*f_iter)->is_oneway()) {
- out << indent() << "if (![outProtocol writeMessageBeginWithName: @\"" << funname << "\"" << endl;
- out << indent() << " type: TMessageTypeREPLY" << endl;
- out << indent() << " sequenceID: seqID" << endl;
- out << indent() << " error: __thriftError]) return NO;" << endl;
- out << indent() << "if (![result write: outProtocol error: __thriftError]) return NO;" << endl;
- out << indent() << "if (![outProtocol writeMessageEnd: __thriftError]) return NO;" << endl;
- out << indent() << "if (![[outProtocol transport] flush: __thriftError]) return NO;" << endl;
- }
- out << indent() << "return YES;" << endl;
-
- scope_down(out);
- }
-
- out << "@end" << endl << endl;
-}
-
-/**
- * Deserializes a field of any type.
- *
- * @param tfield The field
- * @param fieldName The variable name for this field
- */
-void t_cocoa_generator::generate_deserialize_field(ostream& out,
- t_field* tfield,
- string fieldName) {
- t_type* type = get_true_type(tfield->get_type());
-
- if (type->is_void()) {
- throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + tfield->get_name();
- }
-
- if (type->is_struct() || type->is_xception()) {
- generate_deserialize_struct(out, (t_struct*)type, fieldName);
- } else if (type->is_container()) {
- generate_deserialize_container(out, type, fieldName);
- } else if (type->is_base_type() || type->is_enum()) {
- indent(out) << type_name(type) << " " << fieldName << ";" << endl;
- indent(out) << "if (![inProtocol ";
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "compiler error: cannot serialize void field in a struct: " + tfield->get_name();
- break;
- case t_base_type::TYPE_STRING:
- if (type->is_binary()) {
- out << "readBinary:&" << fieldName << " error: __thriftError]";
- } else {
- out << "readString:&" << fieldName << " error: __thriftError]";
- }
- break;
- case t_base_type::TYPE_BOOL:
- out << "readBool:&" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I8:
- out << "readByte:(UInt8 *)&" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I16:
- out << "readI16:&" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I32:
- out << "readI32:&" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I64:
- out << "readI64:&" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_DOUBLE:
- out << "readDouble:&" << fieldName << " error: __thriftError]";
- break;
- default:
- throw "compiler error: no Objective-C name for base type "
- + t_base_type::t_base_name(tbase);
- }
- } else if (type->is_enum()) {
- out << "readI32:&" << fieldName << " error: __thriftError]";
- }
- out << ") return NO;" << endl;
- } else {
- printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n",
- tfield->get_name().c_str(),
- type_name(type).c_str());
- }
-}
-
-/**
- * Generates an unserializer for a struct, allocates the struct and invokes read:
- */
-void t_cocoa_generator::generate_deserialize_struct(ostream& out,
- t_struct* tstruct,
- string fieldName) {
- indent(out) << type_name(tstruct) << fieldName << " = [[" << type_name(tstruct, true)
- << " alloc] init];" << endl;
- indent(out) << "if (![" << fieldName << " read: inProtocol error: __thriftError]) return NO;" << endl;
-}
-
-/**
- * Deserializes a container by reading its size and then iterating
- */
-void t_cocoa_generator::generate_deserialize_container(ostream& out,
- t_type* ttype,
- string fieldName) {
- string size = tmp("_size");
- indent(out) << "SInt32 " << size << ";" << endl;
-
- // Declare variables, read header
- if (ttype->is_map()) {
- indent(out) << "if (![inProtocol readMapBeginReturningKeyType: NULL valueType: NULL size: &" << size << " error: __thriftError]) return NO;" << endl;
- indent(out) << "NSMutableDictionary * " << fieldName
- << " = [[NSMutableDictionary alloc] initWithCapacity: " << size << "];" << endl;
- } else if (ttype->is_set()) {
- indent(out) << "if (![inProtocol readSetBeginReturningElementType: NULL size: &" << size << " error: __thriftError]) return NO;"
- << endl;
- indent(out) << "NSMutableSet * " << fieldName
- << " = [[NSMutableSet alloc] initWithCapacity: " << size << "];" << endl;
- } else if (ttype->is_list()) {
- indent(out) << "if (![inProtocol readListBeginReturningElementType: NULL size: &" << size << " error: __thriftError]) return NO;"
- << endl;
- indent(out) << "NSMutableArray * " << fieldName
- << " = [[NSMutableArray alloc] initWithCapacity: " << size << "];" << endl;
- }
- // FIXME - the code above does not verify that the element types of
- // the containers being read match the element types of the
- // containers we are reading into. Does that matter?
-
- // For loop iterates over elements
- string i = tmp("_i");
- indent(out) << "int " << i << ";" << endl << indent() << "for (" << i << " = 0; " << i << " < "
- << size << "; "
- << "++" << i << ")" << endl;
-
- scope_up(out);
-
- if (ttype->is_map()) {
- generate_deserialize_map_element(out, (t_map*)ttype, fieldName);
- } else if (ttype->is_set()) {
- generate_deserialize_set_element(out, (t_set*)ttype, fieldName);
- } else if (ttype->is_list()) {
- generate_deserialize_list_element(out, (t_list*)ttype, fieldName);
- }
-
- scope_down(out);
-
- // Read container end
- if (ttype->is_map()) {
- indent(out) << "if (![inProtocol readMapEnd: __thriftError]) return NO;" << endl;
- } else if (ttype->is_set()) {
- indent(out) << "if (![inProtocol readSetEnd: __thriftError]) return NO;" << endl;
- } else if (ttype->is_list()) {
- indent(out) << "if (![inProtocol readListEnd: __thriftError]) return NO;" << endl;
- }
-}
-
-/**
- * Take a variable of a given type and wrap it in code to make it
- * suitable for putting into a container, if necessary. Basically,
- * wrap scaler primitives in NSNumber objects.
- */
-string t_cocoa_generator::box(t_type* ttype, string field_name) {
-
- ttype = get_true_type(ttype);
- if (ttype->is_enum()) {
- return "@(" + field_name + ")";
- } else if (ttype->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)ttype)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "can't box void";
- case t_base_type::TYPE_BOOL:
- case t_base_type::TYPE_I8:
- case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
- case t_base_type::TYPE_I64:
- case t_base_type::TYPE_DOUBLE:
- return "@(" + field_name + ")";
- default:
- break;
- }
- }
-
- // do nothing
- return field_name;
-}
-
-/**
- * Extracts the actual value from a boxed value
- */
-string t_cocoa_generator::unbox(t_type* ttype, string field_name) {
- ttype = get_true_type(ttype);
- if (ttype->is_enum()) {
- return "[" + field_name + " intValue]";
- } else if (ttype->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)ttype)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "can't unbox void";
- case t_base_type::TYPE_BOOL:
- return "[" + field_name + " boolValue]";
- case t_base_type::TYPE_I8:
- return "((SInt8)[" + field_name + " charValue])";
- case t_base_type::TYPE_I16:
- return "((SInt16)[" + field_name + " shortValue])";
- case t_base_type::TYPE_I32:
- return "((SInt32)[" + field_name + " longValue])";
- case t_base_type::TYPE_I64:
- return "((SInt64)[" + field_name + " longLongValue])";
- case t_base_type::TYPE_DOUBLE:
- return "[" + field_name + " doubleValue]";
- default:
- break;
- }
- }
-
- // do nothing
- return field_name;
-}
-
-/**
- * Generates code to deserialize a map element
- */
-void t_cocoa_generator::generate_deserialize_map_element(ostream& out,
- t_map* tmap,
- string fieldName) {
- string key = tmp("_key");
- string val = tmp("_val");
- t_type* keyType = tmap->get_key_type();
- t_type* valType = tmap->get_val_type();
- t_field fkey(keyType, key);
- t_field fval(valType, val);
-
- generate_deserialize_field(out, &fkey, key);
- generate_deserialize_field(out, &fval, val);
-
- indent(out) << "[" << fieldName << " setObject: " << box(valType, val)
- << " forKey: " << box(keyType, key) << "];" << endl;
-}
-
-/**
- * Deserializes a set element
- */
-void t_cocoa_generator::generate_deserialize_set_element(ostream& out,
- t_set* tset,
- string fieldName) {
- string elem = tmp("_elem");
- t_type* type = tset->get_elem_type();
- t_field felem(type, elem);
-
- generate_deserialize_field(out, &felem, elem);
-
- indent(out) << "[" << fieldName << " addObject: " << box(type, elem) << "];" << endl;
-}
-
-/**
- * Deserializes a list element
- */
-void t_cocoa_generator::generate_deserialize_list_element(ostream& out,
- t_list* tlist,
- string fieldName) {
- string elem = tmp("_elem");
- t_type* type = tlist->get_elem_type();
- t_field felem(type, elem);
-
- generate_deserialize_field(out, &felem, elem);
-
- indent(out) << "[" << fieldName << " addObject: " << box(type, elem) << "];" << endl;
-}
-
-/**
- * Serializes a field of any type.
- *
- * @param tfield The field to serialize
- * @param fieldName Name to of the variable holding the field
- */
-void t_cocoa_generator::generate_serialize_field(ostream& out, t_field* tfield, string fieldName) {
- t_type* type = get_true_type(tfield->get_type());
-
- // Do nothing for void types
- if (type->is_void()) {
- throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " + tfield->get_name();
- }
-
- if (type->is_struct() || type->is_xception()) {
- generate_serialize_struct(out, (t_struct*)type, fieldName);
- } else if (type->is_container()) {
- generate_serialize_container(out, type, fieldName);
- } else if (type->is_base_type() || type->is_enum()) {
- indent(out) << "if (![outProtocol ";
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "compiler error: cannot serialize void field in a struct: " + fieldName;
- break;
- case t_base_type::TYPE_STRING:
- if (type->is_binary()) {
- out << "writeBinary: " << fieldName << " error: __thriftError]";
- } else {
- out << "writeString: " << fieldName << " error: __thriftError]";
- }
- break;
- case t_base_type::TYPE_BOOL:
- out << "writeBool: " << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I8:
- out << "writeByte: (UInt8)" << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I16:
- out << "writeI16: " << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I32:
- out << "writeI32: " << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_I64:
- out << "writeI64: " << fieldName << " error: __thriftError]";
- break;
- case t_base_type::TYPE_DOUBLE:
- out << "writeDouble: " << fieldName << " error: __thriftError]";
- break;
- default:
- throw "compiler error: no Objective-C name for base type "
- + t_base_type::t_base_name(tbase);
- }
- } else if (type->is_enum()) {
- out << "writeI32: " << fieldName << " error: __thriftError]";
- }
- out << ") return NO;" << endl;
- } else {
- printf("DO NOT KNOW HOW TO SERIALIZE FIELD '%s' TYPE '%s'\n",
- tfield->get_name().c_str(),
- type_name(type).c_str());
- }
-}
-
-/**
- * Serialize a struct.
- *
- * @param tstruct The struct to serialize
- * @param fieldName Name of variable holding struct
- */
-void t_cocoa_generator::generate_serialize_struct(ostream& out,
- t_struct* tstruct,
- string fieldName) {
- (void)tstruct;
- out << indent() << "if (![" << fieldName << " write: outProtocol error: __thriftError]) return NO;" << endl;
-}
-
-/**
- * Serializes a container by writing its size then the elements.
- *
- * @param ttype The type of container
- * @param fieldName Name of variable holding container
- */
-void t_cocoa_generator::generate_serialize_container(ostream& out,
- t_type* ttype,
- string fieldName) {
- scope_up(out);
-
- if (ttype->is_map()) {
- indent(out) << "if (![outProtocol writeMapBeginWithKeyType: "
- << type_to_enum(((t_map*)ttype)->get_key_type())
- << " valueType: " << type_to_enum(((t_map*)ttype)->get_val_type()) << " size: (SInt32)["
- << fieldName << " count] error: __thriftError]) return NO;" << endl;
- } else if (ttype->is_set()) {
- indent(out) << "if (![outProtocol writeSetBeginWithElementType: "
- << type_to_enum(((t_set*)ttype)->get_elem_type()) << " size: (SInt32)[" << fieldName
- << " count] error: __thriftError]) return NO;" << endl;
- } else if (ttype->is_list()) {
- indent(out) << "if (![outProtocol writeListBeginWithElementType: "
- << type_to_enum(((t_list*)ttype)->get_elem_type()) << " size: (SInt32)[" << fieldName
- << " count] error: __thriftError]) return NO;" << endl;
- }
-
- string iter = tmp("_iter");
- string key;
- if (ttype->is_map()) {
- key = tmp("key");
- indent(out) << "NSEnumerator * " << iter << " = [" << fieldName << " keyEnumerator];" << endl;
- indent(out) << "id " << key << ";" << endl;
- indent(out) << "while ((" << key << " = [" << iter << " nextObject]))" << endl;
- } else if (ttype->is_set()) {
- key = tmp("obj");
- indent(out) << "NSEnumerator * " << iter << " = [" << fieldName << " objectEnumerator];"
- << endl;
- indent(out) << "id " << key << ";" << endl;
- indent(out) << "while ((" << key << " = [" << iter << " nextObject]))" << endl;
- } else if (ttype->is_list()) {
- key = tmp("idx");
- indent(out) << "int " << key << ";" << endl;
- indent(out) << "for (" << key << " = 0; " << key << " < [" << fieldName << " count]; " << key
- << "++)" << endl;
- }
-
- scope_up(out);
-
- if (ttype->is_map()) {
- generate_serialize_map_element(out, (t_map*)ttype, key, fieldName);
- } else if (ttype->is_set()) {
- generate_serialize_set_element(out, (t_set*)ttype, key);
- } else if (ttype->is_list()) {
- generate_serialize_list_element(out, (t_list*)ttype, key, fieldName);
- }
-
- scope_down(out);
-
- if (ttype->is_map()) {
- indent(out) << "if (![outProtocol writeMapEnd: __thriftError]) return NO;" << endl;
- } else if (ttype->is_set()) {
- indent(out) << "if (![outProtocol writeSetEnd: __thriftError]) return NO;" << endl;
- } else if (ttype->is_list()) {
- indent(out) << "if (![outProtocol writeListEnd: __thriftError]) return NO;" << endl;
- }
-
- scope_down(out);
-}
-
-/**
- * Serializes the members of a map.
- */
-void t_cocoa_generator::generate_serialize_map_element(ostream& out,
- t_map* tmap,
- string key,
- string mapName) {
- t_field kfield(tmap->get_key_type(), key);
- generate_serialize_field(out, &kfield, unbox(kfield.get_type(), key));
- t_field vfield(tmap->get_val_type(), "[" + mapName + " objectForKey: " + key + "]");
- generate_serialize_field(out, &vfield, unbox(vfield.get_type(), vfield.get_name()));
-}
-
-/**
- * Serializes the members of a set.
- */
-void t_cocoa_generator::generate_serialize_set_element(ostream& out,
- t_set* tset,
- string elementName) {
- t_field efield(tset->get_elem_type(), elementName);
- generate_serialize_field(out, &efield, unbox(efield.get_type(), elementName));
-}
-
-/**
- * Serializes the members of a list.
- */
-void t_cocoa_generator::generate_serialize_list_element(ostream& out,
- t_list* tlist,
- string index,
- string listName) {
- t_field efield(tlist->get_elem_type(), "[" + listName + " objectAtIndex: " + index + "]");
- generate_serialize_field(out, &efield, unbox(efield.get_type(), efield.get_name()));
-}
-
-/**
- * Returns an Objective-C name
- *
- * @param ttype The type
- * @param class_ref Do we want a Class reference istead of a type reference?
- * @return Objective-C type name, i.e. NSDictionary<Key,Value> *
- */
-string t_cocoa_generator::type_name(t_type* ttype, bool class_ref, bool needs_mutable) {
- if (ttype->is_typedef()) {
- string name = (needs_mutable && ttype->get_true_type()->is_container()) ? "Mutable" + ttype->get_name() : ttype->get_name();
- t_program* program = ttype->get_program();
- return program ? (program->get_namespace("cocoa") + name) : name;
- }
-
- string result;
- if (ttype->is_base_type()) {
- return base_type_name((t_base_type*)ttype);
- } else if (ttype->is_enum()) {
- return cocoa_prefix_ + ttype->get_name();
- } else if (ttype->is_map()) {
- t_map *map = (t_map *)ttype;
- result = needs_mutable ? "NSMutableDictionary" : "NSDictionary";
- result += "<" + element_type_name(map->get_key_type()) + ", " + element_type_name(map->get_val_type()) + ">";
- } else if (ttype->is_set()) {
- t_set *set = (t_set *)ttype;
- result = needs_mutable ? "NSMutableSet" : "NSSet";
- result += "<" + element_type_name(set->get_elem_type()) + ">";
- } else if (ttype->is_list()) {
- t_list *list = (t_list *)ttype;
- result = needs_mutable ? "NSMutableArray" : "NSArray";
- result += "<" + element_type_name(list->get_elem_type()) + ">";
- } else {
- // Check for prefix
- t_program* program = ttype->get_program();
- if (program != NULL) {
- result = program->get_namespace("cocoa") + ttype->get_name();
- } else {
- result = ttype->get_name();
- }
- }
-
- if (!class_ref) {
- result += " *";
- }
- return result;
-}
-
-/**
- * Returns an Objective-C type name for container types
- *
- * @param ttype the type
- */
-string t_cocoa_generator::element_type_name(t_type* etype) {
-
- t_type* ttype = etype->get_true_type();
-
- if (etype->is_typedef() && type_can_be_null(ttype)) {
- return type_name(etype);
- }
-
- string result;
- if (ttype->is_base_type()) {
- t_base_type* tbase = (t_base_type*)ttype;
- switch (tbase->get_base()) {
- case t_base_type::TYPE_STRING:
- if (tbase->is_binary()) {
- result = "NSData *";
- }
- else {
- result = "NSString *";
- }
- break;
- default:
- result = "NSNumber *";
- break;
- }
- } else if (ttype->is_enum()) {
- result = "NSNumber *";
- } else if (ttype->is_map()) {
- t_map *map = (t_map *)ttype;
- result = "NSDictionary<" + element_type_name(map->get_key_type()) + ", " + element_type_name(map->get_val_type()) + "> *";
- } else if (ttype->is_set()) {
- t_set *set = (t_set *)ttype;
- result = "NSSet<" + element_type_name(set->get_elem_type()) + "> *";
- } else if (ttype->is_list()) {
- t_list *list = (t_list *)ttype;
- result = "NSArray<" + element_type_name(list->get_elem_type()) + "> *";
- } else if (ttype->is_struct() || ttype->is_xception()) {
- result = cocoa_prefix_ + ttype->get_name() + " *";
- }
-
- return result;
-}
-
-/**
- * Returns the Objective-C type that corresponds to the thrift type.
- *
- * @param tbase The base type
- */
-string t_cocoa_generator::base_type_name(t_base_type* type) {
- t_base_type::t_base tbase = type->get_base();
-
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- return "void";
- case t_base_type::TYPE_STRING:
- if (type->is_binary()) {
- return "NSData *";
- } else {
- return "NSString *";
- }
- case t_base_type::TYPE_BOOL:
- return "BOOL";
- case t_base_type::TYPE_I8:
- return "SInt8";
- case t_base_type::TYPE_I16:
- return "SInt16";
- case t_base_type::TYPE_I32:
- return "SInt32";
- case t_base_type::TYPE_I64:
- return "SInt64";
- case t_base_type::TYPE_DOUBLE:
- return "double";
- default:
- throw "compiler error: no Objective-C name for base type " + t_base_type::t_base_name(tbase);
- }
-}
-
-/**
- * Prints the value of a constant with the given type. Note that type checking
- * is NOT performed in this function as it is always run beforehand using the
- * validate_types method in main.cc
- */
-void t_cocoa_generator::print_const_value(ostream& out,
- string name,
- t_type* type,
- t_const_value* value,
- bool defval) {
- type = get_true_type(type);
-
- if (type->is_base_type()) {
- string v2 = render_const_value(out, type, value);
- indent(out);
- if (defval)
- out << type_name(type) << " ";
- out << name << " = " << v2 << ";" << endl << endl;
- } else if (type->is_enum()) {
- indent(out);
- if (defval)
- out << type_name(type) << " ";
- out << name << " = " << render_const_value(out, type, value) << ";" << endl << endl;
- } else if (type->is_struct() || type->is_xception()) {
- indent(out);
- const vector<t_field*>& fields = ((t_struct*)type)->get_members();
- vector<t_field*>::const_iterator f_iter;
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- if (defval)
- out << type_name(type) << " ";
- out << name << " = [" << type_name(type, true) << " new];"
- << endl;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- t_type* field_type = NULL;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if ((*f_iter)->get_name() == v_iter->first->get_string()) {
- field_type = (*f_iter)->get_type();
- }
- }
- if (field_type == NULL) {
- throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
- }
- string val = render_const_value(out, field_type, v_iter->second);
- std::string cap_name = capitalize(v_iter->first->get_string());
- indent(out) << "[" << name << " set" << cap_name << ":" << val << "];" << endl;
- }
- } else if (type->is_map()) {
- ostringstream mapout;
- indent(mapout);
- t_type* ktype = ((t_map*)type)->get_key_type();
- t_type* vtype = ((t_map*)type)->get_val_type();
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- if (defval)
- mapout << type_name(type) << " ";
- mapout << name << " = @{";
- for (v_iter = val.begin(); v_iter != val.end();) {
- mapout << render_const_value(out, ktype, v_iter->first, true) << ": "
- << render_const_value(out, vtype, v_iter->second, true);
- if (++v_iter != val.end()) {
- mapout << ", ";
- }
- }
- mapout << "}";
- out << mapout.str();
- } else if (type->is_list()) {
- ostringstream listout;
- indent(listout);
- t_type* etype = ((t_list*)type)->get_elem_type();
- const vector<t_const_value*>& val = value->get_list();
- vector<t_const_value*>::const_iterator v_iter;
- if (defval)
- listout << type_name(type) << " ";
- listout << name << " = @[";
- for (v_iter = val.begin(); v_iter != val.end();) {
- listout << render_const_value(out, etype, *v_iter, true);
- if (++v_iter != val.end()) {
- listout << ", ";
- }
- }
- listout << "]";
- out << listout.str();
- } else if (type->is_set()) {
- ostringstream setout;
- indent(setout);
- t_type* etype = ((t_set*)type)->get_elem_type();
- const vector<t_const_value*>& val = value->get_list();
- vector<t_const_value*>::const_iterator v_iter;
- if (defval)
- setout << type_name(type) << " ";
- setout << name << " = [NSSet setWithArray:@[";
- for (v_iter = val.begin(); v_iter != val.end();) {
- setout << render_const_value(out, etype, *v_iter, true);
- if (++v_iter != val.end()) {
- setout << ", ";
- }
- }
- setout << "]]";
- out << setout.str();
- } else {
- throw "compiler error: no const of type " + type->get_name();
- }
-}
-
-string t_cocoa_generator::render_const_value(ostream& out,
- t_type* type,
- t_const_value* value,
- bool box_it) {
- type = get_true_type(type);
- std::ostringstream render;
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_STRING:
- // We must handle binary constant but the syntax of IDL defines
- // nothing about binary constant.
- // if type->is_binary())
- // // binary code
- render << "@\"" << get_escaped_string(value) << '"';
- break;
- case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "YES" : "NO");
- break;
- case t_base_type::TYPE_I8:
- case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
- case t_base_type::TYPE_I64:
- render << value->get_integer();
- break;
- case t_base_type::TYPE_DOUBLE:
- if (value->get_type() == t_const_value::CV_INTEGER) {
- render << value->get_integer();
- } else {
- render << value->get_double();
- }
- break;
- default:
- throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
- }
- } else if (type->is_enum()) {
- render << value->get_integer();
- } else {
- string t = tmp("tmp");
- print_const_value(out, t, type, value, true);
- out << ";" << endl;
- render << t;
- }
-
- if (box_it) {
- return box(type, render.str());
- }
- return render.str();
-}
-
-#if 0
-/**
-ORIGINAL
- * Spit out code that evaluates to the specified constant value.
- */
-string t_cocoa_generator::render_const_value(string name,
- t_type* type,
- t_const_value* value,
- bool box_it) {
- type = get_true_type(type);
- std::ostringstream render;
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_STRING:
- render << "@\"" << get_escaped_string(value) << '"';
- break;
- case t_base_type::TYPE_BOOL:
- render << ((value->get_integer() > 0) ? "YES" : "NO");
- break;
- case t_base_type::TYPE_I8:
- case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
- case t_base_type::TYPE_I64:
- render << value->get_integer();
- break;
- case t_base_type::TYPE_DOUBLE:
- if (value->get_type() == t_const_value::CV_INTEGER) {
- render << value->get_integer();
- } else {
- render << value->get_double();
- }
- break;
- default:
- throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
- }
- } else if (type->is_enum()) {
- render << value->get_integer();
- } else if (type->is_struct() || type->is_xception()) {
- const vector<t_field*>& fields = ((t_struct*)type)->get_members();
- vector<t_field*>::const_iterator f_iter;
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- if (val.size() > 0)
- render << "[[" << type_name(type, true) << " alloc] initWith";
- else
- render << "[[" << type_name(type, true) << " alloc] init";
- bool first = true;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- // FIXME The generated code does not match with initWithXXX
- // initializer and causes compile error.
- // Try: test/DebugProtoTest.thrift and test/SmallTest.thrift
- t_type* field_type = NULL;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- if ((*f_iter)->get_name() == v_iter->first->get_string()) {
- field_type = (*f_iter)->get_type();
- }
- }
- if (field_type == NULL) {
- throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
- }
- if (first) {
- render << capitalize(v_iter->first->get_string());
- first = false;
- } else {
- render << " " << v_iter->first->get_string();
- }
- render << ": " << render_const_value(name, field_type, v_iter->second);
- }
- render << "]";
- } else if (type->is_map()) {
- render << "[[NSDictionary alloc] initWithObjectsAndKeys: ";
- t_type* ktype = ((t_map*)type)->get_key_type();
- t_type* vtype = ((t_map*)type)->get_val_type();
- const map<t_const_value*, t_const_value*, t_const_value::value_compare>& val = value->get_map();
- map<t_const_value*, t_const_value*, t_const_value::value_compare>::const_iterator v_iter;
- bool first = true;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- string key = render_const_value(name, ktype, v_iter->first, true);
- string val = render_const_value(name, vtype, v_iter->second, true);
- if (first) {
- first = false;
- } else {
- render << ", ";
- }
- render << val << ", " << key;
- }
- if (first)
- render << " nil]";
- else
- render << ", nil]";
- } else if (type->is_list()) {
- render << "[[NSArray alloc] initWithObjects: ";
- t_type * etype = ((t_list*)type)->get_elem_type();
- const vector<t_const_value*>& val = value->get_list();
- bool first = true;
- vector<t_const_value*>::const_iterator v_iter;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- if (first) {
- first = false;
- } else {
- render << ", ";
- }
- render << render_const_value(name, etype, *v_iter, true);
- }
- if (first)
- render << " nil]";
- else
- render << ", nil]";
- } else if (type->is_set()) {
- render << "[[NSSet alloc] initWithObjects: ";
- t_type * etype = ((t_set*)type)->get_elem_type();
- const vector<t_const_value*>& val = value->get_list();
- bool first = true;
- vector<t_const_value*>::const_iterator v_iter;
- for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
- if (first) {
- first = false;
- } else {
- render << ", ";
- }
- render << render_const_value(name, etype, *v_iter, true);
- }
- if (first)
- render << " nil]";
- else
- render << ", nil]";
- } else {
- throw "don't know how to render constant for type: " + type->get_name();
- }
-
- if (box_it) {
- return box(type, render.str());
- }
-
- return render.str();
-}
-#endif
-
-/**
- * Declares an Objective-C 2.0 property.
- *
- * @param tfield The field to declare a property for
- */
-string t_cocoa_generator::declare_property(t_field* tfield) {
- std::ostringstream render;
- render << "@property (";
-
- if (type_can_be_copy(tfield->get_type())) {
- render << "copy, ";
- } else if (type_can_be_null(tfield->get_type())) {
- render << "strong, ";
- } else {
- render << "assign, ";
- }
-
- render << "nonatomic) " << type_name(tfield->get_type(), false, true) << " "
- << tfield->get_name() << ";";
-
- // Check if the property name is an Objective-C return +1 count signal
- if ((tfield->get_name().length() >= 3 && tfield->get_name().substr(0,3) == "new") ||
- (tfield->get_name().length() >= 6 && tfield->get_name().substr(0,6) == "create") ||
- (tfield->get_name().length() >= 5 && tfield->get_name().substr(0,5) == "alloc")) {
- // Let Objective-C know not to return +1 for object pointers
- if (type_can_be_null(tfield->get_type())) {
- render << endl;
- render << "- (" + type_name(tfield->get_type()) + ") " + decapitalize(tfield->get_name()) + " __attribute__((objc_method_family(none)));";
- }
- }
-
- return render.str();
-}
-
-/**
- * Declares an Objective-C 2.0 property.
- *
- * @param tfield The field to declare a property for
- */
-string t_cocoa_generator::declare_property_isset(t_field* tfield) {
- return "@property (assign, nonatomic) BOOL " + decapitalize(tfield->get_name()) + "IsSet;";
-}
-
-/**
- * Declares property unset method.
- *
- * @param tfield The field to declare a property for
- */
-string t_cocoa_generator::declare_property_unset(t_field* tfield) {
- return "- (void) unset" + capitalize(tfield->get_name()) + ";";
-}
-
-/**
- * Renders the early out return statement
- *
- * @param tfunction Function definition
- * @return String of rendered invalid return statment
- */
-string t_cocoa_generator::invalid_return_statement(t_function *tfunction) {
- if ((tfunction->get_returntype()->is_void())) {
- return "return NO;";
- }
- return "return nil;";
-}
-
-/**
- * Renders a function signature
- *
- * @param tfunction Function definition
- * @return String of rendered function definition
- */
-string t_cocoa_generator::function_signature(t_function* tfunction, bool include_error) {
- t_type* ttype = tfunction->get_returntype();
- string result;
- if (ttype->is_void()) {
- result = "(BOOL)";
- }
- else if (type_can_be_null(ttype)) {
- result = "(" + type_name(ttype) + ")";
- }
- else {
- result = "(NSNumber *)";
- }
- result += " " + tfunction->get_name() + argument_list(tfunction->get_arglist(), "", include_error);
- return result;
-}
-
-/**
- * Renders a function signature that returns asynchronously instead of
- * literally returning.
- *
- * @param tfunction Function definition
- * @return String of rendered function definition
- */
-string t_cocoa_generator::async_function_signature(t_function* tfunction, bool include_error) {
- t_type* ttype = tfunction->get_returntype();
- t_struct* targlist = tfunction->get_arglist();
- string response_param = "void (^)(" + ((ttype->is_void()) ? "" : type_name(ttype)) + ")";
- std::string result = "(void) " + tfunction->get_name() + argument_list(tfunction->get_arglist(), "", include_error)
- + (targlist->get_members().size() ? " response" : "") + ": ("
- + response_param + ") responseBlock "
- + "failure : (TAsyncFailureBlock) failureBlock";
- return result;
-}
-
-/**
- * Renders a function signature that returns a promise instead of
- * literally returning.
- *
- * @param tfunction Function definition
- * @return String of rendered function definition
- */
-string t_cocoa_generator::promise_function_signature(t_function* tfunction) {
- return "(AnyPromise *) " + tfunction->get_name() + argument_list(tfunction->get_arglist(), "", false);
-}
-
-/**
- * Renders a colon separated list of types and names, suitable for an
- * objective-c parameter list
- */
-string t_cocoa_generator::argument_list(t_struct* tstruct, string protocol_name, bool include_error) {
- string result = "";
- bool include_protocol = !protocol_name.empty();
-
- const vector<t_field*>& fields = tstruct->get_members();
- vector<t_field*>::const_iterator f_iter;
- bool first = true;
- for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
- string argPrefix = "";
- if (first) {
- first = false;
- } else {
- argPrefix = (*f_iter)->get_name();
- result += " ";
- }
- result += argPrefix + ": (" + type_name((*f_iter)->get_type()) + ") " + (*f_iter)->get_name();
- }
- if (include_protocol) {
- if (!first) {
- result += " protocol";
- }
- result += ": (id<TProtocol>) " + protocol_name;
- first = false;
- }
- if (include_error) {
- if (!first) {
- result += " error";
- }
- result += ": (NSError *__autoreleasing *)__thriftError";
- first = false;
- }
- return result;
-}
-
-/**
- * Converts the parse type to an Objective-C enum string for the given type.
- */
-string t_cocoa_generator::type_to_enum(t_type* type) {
- type = get_true_type(type);
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "NO T_VOID CONSTRUCT";
- case t_base_type::TYPE_STRING:
- return "TTypeSTRING";
- case t_base_type::TYPE_BOOL:
- return "TTypeBOOL";
- case t_base_type::TYPE_I8:
- return "TTypeBYTE";
- case t_base_type::TYPE_I16:
- return "TTypeI16";
- case t_base_type::TYPE_I32:
- return "TTypeI32";
- case t_base_type::TYPE_I64:
- return "TTypeI64";
- case t_base_type::TYPE_DOUBLE:
- return "TTypeDOUBLE";
- }
- } else if (type->is_enum()) {
- return "TTypeI32";
- } else if (type->is_struct() || type->is_xception()) {
- return "TTypeSTRUCT";
- } else if (type->is_map()) {
- return "TTypeMAP";
- } else if (type->is_set()) {
- return "TTypeSET";
- } else if (type->is_list()) {
- return "TTypeLIST";
- }
-
- throw "INVALID TYPE IN type_to_enum: " + type->get_name();
-}
-
-/**
- * Returns a format string specifier for the supplied parse type.
- */
-string t_cocoa_generator::format_string_for_type(t_type* type) {
- type = get_true_type(type);
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "NO T_VOID CONSTRUCT";
- case t_base_type::TYPE_STRING:
- return "\\\"%@\\\"";
- case t_base_type::TYPE_BOOL:
- return "%i";
- case t_base_type::TYPE_I8:
- return "%i";
- case t_base_type::TYPE_I16:
- return "%hi";
- case t_base_type::TYPE_I32:
- return "%i";
- case t_base_type::TYPE_I64:
- return "%qi";
- case t_base_type::TYPE_DOUBLE:
- return "%f";
- }
- } else if (type->is_enum()) {
- return "%i";
- } else if (type->is_struct() || type->is_xception()) {
- return "%@";
- } else if (type->is_map()) {
- return "%@";
- } else if (type->is_set()) {
- return "%@";
- } else if (type->is_list()) {
- return "%@";
- }
-
- throw "INVALID TYPE IN format_string_for_type: " + type->get_name();
-}
-
-/**
- * Returns a format cast for the supplied parse type.
- */
-string t_cocoa_generator::format_cast_for_type(t_type* type) {
- type = get_true_type(type);
-
- if (type->is_base_type()) {
- t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
- switch (tbase) {
- case t_base_type::TYPE_VOID:
- throw "NO T_VOID CONSTRUCT";
- case t_base_type::TYPE_STRING:
- return ""; // "\\\"%@\\\"";
- case t_base_type::TYPE_BOOL:
- return ""; // "%i";
- case t_base_type::TYPE_I8:
- return ""; // "%i";
- case t_base_type::TYPE_I16:
- return ""; // "%hi";
- case t_base_type::TYPE_I32:
- return "(int)"; // "%i";
- case t_base_type::TYPE_I64:
- return ""; // "%qi";
- case t_base_type::TYPE_DOUBLE:
- return ""; // "%f";
- }
- } else if (type->is_enum()) {
- return "(int)"; // "%i";
- } else if (type->is_struct() || type->is_xception()) {
- return ""; // "%@";
- } else if (type->is_map()) {
- return ""; // "%@";
- } else if (type->is_set()) {
- return ""; // "%@";
- } else if (type->is_list()) {
- return ""; // "%@";
- }
-
- throw "INVALID TYPE IN format_cast_for_type: " + type->get_name();
-}
-
-/**
- * Generate a call to a field's setter.
- *
- * @param tfield Field the setter is being called on
- * @param fieldName Name of variable to pass to setter
- */
-
-string t_cocoa_generator::call_field_setter(t_field* tfield, string fieldName) {
- return "self." + tfield->get_name() + " = " + fieldName + ";";
-}
-
-THRIFT_REGISTER_GENERATOR(
- cocoa,
- "Cocoa",
- " log_unexpected: Log every time an unexpected field ID or type is encountered.\n"
- " debug_descriptions:\n"
- " Allow use of debugDescription so the app can add description via a cateogory/extension\n"
- " validate_required:\n"
- " Throws exception if any required field is not set.\n"
- " async_clients: Generate clients which invoke asynchronously via block syntax.\n"
- " pods: Generate imports in Cocopods framework format.\n"
- " promise_kit: Generate clients which invoke asynchronously via promises.\n")
diff --git a/compiler/cpp/src/thrift/thriftl.ll b/compiler/cpp/src/thrift/thriftl.ll
index 4f783be96..282e0309c 100644
--- a/compiler/cpp/src/thrift/thriftl.ll
+++ b/compiler/cpp/src/thrift/thriftl.ll
@@ -207,15 +207,14 @@ literal_begin (['\"])
"cpp_include" { return tok_cpp_include; }
"cpp_type" { return tok_cpp_type; }
"java_package" { error_unsupported_namespace_decl("java_package", "java"); /* do nothing */ }
-"cocoa_prefix" { error_unsupported_namespace_decl("cocoa_prefix", "cocoa"); /* do nothing */ }
"csharp_namespace" { error_unsupported_namespace_decl("csharp"); /* do nothing */ }
"delphi_namespace" { error_unsupported_namespace_decl("delphi"); /* do nothing */ }
"php_namespace" { error_unsupported_namespace_decl("php"); /* do nothing */ }
"py_module" { error_unsupported_namespace_decl("py_module", "py"); /* do nothing */ }
"perl_package" { error_unsupported_namespace_decl("perl_package", "perl"); /* do nothing */ }
"ruby_namespace" { error_unsupported_namespace_decl("ruby"); /* do nothing */ }
-"smalltalk_category" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ }
-"smalltalk_prefix" { error_unsupported_namespace_decl("smalltalk_category", "smalltalk.category"); /* do nothing */ }
+"smalltalk_category" { error_unsupported_namespace_decl("smalltalk_category", "st"); /* do nothing */ }
+"smalltalk_prefix" { error_unsupported_namespace_decl("smalltalk_prefix", "st"); /* do nothing */ }
"xsd_all" { return tok_xsd_all; }
"xsd_optional" { return tok_xsd_optional; }
"xsd_nillable" { return tok_xsd_nillable; }
diff --git a/compiler/cpp/tests/CMakeLists.txt b/compiler/cpp/tests/CMakeLists.txt
index e2b100c7a..fde9073ca 100644
--- a/compiler/cpp/tests/CMakeLists.txt
+++ b/compiler/cpp/tests/CMakeLists.txt
@@ -96,36 +96,36 @@ macro(THRIFT_ADD_COMPILER name description initial)
endmacro()
# The following compiler with unit tests can be enabled or disabled
+THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" OFF)
THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" OFF)
+THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" OFF)
THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" OFF)
-THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF)
-THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" OFF)
-THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" OFF)
-THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" OFF)
THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" OFF)
-THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON)
-THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" OFF)
-THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" OFF)
-THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" OFF)
-THRIFT_ADD_COMPILER(php "Enable compiler for PHP" OFF)
+THRIFT_ADD_COMPILER(d "Enable compiler for D" OFF)
+THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" OFF)
+THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" OFF)
THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" OFF)
-THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" OFF)
-THRIFT_ADD_COMPILER(swift "Enable compiler for Cocoa Swift" OFF)
-THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" OFF)
-THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" OFF)
+THRIFT_ADD_COMPILER(go "Enable compiler for Go" OFF)
+THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" OFF)
+THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" OFF)
THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" OFF)
-THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" OFF)
THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" OFF)
+THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF)
+THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF)
THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" OFF)
THRIFT_ADD_COMPILER(json "Enable compiler for JSON" OFF)
-THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF)
-THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" OFF)
-THRIFT_ADD_COMPILER(go "Enable compiler for Go" OFF)
-THRIFT_ADD_COMPILER(d "Enable compiler for D" OFF)
THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" OFF)
-THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" OFF)
+THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON)
+THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" OFF)
+THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" OFF)
+THRIFT_ADD_COMPILER(php "Enable compiler for PHP" OFF)
+THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" OFF)
+THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" OFF)
THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" OFF)
+THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" OFF)
+THRIFT_ADD_COMPILER(swift "Enable compiler for Swift" OFF)
THRIFT_ADD_COMPILER(xml "Enable compiler for XML" OFF)
+THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" OFF)
# Thrift is looking for include files in the src directory
# we also add the current binary directory for generated files
@@ -150,4 +150,4 @@ set_target_properties(thrift_compiler_tests PROPERTIES OUTPUT_NAME thrift_compil
target_link_libraries(thrift_compiler_tests thrift_compiler)
enable_testing()
-add_test(NAME ThriftTests COMMAND thrift_compiler_tests) \ No newline at end of file
+add_test(NAME ThriftTests COMMAND thrift_compiler_tests)
diff --git a/contrib/thrift.spec b/contrib/thrift.spec
index cc3c33c8e..ffdfab2ab 100644
--- a/contrib/thrift.spec
+++ b/contrib/thrift.spec
@@ -58,8 +58,8 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Thrift is a software framework for scalable cross-language services
development. It combines a powerful software stack with a code generation
engine to build services that work efficiently and seamlessly between C++,
-Java, C#, Python, Ruby, Perl, PHP, Objective C/Cocoa, Smalltalk, Erlang,
-Objective Caml, and Haskell.
+Java, C#, Python, Ruby, Perl, PHP, Smalltalk, Erlang, OCaml, Haskell, and
+other languages.
%files
%defattr(-,root,root)
diff --git a/debian/copyright b/debian/copyright
index 850643c9a..3e6fcf721 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -28,7 +28,6 @@ the Thrift Software License (see doc/old-thrift-license.txt), and relicensed
under the Apache 2.0 License:
compiler/cpp/Makefile.am
- compiler/cpp/src/generate/t_cocoa_generator.cc
compiler/cpp/src/generate/t_cpp_generator.cc
compiler/cpp/src/generate/t_csharp_generator.cc
compiler/cpp/src/generate/t_erl_generator.cc
diff --git a/doap.rdf b/doap.rdf
index cb76facfa..50b3491d6 100755
--- a/doap.rdf
+++ b/doap.rdf
@@ -27,7 +27,7 @@
<name>Apache Thrift</name>
<homepage rdf:resource="http://thrift.apache.org" />
<asfext:pmc rdf:resource="http://thrift.apache.org" />
- <shortdesc>Apache Thrift software provides a framework for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages. </shortdesc>
+ <shortdesc>Apache Thrift software provides a framework for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages. </shortdesc>
<description>Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages. Instead of writing a load of boilerplate code to serialize and transport your objects and invoke remote methods, you can get right down to business. </description>
<bug-database rdf:resource="https://issues.apache.org/jira/browse/THRIFT" />
<mailing-list rdf:resource="http://thrift.apache.org/mailing/" />
@@ -36,7 +36,6 @@
<programming-language>C</programming-language>
<programming-language>C#</programming-language>
<programming-language>C++</programming-language>
- <programming-language>Cocoa</programming-language>
<programming-language>D</programming-language>
<programming-language>Dart</programming-language>
<programming-language>Delphi</programming-language>
diff --git a/doc/specs/idl.md b/doc/specs/idl.md
index bf22f5477..069f2fc37 100644
--- a/doc/specs/idl.md
+++ b/doc/specs/idl.md
@@ -1,10 +1,11 @@
## Thrift interface description language
+
+For Thrift version 1.0.0.
+
The Thrift interface definition language (IDL) allows for the definition of [Thrift Types](/docs/types). A Thrift IDL file is processed by the Thrift code generator to produce code for the various target languages to support the defined structs and services in the IDL file.
## Description
-*Under construction*
-
Here is a description of the Thrift IDL.
## Document
@@ -35,32 +36,9 @@ A C++ include adds a custom C++ include to the output of the C++ code generator
A namespace declares which namespaces/package/module/etc. the type definitions in this file will be declared in for the target languages. The namespace scope indicates which language the namespace applies to; a scope of '*' indicates that the namespace applies to all target languages.
- [5] Namespace ::= ( 'namespace' ( NamespaceScope Identifier ) |
- ( 'smalltalk.category' STIdentifier ) |
- ( 'smalltalk.prefix' Identifier ) ) |
- ( 'php_namespace' Literal ) |
- ( 'xsd_namespace' Literal )
-
- [6] NamespaceScope ::= '*' | 'cpp' | 'java' | 'py' | 'perl' | 'rb' | 'cocoa' | 'csharp'
-
-N.B.: Smalltalk has two distinct types of namespace commands:
-
-- smalltalk.prefix: Prepended to generated classnames.
- - Smalltalk does not have namespaces for classes, so prefixes
- are used to avoid class-name collisions.
- Often, the prefix is the author's initials, like "KB" or "JWS",
- or an abbreviation of the package name, like "MC" for "Monticello".
-- smalltalk.category: Determines the category for generated classes.
- Any dots in the identifier will be replaced with hyphens when generating
- the category name.
- If not provided, defaults to "Generated-" + the program name.
- Methods will not be categorized beyond "as yet uncategorized".
- - Smalltalk allows filing both classes and methods within classes into named
- groups. These named groups of methods are called categories.
-
-N.B.: The `php_namespace` directive will be deprecated at some point in the future in favor of the scoped syntax, but the scoped syntax is not yet supported for PHP.
+ [5] Namespace ::= ( 'namespace' ( NamespaceScope Identifier ) )
-N.B.: The `xsd_namespace` directive has some purpose internal to Facebook but serves no purpose in Thrift itself. Use of this feature is strongly discouraged
+ [6] NamespaceScope ::= '*' | 'c_glib' | 'cpp' | 'csharp' | 'delphi' | 'go' | 'java' | 'js' | 'lua' | 'netcore' | 'perl' | 'php' | 'py' | 'py.twisted' | 'rb' | 'st' | 'xsd'
## Definition
diff --git a/lib/Makefile.am b/lib/Makefile.am
index b6ce20e3c..0c6901940 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -110,7 +110,6 @@ endif
# so they will end up in our release tarballs.
EXTRA_DIST = \
as3 \
- cocoa \
d \
dart \
delphi \
diff --git a/lib/cocoa/README.md b/lib/cocoa/README.md
deleted file mode 100644
index bbe3c934f..000000000
--- a/lib/cocoa/README.md
+++ /dev/null
@@ -1,21 +0,0 @@
-Thrift Cocoa Software Library
-
-License
-=======
-
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you 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.
diff --git a/lib/cocoa/coding_standards.md b/lib/cocoa/coding_standards.md
deleted file mode 100644
index fa0390bb5..000000000
--- a/lib/cocoa/coding_standards.md
+++ /dev/null
@@ -1 +0,0 @@
-Please follow [General Coding Standards](/doc/coding_standards.md)
diff --git a/lib/cocoa/src/TApplicationError.h b/lib/cocoa/src/TApplicationError.h
deleted file mode 100644
index 079881a60..000000000
--- a/lib/cocoa/src/TApplicationError.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocol.h"
-
-extern NSString *TApplicationErrorDomain;
-
-typedef NS_ENUM (int, TApplicationError) {
- TApplicationErrorUnknown = 0,
- TApplicationErrorUnknownMethod = 1,
- TApplicationErrorInvalidMessageType = 2,
- TApplicationErrorWrongMethodName = 3,
- TApplicationErrorBadSequenceId = 4,
- TApplicationErrorMissingResult = 5,
- TApplicationErrorInternalError = 6,
- TApplicationErrorProtocolError = 7,
- TApplicationErrorInvalidTransform = 8,
- TApplicationErrorInvalidProtocol = 9,
- TApplicationErrorUnsupportedClientType = 10,
-};
-
-
-extern NSString *TApplicationErrorNameKey;
-extern NSString *TApplicationErrorReasonKey;
-extern NSString *TApplicationErrorMethodKey;
-
-
-@interface NSError (TApplicationError)
-
-@property (readonly, copy) NSString *name;
-@property (readonly, copy) NSString *reason;
-
-+(instancetype) errorWithType:(TApplicationError)type reason:(NSString *)reason;
-
-+(instancetype) read:(id<TProtocol>)protocol;
-
--(BOOL) write:(id<TProtocol>)outProtocol error:(NSError *__autoreleasing *)error;
-
-@end
diff --git a/lib/cocoa/src/TApplicationError.m b/lib/cocoa/src/TApplicationError.m
deleted file mode 100644
index 080bc0b7c..000000000
--- a/lib/cocoa/src/TApplicationError.m
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TApplicationError.h"
-#import "TProtocolUtil.h"
-
-
-NSString *TApplicationErrorDomain = @"TApplicationErrorDomain";
-
-
-NSString *TApplicationErrorNameKey = @"name";
-NSString *TApplicationErrorReasonKey = @"reason";
-NSString *TApplicationErrorMethodKey = @"method";
-
-
-@implementation NSError (TApplicationError)
-
--(NSString *) reason
-{
- return self.userInfo[TApplicationErrorReasonKey];
-}
-
--(NSString *) name
-{
- return self.userInfo[TApplicationErrorNameKey];
-}
-
-+(instancetype) errorWithType:(TApplicationError)type reason:(NSString *)reason
-{
- NSString *name;
- switch (type) {
- case TApplicationErrorUnknownMethod:
- name = @"Unknown Method";
- break;
-
- case TApplicationErrorInvalidMessageType:
- name = @"Invalid Message Type";
- break;
-
- case TApplicationErrorWrongMethodName:
- name = @"Wrong Method Name";
- break;
-
- case TApplicationErrorBadSequenceId:
- name = @"Bad Sequence ID";
- break;
-
- case TApplicationErrorMissingResult:
- name = @"Missing Result";
- break;
-
- case TApplicationErrorInternalError:
- name = @"Internal Error";
- break;
-
- case TApplicationErrorProtocolError:
- name = @"Protocol Error";
- break;
-
- case TApplicationErrorInvalidTransform:
- name = @"Invalid Transform";
- break;
-
- case TApplicationErrorInvalidProtocol:
- name = @"Invalid Protocol";
- break;
-
- case TApplicationErrorUnsupportedClientType:
- name = @"Unsupported Client Type";
- break;
-
- default:
- name = @"Unknown";
- break;
- }
-
- NSDictionary *userInfo;
- if (reason) {
- userInfo = @{TApplicationErrorNameKey:name,
- TApplicationErrorReasonKey:reason};
- }
- else {
- userInfo = @{TApplicationErrorNameKey:name};
- }
-
- return [NSError errorWithDomain:TApplicationErrorDomain
- code:type
- userInfo:userInfo];
-}
-
-
-+(instancetype) read:(id<TProtocol>)protocol
-{
- NSString *reason = nil;
- SInt32 type = TApplicationErrorUnknown;
- SInt32 fieldType;
- SInt32 fieldID;
-
- NSError *error;
- if (![protocol readStructBeginReturningName:NULL error:&error]) {
- return error;
- }
-
- while (true) {
-
- if (![protocol readFieldBeginReturningName:NULL
- type:&fieldType
- fieldID:&fieldID
- error:&error])
- {
- return error;
- }
-
- if (fieldType == TTypeSTOP) {
- break;
- }
-
- switch (fieldID) {
- case 1:
- if (fieldType == TTypeSTRING) {
- if (![protocol readString:&reason error:&error]) {
- return error;
- }
- }
- else {
- if (![TProtocolUtil skipType:fieldType onProtocol:protocol error:&error]) {
- return error;
- }
- }
- break;
-
- case 2:
- if (fieldType == TTypeI32) {
- if (![protocol readI32:&type error:&error]) {
- return error;
- }
- }
- else {
- if (![TProtocolUtil skipType:fieldType onProtocol:protocol error:&error]) {
- return error;
- }
- }
- break;
-
- default:
- if (![TProtocolUtil skipType:fieldType onProtocol:protocol error:&error]) {
- return error;
- }
- break;
- }
- if (![protocol readFieldEnd:&error]) {
- return error;
- }
-
- }
-
- if (![protocol readStructEnd:&error]) {
- return error;
- }
-
- return [NSError errorWithType:type reason:reason];
-}
-
-
--(BOOL) write:(id<TProtocol>)protocol error:(NSError *__autoreleasing *)error
-{
- if (![protocol writeStructBeginWithName:@"TApplicationException" error:error]) {
- return NO;
- }
-
- if (self.localizedDescription != nil) {
- if (![protocol writeFieldBeginWithName:@"message"
- type:TTypeSTRING
- fieldID:1 error:error])
- {
- return NO;
- }
-
- if (![protocol writeString:self.localizedDescription error:error]) {
- return NO;
- }
-
- if (![protocol writeFieldEnd:error]) {
- return NO;
- }
- }
-
- if (![protocol writeFieldBeginWithName:@"type"
- type:TTypeI32
- fieldID:2
- error:error])
- {
- return NO;
- }
-
- if (![protocol writeI32:(SInt32)self.code error:error]) {
- return NO;
- }
-
- if (![protocol writeFieldEnd:error]) {
- return NO;
- }
-
- if (![protocol writeFieldStop:error]) {
- return NO;
- }
-
- if (![protocol writeStructEnd:error]) {
- return NO;
- }
-
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/TBaseClient.h b/lib/cocoa/src/TBaseClient.h
deleted file mode 100644
index 0f73aa027..000000000
--- a/lib/cocoa/src/TBaseClient.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocol.h"
-#import "TApplicationError.h"
-
-@interface TBaseClient : NSObject
-
--(NSError *) checkIncomingMessageException:(id<TProtocol>)protocol;
-
-@end
diff --git a/lib/cocoa/src/TBaseClient.m b/lib/cocoa/src/TBaseClient.m
deleted file mode 100644
index 249cae066..000000000
--- a/lib/cocoa/src/TBaseClient.m
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TBaseClient.h"
-#import "TApplicationError.h"
-
-
-@interface TBaseClient ()
-@end
-
-
-@implementation TBaseClient
-
--(NSError *) checkIncomingMessageException:(id<TProtocol>)inProtocol
-{
- NSError *thriftError;
-
- SInt32 msgType = 0;
- if (![inProtocol readMessageBeginReturningName:nil type:&msgType sequenceID:NULL error:&thriftError]) {
- return thriftError;
- }
-
- if (msgType == TMessageTypeEXCEPTION) {
-
- thriftError = [NSError read:inProtocol];
-
- [inProtocol readMessageEnd:NULL];
-
- return thriftError;
- }
-
- return nil;
-}
-
-@end
diff --git a/lib/cocoa/src/TBinary.swift b/lib/cocoa/src/TBinary.swift
deleted file mode 100644
index c8a366075..000000000
--- a/lib/cocoa/src/TBinary.swift
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public struct TBinary : TSerializable {
-
- public static var thriftType : TType { return .STRING }
-
- private var storage : NSData
-
- public init() {
- self.storage = NSData()
- }
-
- public init(contentsOfFile file: String, options: NSDataReadingOptions = []) throws {
- self.storage = try NSData(contentsOfFile: file, options: options)
- }
-
- public init(contentsOfURL URL: NSURL, options: NSDataReadingOptions = []) throws {
- self.storage = try NSData(contentsOfURL: URL, options: options)
- }
-
- public init?(base64EncodedData base64Data: NSData, options: NSDataBase64DecodingOptions = []) {
- guard let storage = NSData(base64EncodedData: base64Data, options: options) else {
- return nil
- }
- self.storage = storage
- }
-
- public init(data: NSData) {
- self.storage = data
- }
-
- public var length : Int {
- return storage.length
- }
-
- public var hashValue : Int {
- return storage.hashValue
- }
-
- public var bytes : UnsafePointer<Void> {
- return storage.bytes
- }
-
- public func getBytes(buffer: UnsafeMutablePointer<Void>, length: Int) {
- storage.getBytes(buffer, length: length)
- }
-
- public func getBytes(buffer: UnsafeMutablePointer<Void>, range: Range<Int>) {
- storage.getBytes(buffer, range: NSRange(range))
- }
-
- public func subBinaryWithRange(range: Range<Int>) -> TBinary {
- return TBinary(data: storage.subdataWithRange(NSRange(range)))
- }
-
- public func writeToFile(path: String, options: NSDataWritingOptions = []) throws {
- try storage.writeToFile(path, options: options)
- }
-
- public func writeToURL(url: NSURL, options: NSDataWritingOptions = []) throws {
- try storage.writeToURL(url, options: options)
- }
-
- public func rangeOfData(dataToFind data: NSData, options: NSDataSearchOptions, range: Range<Int>) -> Range<Int>? {
- return storage.rangeOfData(data, options: options, range: NSRange(range)).toRange()
- }
-
- public func enumerateByteRangesUsingBlock(block: (UnsafePointer<Void>, Range<Int>, inout Bool) -> Void) {
- storage.enumerateByteRangesUsingBlock { bytes, range, stop in
- var stopTmp = Bool(stop.memory)
- block(bytes, range.toRange()!, &stopTmp)
- stop.memory = ObjCBool(stopTmp)
- }
- }
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> TBinary {
- var data : NSData?
- try proto.readBinary(&data)
- return TBinary(data: data!)
- }
-
- public static func writeValue(value: TBinary, toProtocol proto: TProtocol) throws {
- try proto.writeBinary(value.storage)
- }
-
-}
-
-extension TBinary : CustomStringConvertible, CustomDebugStringConvertible {
-
- public var description : String {
- return storage.description
- }
-
- public var debugDescription : String {
- return storage.debugDescription
- }
-
-}
-
-public func ==(lhs: TBinary, rhs: TBinary) -> Bool {
- return lhs.storage == rhs.storage
-}
diff --git a/lib/cocoa/src/TEnum.swift b/lib/cocoa/src/TEnum.swift
deleted file mode 100644
index 562a53ade..000000000
--- a/lib/cocoa/src/TEnum.swift
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public protocol TEnum : TSerializable {
-
-}
-
-public extension TEnum {
-
- public static var thriftType : TType { return TType.I32 }
-
-}
diff --git a/lib/cocoa/src/TError.h b/lib/cocoa/src/TError.h
deleted file mode 100644
index abb72c7ad..000000000
--- a/lib/cocoa/src/TError.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-
-extern NSString *TErrorDomain;
diff --git a/lib/cocoa/src/TError.m b/lib/cocoa/src/TError.m
deleted file mode 100644
index df7f92dc5..000000000
--- a/lib/cocoa/src/TError.m
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TError.h"
-
-
-NSString *TErrorDomain = @"TErrorDomain";
diff --git a/lib/cocoa/src/TList.swift b/lib/cocoa/src/TList.swift
deleted file mode 100644
index 005bd817d..000000000
--- a/lib/cocoa/src/TList.swift
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-
-public struct TList<Element : TSerializable> : MutableCollectionType, Hashable, ArrayLiteralConvertible, TSerializable {
-
- public static var thriftType : TType { return .LIST }
-
- typealias Storage = Array<Element>
-
- public typealias Index = Storage.Index
-
- private var storage = Storage()
-
- public var startIndex : Index {
- return storage.startIndex
- }
-
- public var endIndex : Index {
- return storage.endIndex
- }
-
- public subscript (position: Index) -> Element {
- get {
- return storage[position]
- }
- set {
- storage[position] = newValue
- }
- }
-
- public var hashValue : Int {
- let prime = 31
- var result = 1
- for element in storage {
- result = prime * result + element.hashValue
- }
- return result
- }
-
- public init(arrayLiteral elements: Element...) {
- self.storage = Storage(storage)
- }
-
- public init() {
- self.storage = Storage()
- }
-
- public mutating func append(newElement: Element) {
- self.storage.append(newElement)
- }
-
- public mutating func appendContentsOf<C : CollectionType where C.Generator.Element == Element>(newstorage: C) {
- self.storage.appendContentsOf(newstorage)
- }
-
- public mutating func insert(newElement: Element, atIndex index: Int) {
- self.storage.insert(newElement, atIndex: index)
- }
-
- public mutating func insertContentsOf<C : CollectionType where C.Generator.Element == Element>(newElements: C, at index: Int) {
- self.storage.insertContentsOf(newElements, at: index)
- }
-
- public mutating func removeAll(keepCapacity keepCapacity: Bool = true) {
- self.storage.removeAll(keepCapacity: keepCapacity)
- }
-
- public mutating func removeAtIndex(index: Index) {
- self.storage.removeAtIndex(index)
- }
-
- public mutating func removeFirst(n: Int = 0) {
- self.storage.removeFirst(n)
- }
-
- public mutating func removeLast() -> Element {
- return self.storage.removeLast()
- }
-
- public mutating func removeRange(subRange: Range<Index>) {
- self.storage.removeRange(subRange)
- }
-
- public mutating func reserveCapacity(minimumCapacity: Int) {
- self.storage.reserveCapacity(minimumCapacity)
- }
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> TList {
- let (elementType, size) = try proto.readListBegin()
- if elementType != Element.thriftType {
- throw NSError(
- domain: TProtocolErrorDomain,
- code: Int(TProtocolError.InvalidData.rawValue),
- userInfo: [TProtocolErrorExtendedErrorKey: NSNumber(int: TProtocolExtendedError.UnexpectedType.rawValue)])
- }
- var list = TList()
- for _ in 0..<size {
- let element = try Element.readValueFromProtocol(proto)
- list.storage.append(element)
- }
- try proto.readListEnd()
- return list
- }
-
- public static func writeValue(value: TList, toProtocol proto: TProtocol) throws {
- try proto.writeListBeginWithElementType(Element.thriftType, size: value.count)
- for element in value.storage {
- try Element.writeValue(element, toProtocol: proto)
- }
- try proto.writeListEnd()
- }
-}
-
-extension TList : CustomStringConvertible, CustomDebugStringConvertible {
-
- public var description : String {
- return storage.description
- }
-
- public var debugDescription : String {
- return storage.debugDescription
- }
-
-}
-
-public func ==<Element>(lhs: TList<Element>, rhs: TList<Element>) -> Bool {
- return lhs.storage == rhs.storage
-}
diff --git a/lib/cocoa/src/TMap.swift b/lib/cocoa/src/TMap.swift
deleted file mode 100644
index e96e7474e..000000000
--- a/lib/cocoa/src/TMap.swift
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public struct TMap<Key : TSerializable, Value : TSerializable> : CollectionType, DictionaryLiteralConvertible, TSerializable {
-
- public static var thriftType : TType { return .MAP }
-
- typealias Storage = Dictionary<Key, Value>
-
- public typealias Index = Storage.Index
-
- public typealias Element = Storage.Element
-
- private var storage : Storage
-
- public var startIndex : Index {
- return storage.startIndex
- }
-
- public var endIndex: Index {
- return storage.endIndex
- }
-
- public var keys: LazyMapCollection<[Key : Value], Key> {
- return storage.keys
- }
-
- public var values: LazyMapCollection<[Key : Value], Value> {
- return storage.values
- }
-
- public init() {
- storage = Storage()
- }
-
- public init(dictionaryLiteral elements: (Key, Value)...) {
- storage = Storage()
- for (key, value) in elements {
- storage[key] = value
- }
- }
-
- public init(minimumCapacity: Int) {
- storage = Storage(minimumCapacity: minimumCapacity)
- }
-
- public subscript (position: Index) -> Element {
- get {
- return storage[position]
- }
- }
-
- public func indexForKey(key: Key) -> Index? {
- return storage.indexForKey(key)
- }
-
- public subscript (key: Key) -> Value? {
- get {
- return storage[key]
- }
- set {
- storage[key] = newValue
- }
- }
-
- public mutating func updateValue(value: Value, forKey key: Key) -> Value? {
- return updateValue(value, forKey: key)
- }
-
- public mutating func removeAtIndex(index: DictionaryIndex<Key, Value>) -> (Key, Value) {
- return removeAtIndex(index)
- }
-
- public mutating func removeValueForKey(key: Key) -> Value? {
- return storage.removeValueForKey(key)
- }
-
- public mutating func removeAll(keepCapacity keepCapacity: Bool = false) {
- storage.removeAll(keepCapacity: keepCapacity)
- }
-
- public var hashValue : Int {
- let prime = 31
- var result = 1
- for (key, value) in storage {
- result = prime * result + key.hashValue
- result = prime * result + value.hashValue
- }
- return result
- }
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> TMap {
- let (keyType, valueType, size) = try proto.readMapBegin()
- if keyType != Key.thriftType || valueType != Value.thriftType {
- throw NSError(
- domain: TProtocolErrorDomain,
- code: Int(TProtocolError.InvalidData.rawValue),
- userInfo: [TProtocolErrorExtendedErrorKey: NSNumber(int: TProtocolExtendedError.UnexpectedType.rawValue)])
- }
- var map = TMap()
- for _ in 0..<size {
- let key = try Key.readValueFromProtocol(proto)
- let value = try Value.readValueFromProtocol(proto)
- map.storage[key] = value
- }
- try proto.readMapEnd()
- return map
- }
-
- public static func writeValue(value: TMap, toProtocol proto: TProtocol) throws {
- try proto.writeMapBeginWithKeyType(Key.thriftType, valueType: Value.thriftType, size: value.count)
- for (key, value) in value.storage {
- try Key.writeValue(key, toProtocol: proto)
- try Value.writeValue(value, toProtocol: proto)
- }
- try proto.writeMapEnd()
- }
-
-}
-
-
-extension TMap : CustomStringConvertible, CustomDebugStringConvertible {
-
- public var description : String {
- return storage.description
- }
-
- public var debugDescription : String {
- return storage.debugDescription
- }
-
-}
-
-public func ==<Key, Value>(lhs: TMap<Key,Value>, rhs: TMap<Key, Value>) -> Bool {
- if lhs.count != rhs.count {
- return false
- }
- return lhs.storage == rhs.storage
-}
diff --git a/lib/cocoa/src/TProcessor.h b/lib/cocoa/src/TProcessor.h
deleted file mode 100644
index 20c72e2e1..000000000
--- a/lib/cocoa/src/TProcessor.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TProtocol.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@protocol TProcessor <NSObject>
-
--(BOOL) processOnInputProtocol:(id <TProtocol>)inProtocol
- outputProtocol:(id <TProtocol>)outProtocol
- error:(NSError **)error;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/TProcessorFactory.h b/lib/cocoa/src/TProcessorFactory.h
deleted file mode 100644
index 85020a593..000000000
--- a/lib/cocoa/src/TProcessorFactory.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TProcessor.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@protocol TProcessorFactory <NSObject>
-
--(id<TProcessor>) processorForTransport:(id<TTransport>)transport;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/TProtocol.swift b/lib/cocoa/src/TProtocol.swift
deleted file mode 100644
index 177584979..000000000
--- a/lib/cocoa/src/TProtocol.swift
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public extension TProtocol {
-
- public func readMessageBegin() throws -> (String, TMessageType, Int) {
-
- var name : NSString?
- var type : Int32 = -1
- var sequenceID : Int32 = -1
-
- try readMessageBeginReturningName(&name, type: &type, sequenceID: &sequenceID)
-
- return (name as String!, TMessageType(rawValue: type)!, Int(sequenceID))
- }
-
- public func writeMessageBeginWithName(name: String, type: TMessageType, sequenceID: Int) throws {
- try writeMessageBeginWithName(name, type: type.rawValue, sequenceID: Int32(sequenceID))
- }
-
- public func readStructBegin() throws -> (String?) {
-
- var name : NSString? = nil
-
- try readStructBeginReturningName(&name)
-
- return (name as String?)
- }
-
- public func readFieldBegin() throws -> (String?, TType, Int) {
-
- var name : NSString? = nil
- var type : Int32 = -1
- var fieldID : Int32 = -1
-
- try readFieldBeginReturningName(&name, type: &type, fieldID: &fieldID)
-
- return (name as String?, TType(rawValue: type)!, Int(fieldID))
- }
-
- public func writeFieldBeginWithName(name: String, type: TType, fieldID: Int) throws {
- try writeFieldBeginWithName(name, type: type.rawValue, fieldID: Int32(fieldID))
- }
-
- public func readMapBegin() throws -> (TType, TType, Int32) {
-
- var keyType : Int32 = -1
- var valueType : Int32 = -1
- var size : Int32 = 0
-
- try readMapBeginReturningKeyType(&keyType, valueType: &valueType, size: &size)
-
- return (TType(rawValue: keyType)!, TType(rawValue: valueType)!, size)
- }
-
- public func writeMapBeginWithKeyType(keyType: TType, valueType: TType, size: Int) throws {
- try writeMapBeginWithKeyType(keyType.rawValue, valueType: valueType.rawValue, size: Int32(size))
- }
-
- public func readSetBegin() throws -> (TType, Int32) {
-
- var elementType : Int32 = -1
- var size : Int32 = 0
-
- try readSetBeginReturningElementType(&elementType, size: &size)
-
- return (TType(rawValue: elementType)!, size)
- }
-
- public func writeSetBeginWithElementType(elementType: TType, size: Int) throws {
- try writeSetBeginWithElementType(elementType.rawValue, size: Int32(size))
- }
-
- public func readListBegin() throws -> (TType, Int32) {
-
- var elementType : Int32 = -1
- var size : Int32 = 0
-
- try readListBeginReturningElementType(&elementType, size: &size)
-
- return (TType(rawValue: elementType)!, size)
- }
-
- public func writeListBeginWithElementType(elementType: TType, size: Int) throws {
- try writeListBeginWithElementType(elementType.rawValue, size: Int32(size))
- }
-
- public func writeFieldValue<T: TSerializable>(value: T, name: String, type: TType, id: Int32) throws {
- try writeFieldBeginWithName(name, type: type.rawValue, fieldID: id)
- try writeValue(value)
- try writeFieldEnd()
- }
-
- public func readValue<T: TSerializable>() throws -> T {
- return try T.readValueFromProtocol(self)
- }
-
- public func writeValue<T: TSerializable>(value: T) throws {
- try T.writeValue(value, toProtocol: self)
- }
-
- public func readResultMessageBegin() throws {
-
- let (_, type, _) = try readMessageBegin();
-
- if type == .EXCEPTION {
- let x = try readException()
- throw x
- }
-
- return
- }
-
- public func validateValue(value: Any?, named name: String) throws {
-
- if value == nil {
- throw NSError(
- domain: TProtocolErrorDomain,
- code: Int(TProtocolError.Unknown.rawValue),
- userInfo: [TProtocolErrorFieldNameKey: name])
- }
-
- }
-
- public func readException() throws -> ErrorType {
-
- var reason : String?
- var type = TApplicationError.Unknown
-
- try readStructBegin()
-
- fields: while (true) {
-
- let (_, fieldType, fieldID) = try readFieldBegin()
-
- switch (fieldID, fieldType) {
- case (_, .STOP):
- break fields
-
- case (1, .STRING):
- reason = try readValue() as String
-
- case (2, .I32):
- let typeVal = try readValue() as Int32
- if let tmp = TApplicationError(rawValue: typeVal) {
- type = tmp
- }
-
- case let (_, unknownType):
- try skipType(unknownType)
- }
-
- try readFieldEnd()
- }
-
- try readStructEnd()
-
- return NSError(type:type, reason:reason ?? "")
- }
-
- public func writeExceptionForMessageName(name: String, sequenceID: Int, ex: NSError) throws {
- try writeMessageBeginWithName(name, type: .EXCEPTION, sequenceID: sequenceID)
- try ex.write(self)
- try writeMessageEnd()
- }
-
- public func skipType(type: TType) throws {
- try TProtocolUtil.skipType(type.rawValue, onProtocol: self)
- }
-
-}
diff --git a/lib/cocoa/src/TSerializable.swift b/lib/cocoa/src/TSerializable.swift
deleted file mode 100644
index 3fdfd41b0..000000000
--- a/lib/cocoa/src/TSerializable.swift
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public protocol TSerializable : Hashable {
-
- static var thriftType : TType { get }
-
- init()
-
- static func readValueFromProtocol(proto: TProtocol) throws -> Self
-
- static func writeValue(value: Self, toProtocol proto: TProtocol) throws
-
-}
-
-
-
-infix operator ?== {}
-
-public func ?==<T: TSerializable>(lhs: T?, rhs: T?) -> Bool {
- if let l = lhs, r = rhs {
- return l == r
- }
- return lhs == rhs
-}
-
-public func ?==<T: TSerializable>(lhs: T, rhs: T) -> Bool {
- return lhs == rhs
-}
-
-
-
-extension Bool : TSerializable {
-
- public static let thriftType = TType.BOOL
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Bool {
- var value : ObjCBool = false
- try proto.readBool(&value)
- return value.boolValue
- }
-
- public static func writeValue(value: Bool, toProtocol proto: TProtocol) throws {
- try proto.writeBool(value)
- }
-
-}
-
-extension Int8 : TSerializable {
-
- public static let thriftType = TType.BYTE
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Int8 {
- var value = UInt8()
- try proto.readByte(&value)
- return Int8(value)
- }
-
- public static func writeValue(value: Int8, toProtocol proto: TProtocol) throws {
- try proto.writeByte(UInt8(value))
- }
-
-}
-
-extension Int16 : TSerializable {
-
- public static let thriftType = TType.I16
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Int16 {
- var value = Int16()
- try proto.readI16(&value)
- return value
- }
-
- public static func writeValue(value: Int16, toProtocol proto: TProtocol) throws {
- try proto.writeI16(value)
- }
-
-}
-
-extension Int : TSerializable {
-
- public static let thriftType = TType.I32
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Int {
- var value = Int32()
- try proto.readI32(&value)
- return Int(value)
- }
-
- public static func writeValue(value: Int, toProtocol proto: TProtocol) throws {
- try proto.writeI32(Int32(value))
- }
-
-}
-
-extension Int32 : TSerializable {
-
- public static let thriftType = TType.I32
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Int32 {
- var value = Int32()
- try proto.readI32(&value)
- return value
- }
-
- public static func writeValue(value: Int32, toProtocol proto: TProtocol) throws {
- try proto.writeI32(value)
- }
-
-}
-
-extension Int64 : TSerializable {
-
- public static let thriftType = TType.I64
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Int64 {
- var value = Int64()
- try proto.readI64(&value)
- return value
- }
-
- public static func writeValue(value: Int64, toProtocol proto: TProtocol) throws {
- try proto.writeI64(value)
- }
-
-}
-
-extension Double : TSerializable {
-
- public static let thriftType = TType.DOUBLE
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> Double {
- var value = Double()
- try proto.readDouble(&value)
- return value
- }
-
- public static func writeValue(value: Double, toProtocol proto: TProtocol) throws {
- try proto.writeDouble(value)
- }
-
-}
-
-extension String : TSerializable {
-
- public static let thriftType = TType.STRING
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> String {
- var value : NSString?
- try proto.readString(&value)
- return value as! String
- }
-
- public static func writeValue(value: String, toProtocol proto: TProtocol) throws {
- try proto.writeString(value)
- }
-
-}
diff --git a/lib/cocoa/src/TSet.swift b/lib/cocoa/src/TSet.swift
deleted file mode 100644
index 85833e5c0..000000000
--- a/lib/cocoa/src/TSet.swift
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public struct TSet<Element : TSerializable> : CollectionType, ArrayLiteralConvertible, TSerializable {
-
- public static var thriftType : TType { return .SET }
-
- public typealias Index = Storage.Index
-
- typealias Storage = Set<Element>
-
- private var storage : Storage
-
- public init() {
- storage = Storage()
- }
-
- public init(arrayLiteral elements: Element...) {
- storage = Storage(elements)
- }
-
- public init<S : SequenceType where S.Generator.Element == Element>(_ sequence: S) {
- storage = Storage(sequence)
- }
-
- public var startIndex : Index { return storage.startIndex }
-
- public var endIndex : Index { return storage.endIndex }
-
- public mutating func insert(member: Element) {
- return storage.insert(member)
- }
-
- public mutating func remove(element: Element) -> Element? {
- return storage.remove(element)
- }
-
- public mutating func removeAll(keepCapacity keepCapacity: Bool = false) {
- return storage.removeAll(keepCapacity: keepCapacity)
- }
-
- public mutating func removeAtIndex(index: SetIndex<Element>) -> Element {
- return storage.removeAtIndex(index)
- }
-
- public subscript (position: SetIndex<Element>) -> Element {
- return storage[position]
- }
-
- public func union(other: TSet) -> TSet {
- return TSet(storage.union(other))
- }
-
- public func intersect(other: TSet) -> TSet {
- return TSet(storage.intersect(other))
- }
-
- public func exclusiveOr(other: TSet) -> TSet {
- return TSet(storage.exclusiveOr(other))
- }
-
- public func subtract(other: TSet) -> TSet {
- return TSet(storage.subtract(other))
- }
-
- public mutating func intersectInPlace(other: TSet) {
- storage.intersectInPlace(other)
- }
-
- public mutating func exclusiveOrInPlace(other: TSet) {
- storage.exclusiveOrInPlace(other)
- }
-
- public mutating func subtractInPlace(other: TSet) {
- storage.subtractInPlace(other)
- }
-
- public func isSubsetOf(other: TSet) -> Bool {
- return storage.isSubsetOf(other)
- }
-
- public func isDisjointWith(other: TSet) -> Bool {
- return storage.isDisjointWith(other)
- }
-
- public func isSupersetOf(other: TSet) -> Bool {
- return storage.isSupersetOf(other)
- }
-
- public var isEmpty: Bool { return storage.isEmpty }
-
- public var hashValue : Int {
- let prime = 31
- var result = 1
- for element in storage {
- result = prime * result + element.hashValue
- }
- return result
- }
-
- public static func readValueFromProtocol(proto: TProtocol) throws -> TSet {
- let (elementType, size) = try proto.readSetBegin()
- if elementType != Element.thriftType {
- throw NSError(
- domain: TProtocolErrorDomain,
- code: Int(TProtocolError.InvalidData.rawValue),
- userInfo: [TProtocolErrorExtendedErrorKey: NSNumber(int: elementType.rawValue)])
- }
- var set = TSet()
- for _ in 0..<size {
- let element = try Element.readValueFromProtocol(proto)
- set.storage.insert(element)
- }
- try proto.readSetEnd()
- return set
- }
-
- public static func writeValue(value: TSet, toProtocol proto: TProtocol) throws {
- try proto.writeSetBeginWithElementType(Element.thriftType, size: value.count)
- for element in value.storage {
- try Element.writeValue(element, toProtocol: proto)
- }
- try proto.writeSetEnd()
- }
-
-}
-
-extension TSet : CustomStringConvertible, CustomDebugStringConvertible {
-
- public var description : String {
- return storage.description
- }
-
- public var debugDescription : String {
- return storage.debugDescription
- }
-
-}
-
-public func ==<Element>(lhs: TSet<Element>, rhs: TSet<Element>) -> Bool {
- return lhs.storage == rhs.storage
-}
diff --git a/lib/cocoa/src/TSharedProcessorFactory.h b/lib/cocoa/src/TSharedProcessorFactory.h
deleted file mode 100644
index c75fad1ee..000000000
--- a/lib/cocoa/src/TSharedProcessorFactory.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TProcessorFactory.h"
-
-
-@interface TSharedProcessorFactory : NSObject <TProcessorFactory>
-
--(id) initWithSharedProcessor:(id<TProcessor>)sharedProcessor;
-
-@end
diff --git a/lib/cocoa/src/TSharedProcessorFactory.m b/lib/cocoa/src/TSharedProcessorFactory.m
deleted file mode 100644
index 3d55f4793..000000000
--- a/lib/cocoa/src/TSharedProcessorFactory.m
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-
-#import "TSharedProcessorFactory.h"
-
-
-@interface TSharedProcessorFactory ()
-
-@property(strong, nonatomic) id<TProcessor> sharedProcessor;
-
-@end
-
-
-@implementation TSharedProcessorFactory
-
-
--(id) initWithSharedProcessor:(id<TProcessor>)sharedProcessor
-{
- self = [super init];
- if (self) {
- _sharedProcessor = sharedProcessor;
- }
-
- return self;
-}
-
--(id<TProcessor>) processorForTransport:(id<TTransport>)transport
-{
- return _sharedProcessor;
-}
-
-@end
diff --git a/lib/cocoa/src/TStruct.swift b/lib/cocoa/src/TStruct.swift
deleted file mode 100644
index cea72e752..000000000
--- a/lib/cocoa/src/TStruct.swift
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-import Foundation
-
-
-public protocol TStruct : TSerializable {
-}
-
-
-public extension TStruct {
-
- public static var thriftType : TType { return TType.STRUCT }
-
-}
diff --git a/lib/cocoa/src/Thrift.h b/lib/cocoa/src/Thrift.h
deleted file mode 100644
index d01826dbe..000000000
--- a/lib/cocoa/src/Thrift.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#define ThriftVersion @"1.0.0"
diff --git a/lib/cocoa/src/protocol/TBase.h b/lib/cocoa/src/protocol/TBase.h
deleted file mode 100644
index 9935d5068..000000000
--- a/lib/cocoa/src/protocol/TBase.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-#import "TProtocol.h"
-
-@protocol TBase <NSObject>
-
-/**
- * De-serialize object from the given input protocol
- *
- * @param inProtocol protocol used for reading
- */
--(BOOL) read:(id <TProtocol>)inProtocol error:(NSError **)error;
-
-/**
- * Serialize object to the given protocol
- *
- * @param outProtocol output protocol used for writing
- */
--(BOOL) write:(id <TProtocol>)outProtocol error:(NSError **)error;
-
-
-/**
- * Validate required fields
- */
--(BOOL) validate:(NSError *__autoreleasing *)__thriftError;
-
-@end
diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.h b/lib/cocoa/src/protocol/TBinaryProtocol.h
deleted file mode 100644
index bb90fadcb..000000000
--- a/lib/cocoa/src/protocol/TBinaryProtocol.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocol.h"
-#import "TTransport.h"
-#import "TProtocolFactory.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TBinaryProtocol : NSObject <TProtocol>
-
-@property (assign, nonatomic) UInt32 messageSizeLimit;
-
--(id) initWithTransport:(id <TTransport>)transport;
-
--(id) initWithTransport:(id <TTransport>)transport
- strictRead:(BOOL)strictRead
- strictWrite:(BOOL)strictWrite;
-
-@end;
-
-
-@interface TBinaryProtocolFactory : NSObject <TProtocolFactory>
-
-+(TBinaryProtocolFactory *) sharedFactory;
-
--(TBinaryProtocol *) newProtocolOnTransport:(id <TTransport>)transport;
-
-@end
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.m b/lib/cocoa/src/protocol/TBinaryProtocol.m
deleted file mode 100644
index 1f9e57ac8..000000000
--- a/lib/cocoa/src/protocol/TBinaryProtocol.m
+++ /dev/null
@@ -1,740 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TBinaryProtocol.h"
-#import "TProtocolError.h"
-
-
-static SInt32 VERSION_1 = 0x80010000;
-static SInt32 VERSION_MASK = 0xffff0000;
-
-
-static TBinaryProtocolFactory *gSharedFactory = nil;
-
-
-@implementation TBinaryProtocolFactory
-
-+(TBinaryProtocolFactory *) sharedFactory
-{
- if (gSharedFactory == nil) {
- gSharedFactory = [[TBinaryProtocolFactory alloc] init];
- }
-
- return gSharedFactory;
-}
-
--(NSString *) protocolName
-{
- return @"binary";
-}
-
--(TBinaryProtocol *) newProtocolOnTransport:(id <TTransport>)transport
-{
- return [[TBinaryProtocol alloc] initWithTransport:transport];
-}
-
-@end
-
-
-@interface TBinaryProtocol ()
-
-@property(strong, nonatomic) id <TTransport> transport;
-
-@property(assign, nonatomic) BOOL strictRead;
-@property(assign, nonatomic) BOOL strictWrite;
-
-@property(strong, nonatomic) NSString *currentMessageName;
-@property(strong, nonatomic) NSString *currentFieldName;
-
-@end
-
-
-@implementation TBinaryProtocol
-
--(id) initWithTransport:(id <TTransport>)aTransport
-{
- return [self initWithTransport:aTransport strictRead:NO strictWrite:YES];
-}
-
--(id) initWithTransport:(id <TTransport>)transport
- strictRead:(BOOL)strictRead
- strictWrite:(BOOL)strictWrite
-{
- self = [super init];
- if (self) {
- _transport = transport;
- _strictRead = strictRead;
- _strictWrite = strictWrite;
- }
- return self;
-}
-
--(id <TTransport>) transport
-{
- return _transport;
-}
-
--(NSString *) readStringBody:(int)size error:(NSError **)error
-{
- NSMutableData *data = [NSMutableData dataWithLength:size];
- if (!data) {
- PROTOCOL_ERROR(nil, Unknown, @"Unable to allocate %d bytes", size);
- }
-
- if (![_transport readAll:data.mutableBytes offset:0 length:size error:error]) {
- PROTOCOL_TRANSPORT_ERROR(nil, error, @"Transport read failed");
- }
-
- return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-}
-
-
--(BOOL) readMessageBeginReturningName:(NSString **)name
- type:(SInt32 *)type
- sequenceID:(SInt32 *)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- SInt32 size;
- if (![self readI32:&size error:error]) {
- return NO;
- }
- ;
-
- if (size < 0) {
- int version = size & VERSION_MASK;
- if (version != VERSION_1) {
- PROTOCOL_ERROR(NO, BadVersion, @"Bad message version");
- }
- if (type != NULL) {
- *type = size & 0x00FF;
- }
- NSString *messageName;
- if (![self readString:&messageName error:error]) {
- return NO;
- }
- if (name != nil) {
- *name = messageName;
- }
- }
- else {
-
- if (_strictRead) {
- PROTOCOL_ERROR(NO, InvalidData, @"Missing message version, old client?");
- }
-
- if (_messageSizeLimit > 0 && size > _messageSizeLimit) {
- PROTOCOL_ERROR(NO, SizeLimit, @"Message exceeeds size limit of %d", (int)size);
- }
-
- NSString *messageName = [self readStringBody:size error:error];
- if (!messageName) {
- return NO;
- }
-
- if (name != NULL) {
- *name = messageName;
- }
-
- UInt8 messageType;
- if (![self readByte:&messageType error:error]) {
- return NO;
- }
-
- if (type != NULL) {
- *type = messageType;
- }
- }
-
- SInt32 seqID;
- if (![self readI32:&seqID error:error]) {
- return NO;
- }
- if (sequenceID != NULL) {
- *sequenceID = seqID;
- }
-
- return YES;
-}
-
-
--(BOOL) readMessageEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readStructBeginReturningName:(NSString *__autoreleasing *)name error:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readStructEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readFieldBeginReturningName:(NSString *__autoreleasing *)name
- type:(SInt32 *)fieldType
- fieldID:(SInt32 *)fieldID
- error:(NSError *__autoreleasing *)error
-{
- if (name != nil) {
- *name = nil;
- }
-
- UInt8 ft;
- if (![self readByte:&ft error:error]) {
- return NO;
- }
- if (fieldType != NULL) {
- *fieldType = ft;
- }
- if (ft != TTypeSTOP) {
- SInt16 fid;
- if (![self readI16:&fid error:error]) {
- return NO;
- }
- if (fieldID != NULL) {
- *fieldID = fid;
- }
- }
- return YES;
-}
-
-
--(BOOL) readFieldEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readString:(NSString *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- SInt32 size;
- if (![self readI32:&size error:error]) {
- return NO;
- }
-
- NSString *string = [self readStringBody:size error:error];
- if (!string) {
- return NO;
- }
-
- *value = string;
-
- return YES;
-}
-
-
--(BOOL) readBool:(BOOL *)value error:(NSError *__autoreleasing *)error
-{
- UInt8 byte;
- if (![self readByte:&byte error:error]) {
- return NO;
- }
-
- *value = byte == 1;
-
- return YES;
-}
-
-
--(BOOL) readByte:(UInt8 *)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[1];
- if (![_transport readAll:buff offset:0 length:1 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- *value = buff[0];
-
- return YES;
-}
-
-
--(BOOL) readI16:(SInt16 *)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[2];
- if (![_transport readAll:buff offset:0 length:2 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- *value =
- ((SInt16)(buff[0] & 0xff) << 8) |
- ((SInt16)(buff[1] & 0xff));
-
- return YES;
-}
-
-
--(BOOL) readI32:(SInt32 *)value error:(NSError *__autoreleasing *)error
-{
- UInt8 i32rd[4];
- if (![_transport readAll:i32rd offset:0 length:4 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- *value =
- ((i32rd[0] & 0xff) << 24) |
- ((i32rd[1] & 0xff) << 16) |
- ((i32rd[2] & 0xff) << 8) |
- ((i32rd[3] & 0xff));
-
- return YES;
-}
-
-
--(BOOL) readI64:(SInt64 *)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[8];
- if (![_transport readAll:buff offset:0 length:8 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- *value =
- ((SInt64)(buff[0] & 0xff) << 56) |
- ((SInt64)(buff[1] & 0xff) << 48) |
- ((SInt64)(buff[2] & 0xff) << 40) |
- ((SInt64)(buff[3] & 0xff) << 32) |
- ((SInt64)(buff[4] & 0xff) << 24) |
- ((SInt64)(buff[5] & 0xff) << 16) |
- ((SInt64)(buff[6] & 0xff) << 8) |
- ((SInt64)(buff[7] & 0xff));
-
- return YES;
-}
-
-
--(BOOL) readDouble:(double *)value error:(NSError *__autoreleasing *)error
-{
- // FIXME - will this get us into trouble on PowerPC?
- return [self readI64:(SInt64 *)value error:error];
-}
-
-
--(BOOL) readBinary:(NSData *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- SInt32 size;
- if (![self readI32:&size error:error]) {
- return NO;
- }
-
- NSMutableData *data = [NSMutableData dataWithLength:size];
- if (!data) {
- PROTOCOL_ERROR(NO, Unknown, @"Unable to allocate %d bytes", (int)size);
- }
-
- if (![_transport readAll:data.mutableBytes offset:0 length:size error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- *value = data;
-
- return YES;
-}
-
-
--(BOOL) readMapBeginReturningKeyType:(SInt32 *)keyType
- valueType:(SInt32 *)valueType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- UInt8 kt;
- if (![self readByte:&kt error:error]) {
- return NO;
- }
-
- UInt8 vt;
- if (![self readByte:&vt error:error]) {
- return NO;
- }
-
- SInt32 s;
- if (![self readI32:&s error:error]) {
- return NO;
- }
-
- if (keyType != NULL) {
- *keyType = kt;
- }
-
- if (valueType != NULL) {
- *valueType = vt;
- }
-
- if (size != NULL) {
- *size = s;
- }
-
- return YES;
-}
-
-
--(BOOL) readMapEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readSetBeginReturningElementType:(SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- UInt8 et;
- if (![self readByte:&et error:error]) {
- return NO;
- }
-
- SInt32 s;
- if (![self readI32:&s error:error]) {
- return NO;
- }
-
- if (elementType != NULL) {
- *elementType = et;
- }
-
- if (size != NULL) {
- *size = s;
- }
-
- return YES;
-}
-
-
--(BOOL) readSetEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) readListBeginReturningElementType:(SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- UInt8 et;
- if (![self readByte:&et error:error]) {
- return NO;
- }
-
- SInt32 s;
- if (![self readI32:&s error:error]) {
- return NO;
- }
-
- if (elementType != NULL) {
- *elementType = et;
- }
-
- if (size != NULL) {
- *size = s;
- }
-
- return YES;
-}
-
-
--(BOOL) readListEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
-
--(BOOL) writeMessageBeginWithName:(NSString *)name
- type:(SInt32)messageType
- sequenceID:(SInt32)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- if (_strictWrite) {
-
- int version = VERSION_1 | messageType;
-
- if (![self writeI32:version error:error]) {
- return NO;
- }
-
- if (![self writeString:name error:error]) {
- return NO;
- }
-
- if (![self writeI32:sequenceID error:error]) {
- return NO;
- }
- }
- else {
-
- if (![self writeString:name error:error]) {
- return NO;
- }
-
- if (![self writeByte:messageType error:error]) {
- return NO;
- }
-
- if (![self writeI32:sequenceID error:error]) {
- return NO;
- }
- }
-
- _currentMessageName = name;
-
- return YES;
-}
-
-
--(BOOL) writeMessageEnd:(NSError *__autoreleasing *)error
-{
- _currentMessageName = nil;
- return YES;
-}
-
-
--(BOOL) writeStructBeginWithName:(NSString *)name
- error:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) writeStructEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) writeFieldBeginWithName:(NSString *)name
- type:(SInt32)fieldType
- fieldID:(SInt32)fieldID
- error:(NSError *__autoreleasing *)error
-{
- if (![self writeByte:fieldType error:error]) {
- return NO;
- }
-
- if (![self writeI16:fieldID error:error]) {
- return NO;
- }
-
- return YES;
-}
-
-
--(BOOL) writeBool:(BOOL)value error:(NSError *__autoreleasing *)error
-{
- return [self writeByte:(value ? 1 : 0) error:error];
-}
-
-
--(BOOL) writeByte:(UInt8)value error:(NSError *__autoreleasing *)error
-{
- if (![_transport write:&value offset:0 length:1 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
- return YES;
-}
-
-
--(BOOL) writeI16:(short)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[2];
- buff[0] = 0xff & (value >> 8);
- buff[1] = 0xff & value;
-
- if (![_transport write:buff offset:0 length:2 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
-
--(BOOL) writeI32:(SInt32)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[4];
- buff[0] = 0xFF & (value >> 24);
- buff[1] = 0xFF & (value >> 16);
- buff[2] = 0xFF & (value >> 8);
- buff[3] = 0xFF & value;
-
- if (![_transport write:buff offset:0 length:4 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
-
--(BOOL) writeI64:(SInt64)value error:(NSError *__autoreleasing *)error
-{
- UInt8 buff[8];
- buff[0] = 0xFF & (value >> 56);
- buff[1] = 0xFF & (value >> 48);
- buff[2] = 0xFF & (value >> 40);
- buff[3] = 0xFF & (value >> 32);
- buff[4] = 0xFF & (value >> 24);
- buff[5] = 0xFF & (value >> 16);
- buff[6] = 0xFF & (value >> 8);
- buff[7] = 0xFF & value;
-
- if (![_transport write:buff offset:0 length:8 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
-
--(BOOL) writeDouble:(double)value error:(NSError *__autoreleasing *)error
-{
- // FIXME - will this get us in trouble on PowerPC?
- if (![self writeI64:*(SInt64 *)&value error:error]) {
- return NO;
- }
-
- return YES;
-}
-
-
--(BOOL) writeString:(NSString *)value error:(NSError *__autoreleasing *)error
-{
- if (value != nil) {
-
- const char *utf8Bytes = [value UTF8String];
-
- SInt32 length = (SInt32)strlen(utf8Bytes);
- if (![self writeI32:length error:error]) {
- return NO;
- }
-
- if (![_transport write:(UInt8 *)utf8Bytes offset:0 length:(int)length error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- }
- else {
-
- // instead of crashing when we get null, let's write out a zero
- // length string
- if (![self writeI32:0 error:error]) {
- return NO;
- }
-
- }
-
- return YES;
-}
-
-
--(BOOL) writeBinary:(NSData *)data error:(NSError *__autoreleasing *)error
-{
- if (![self writeI32:(SInt32)data.length error:error]) {
- return NO;
- }
-
- if (![_transport write:data.bytes offset:0 length:(UInt32)data.length error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
-
--(BOOL) writeFieldStop:(NSError *__autoreleasing *)error
-{
- if (![self writeByte:TTypeSTOP error:error]) {
- return NO;
- }
-
- return YES;
-}
-
-
--(BOOL) writeFieldEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) writeMapBeginWithKeyType:(SInt32)keyType
- valueType:(SInt32)valueType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- if (![self writeByte:keyType error:error]) {
- return NO;
- }
- if (![self writeByte:valueType error:error]) {
- return NO;
- }
- if (![self writeI32:(int)size error:error]) {
- return NO;
- }
- return YES;
-}
-
-
--(BOOL) writeMapEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) writeSetBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- if (![self writeByte:elementType error:error]) {
- return NO;
- }
- if (![self writeI32:size error:error]) {
- return NO;
- }
- return YES;
-}
-
-
--(BOOL) writeSetEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-
--(BOOL) writeListBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- if (![self writeByte:elementType error:error]) {
- return NO;
- }
- if (![self writeI32:size error:error]) {
- return NO;
- }
- return YES;
-}
-
-
--(BOOL) writeListEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/protocol/TCompactProtocol.h b/lib/cocoa/src/protocol/TCompactProtocol.h
deleted file mode 100644
index 3f6accc5a..000000000
--- a/lib/cocoa/src/protocol/TCompactProtocol.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocol.h"
-#import "TTransport.h"
-#import "TProtocolFactory.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TCompactProtocol : NSObject <TProtocol>
-
--(id) initWithTransport:(id <TTransport>)transport;
-
-@end
-
-@interface TCompactProtocolFactory : NSObject <TProtocolFactory>
-
-+(TCompactProtocolFactory *) sharedFactory;
-
--(TCompactProtocol *) newProtocolOnTransport:(id <TTransport>)transport;
-
-@end
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/protocol/TCompactProtocol.m b/lib/cocoa/src/protocol/TCompactProtocol.m
deleted file mode 100644
index 9b0ebb2a7..000000000
--- a/lib/cocoa/src/protocol/TCompactProtocol.m
+++ /dev/null
@@ -1,983 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TCompactProtocol.h"
-#import "TProtocolError.h"
-
-static const UInt8 COMPACT_PROTOCOL_ID = 0x82;
-static const UInt8 COMPACT_VERSION = 1;
-static const UInt8 COMPACT_VERSION_MASK = 0x1F; // 0001 1111
-static const UInt8 COMPACT_TYPE_MASK = 0xE0; // 1110 0000
-static const UInt8 COMPACT_TYPE_BITS = 0x07; // 0000 0111
-static const int COMPACT_TYPE_SHIFT_AMOUNT = 5;
-
-enum {
- TCType_STOP = 0x00,
- TCType_BOOLEAN_TRUE = 0x01,
- TCType_BOOLEAN_FALSE = 0x02,
- TCType_BYTE = 0x03,
- TCType_I16 = 0x04,
- TCType_I32 = 0x05,
- TCType_I64 = 0x06,
- TCType_DOUBLE = 0x07,
- TCType_BINARY = 0x08,
- TCType_LIST = 0x09,
- TCType_SET = 0x0A,
- TCType_MAP = 0x0B,
- TCType_STRUCT = 0x0C,
-};
-
-@implementation TCompactProtocolFactory
-
-+(TCompactProtocolFactory *) sharedFactory
-{
- static TCompactProtocolFactory *gSharedFactory = nil;
- if (gSharedFactory == nil) {
- gSharedFactory = [[TCompactProtocolFactory alloc] init];
- }
-
- return gSharedFactory;
-}
-
--(NSString *) protocolName
-{
- return @"compact";
-}
-
--(TCompactProtocol *) newProtocolOnTransport:(id <TTransport>)transport
-{
- return [[TCompactProtocol alloc] initWithTransport:transport];
-}
-
-@end
-
-
-@interface TCompactProtocol ()
-
-@property(strong, nonatomic) id <TTransport> transport;
-
-@property(strong, nonatomic) NSMutableArray *lastField;
-@property(assign, nonatomic) short lastFieldId;
-
-@property(strong, nonatomic) NSString *boolFieldName;
-@property(strong, nonatomic) NSNumber *boolFieldType;
-@property(strong, nonatomic) NSNumber *boolFieldId;
-@property(strong, nonatomic) NSNumber *booleanValue;
-
-@property(strong, nonatomic) NSString *currentMessageName;
-
-@end
-
-
-@implementation TCompactProtocol
-
--(id) init
-{
- self = [super init];
-
- if (self != nil) {
- _lastField = [[NSMutableArray alloc] init];
- }
-
- return self;
-}
-
--(id) initWithTransport:(id <TTransport>)aTransport
-{
- self = [self init];
-
- if (self != nil) {
- _transport = aTransport;
- }
-
- return self;
-}
-
--(id <TTransport>) transport
-{
- return _transport;
-}
-
--(BOOL) writeByteDirect:(UInt8)n error:(NSError *__autoreleasing *)error
-{
- if (![_transport write:(UInt8 *)&n offset:0 length:1 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
- return YES;
-}
-
--(BOOL) writeVarint32:(UInt32)n error:(NSError *__autoreleasing *)error
-{
- UInt8 i32buf[5] = {0};
- UInt32 idx = 0;
-
- while (true) {
- if ((n & ~0x7F) == 0) {
- i32buf[idx++] = (UInt8)n;
- break;
- }
- else {
- i32buf[idx++] = (UInt8)((n & 0x7F) | 0x80);
- n >>= 7;
- }
- }
-
- if (![_transport write:i32buf offset:0 length:idx error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
--(BOOL) writeMessageBeginWithName:(NSString *)name
- type:(SInt32)messageType
- sequenceID:(SInt32)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- if (![self writeByteDirect:COMPACT_PROTOCOL_ID error:error]) {
- return NO;
- }
- if (![self writeByteDirect:(UInt8)((COMPACT_VERSION & COMPACT_VERSION_MASK) |
- ((((UInt32)messageType) << COMPACT_TYPE_SHIFT_AMOUNT) & COMPACT_TYPE_MASK)) error:error])
- {
- return NO;
- }
- if (![self writeVarint32:(UInt32)sequenceID error:error]) {
- return NO;
- }
- if (![self writeString:name error:error]) {
- return NO;
- }
-
- _currentMessageName = name;
-
- return YES;
-}
-
--(BOOL) writeStructBeginWithName:(NSString *)name error:(NSError *__autoreleasing *)error
-{
- [_lastField addObject:@(_lastFieldId)];
- _lastFieldId = 0;
- return YES;
-}
-
--(BOOL) writeStructEnd:(NSError *__autoreleasing *)error
-{
- _lastFieldId = [_lastField.lastObject shortValue];
- [_lastField removeLastObject];
- return YES;
-}
-
--(BOOL) writeFieldBeginWithName:(NSString *)name
- type:(SInt32)fieldType
- fieldID:(SInt32)fieldID
- error:(NSError *__autoreleasing *)error
-{
- if (fieldType == TTypeBOOL) {
- _boolFieldName = [name copy];
- _boolFieldType = @(fieldType);
- _boolFieldId = @(fieldID);
- return YES;
- }
- else {
- return [self writeFieldBeginInternalWithName:name
- type:fieldType
- fieldID:fieldID
- typeOverride:0xFF
- error:error];
- }
-}
-
--(BOOL) writeFieldBeginInternalWithName:(NSString *)name
- type:(SInt32)fieldType
- fieldID:(SInt32)fieldID
- typeOverride:(UInt8)typeOverride
- error:(NSError *__autoreleasing *)error
-{
- UInt8 typeToWrite = typeOverride == 0xFF ? [self compactTypeForTType:fieldType] : typeOverride;
-
- // check if we can use delta encoding for the field id
- if (fieldID > _lastFieldId && fieldID - _lastFieldId <= 15) {
- // Write them together
- if (![self writeByteDirect:(fieldID - _lastFieldId) << 4 | typeToWrite error:error]) {
- return NO;
- }
- }
- else {
- // Write them separate
- if (![self writeByteDirect:typeToWrite error:error]) {
- return NO;
- }
- if (![self writeI16:fieldID error:error]) {
- return NO;
- }
- }
-
- _lastFieldId = fieldID;
-
- return YES;
-}
-
--(BOOL) writeFieldStop:(NSError *__autoreleasing *)error
-{
- return [self writeByteDirect:TCType_STOP error:error];
-}
-
--(BOOL) writeMapBeginWithKeyType:(SInt32)keyType
- valueType:(SInt32)valueType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- if (size == 0) {
- if (![self writeByteDirect:0 error:error]) {
- return NO;
- }
- }
- else {
- if (![self writeVarint32:(UInt32)size error:error]) {
- return NO;
- }
- if (![self writeByteDirect:[self compactTypeForTType:keyType] << 4 | [self compactTypeForTType:valueType] error:error]) {
- return NO;
- }
- }
- return YES;
-}
-
--(BOOL) writeListBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- return [self writeCollectionBeginWithElementType:elementType size:size error:error];
-}
-
--(BOOL) writeSetBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- return [self writeCollectionBeginWithElementType:elementType size:size error:error];
-}
-
--(BOOL) writeBool:(BOOL)b error:(NSError *__autoreleasing *)error
-{
- BOOL result;
- if (_boolFieldId != nil && _boolFieldName != nil && _boolFieldType != nil) {
- // we haven't written the field header yet
- result = [self writeFieldBeginInternalWithName:_boolFieldName
- type:_boolFieldType.intValue
- fieldID:_boolFieldId.intValue
- typeOverride:b ? TCType_BOOLEAN_TRUE : TCType_BOOLEAN_FALSE
- error:error];
- _boolFieldId = nil;
- _boolFieldName = nil;
- _boolFieldType = nil;
- }
- else {
- // we're not part of a field, so just Write the value.
- result = [self writeByteDirect:b ? TCType_BOOLEAN_TRUE : TCType_BOOLEAN_FALSE error:error];
- }
- return result;
-}
-
--(BOOL) writeByte:(UInt8)value error:(NSError *__autoreleasing *)error
-{
- return [self writeByteDirect:value error:error];
-}
-
--(BOOL) writeI16:(SInt16)value error:(NSError *__autoreleasing *)error
-{
- return [self writeVarint32:[self i32ToZigZag:value] error:error];
-}
-
--(BOOL) writeI32:(SInt32)value error:(NSError *__autoreleasing *)error
-{
- return [self writeVarint32:[self i32ToZigZag:value] error:error];
-}
-
--(BOOL) writeI64:(SInt64)value error:(NSError *__autoreleasing *)error
-{
- return [self writeVarint64:[self i64ToZigZag:value] error:error];
-}
-
--(BOOL) writeDouble:(double)value error:(NSError *__autoreleasing *)error
-{
- // Safe bit-casting double->uint64
-
- UInt64 bits = 0;
- memcpy(&bits, &value, 8);
-
- bits = OSSwapHostToLittleInt64(bits);
-
- if (![_transport write:(UInt8 *)&bits offset:0 length:8 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
--(BOOL) writeString:(NSString *)value error:(NSError *__autoreleasing *)error
-{
- return [self writeBinary:[value dataUsingEncoding:NSUTF8StringEncoding] error:error];
-}
-
--(BOOL) writeBinary:(NSData *)data error:(NSError *__autoreleasing *)error
-{
- if (![self writeVarint32:(UInt32)data.length error:error]) {
- return NO;
- }
- if (![_transport write:data.bytes offset:0 length:(UInt32)data.length error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
- return YES;
-}
-
--(BOOL) writeMessageEnd:(NSError *__autoreleasing *)error
-{
- _currentMessageName = nil;
- return YES;
-}
-
--(BOOL) writeMapEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(BOOL) writeListEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(BOOL) writeSetEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(BOOL) writeFieldEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(BOOL) writeCollectionBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- UInt8 ctypeElement = [self compactTypeForTType:elementType];
-
- if (size <= 14) {
- if (![self writeByteDirect:size << 4 | ctypeElement error:error]) {
- return NO;
- }
- }
- else {
- if (![self writeByteDirect:0xf0 | ctypeElement error:error]) {
- return NO;
- }
- if (![self writeVarint32:(UInt32)size error:error]) {
- return NO;
- }
- }
- return YES;
-}
-
--(BOOL) writeVarint64:(UInt64)n error:(NSError *__autoreleasing *)error
-{
- UInt8 varint64out[10] = {0};
- int idx = 0;
-
- while (true) {
- if ((n & ~0x7FL) == 0) {
- varint64out[idx++] = (UInt8)n;
- break;
- }
- else {
- varint64out[idx++] = (UInt8)((n & 0x7F) | 0x80);
- n >>= 7;
- }
- }
-
- if (![_transport write:varint64out offset:0 length:idx error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport write failed");
- }
-
- return YES;
-}
-
--(UInt32) i32ToZigZag:(SInt32)n
-{
- /*
- ZigZag encoding maps signed integers to unsigned integers so that
- numbers with a small absolute value (for instance, -1) have
- a small varint encoded value too. It does this in a way that
- "zig-zags" back and forth through the positive and negative integers,
- so that -1 is encoded as 1, 1 is encoded as 2, -2 is encoded as 3, and so
- on
- */
- return (UInt32)(n << 1) ^ (UInt32)(n >> 31);
-}
-
--(UInt64) i64ToZigZag:(SInt64)n
-{
- return (UInt64)(n << 1) ^ (UInt64)(n >> 63);
-}
-
--(BOOL) readMessageBeginReturningName:(NSString **)pname
- type:(SInt32 *)ptype
- sequenceID:(SInt32 *)psequenceID
- error:(NSError *__autoreleasing *)error
-{
- UInt8 protocolId;
- if (![self readByte:&protocolId error:error]) {
- return NO;
- }
-
- if (protocolId != COMPACT_PROTOCOL_ID) {
- if (error) {
- *error = [NSError errorWithDomain:TProtocolErrorDomain
- code:TProtocolErrorUnknown
- userInfo:@{TProtocolErrorExtendedErrorKey: @(TProtocolExtendedErrorMismatchedProtocol),
- TProtocolErrorExpectedIdKey: @(COMPACT_PROTOCOL_ID)}];
- }
- return NO;
- }
-
- UInt8 versionAndType;
- if (![self readByte:&versionAndType error:error]) {
- return NO;
- }
-
- UInt8 version = versionAndType & COMPACT_VERSION_MASK;
- if (version != COMPACT_VERSION) {
- if (error) {
- *error = [NSError errorWithDomain:TProtocolErrorDomain
- code:TProtocolErrorBadVersion
- userInfo:@{TProtocolErrorExpectedVersionKey: @(COMPACT_VERSION)}];
- }
- return NO;
- }
-
- int type = (versionAndType >> COMPACT_TYPE_SHIFT_AMOUNT) & COMPACT_TYPE_BITS;
- UInt32 sequenceID;
- if (![self readVarint32:&sequenceID error:error]) {
- return NO;
- }
- NSString *name;
- if (![self readString:&name error:error]) {
- return NO;
- }
-
- if (ptype != NULL) {
- *ptype = type;
- }
- if (psequenceID != NULL) {
- *psequenceID = sequenceID;
- }
- if (pname != NULL) {
- *pname = name;
- }
- return YES;
-}
-
--(BOOL) readStructBeginReturningName:(NSString **)pname error:(NSError *__autoreleasing *)error
-{
- [_lastField addObject:@(_lastFieldId)];
- _lastFieldId = 0;
-
- if (pname != NULL) {
- *pname = @"";
- }
-
- return YES;
-}
-
--(BOOL) readStructEnd:(NSError *__autoreleasing *)error
-{
- _lastFieldId = [_lastField.lastObject shortValue];
- [_lastField removeLastObject];
- return YES;
-}
-
--(BOOL) readFieldBeginReturningName:(NSString **)pname
- type:(SInt32 *)pfieldType
- fieldID:(SInt32 *)pfieldID
- error:(NSError *__autoreleasing *)error
-{
- UInt8 byte;
- if (![self readByte:&byte error:error]) {
- return NO;
- }
-
- UInt8 type = byte & 0x0f;
-
- // if it's a stop, then we can return immediately, as the struct is over.
- if (type == TCType_STOP) {
- if (pname != NULL) {
- *pname = @"";
- }
- if (pfieldType != NULL) {
- *pfieldType = TTypeSTOP;
- }
- if (pfieldID != NULL) {
- *pfieldID = 0;
- }
- return YES;
- }
-
- short fieldId = 0;
-
- // mask off the 4 MSB of the type header. it could contain a field id delta.
- short modifier = (byte & 0xf0) >> 4;
- if (modifier == 0) {
- // not a delta. look ahead for the zigzag varint field id.
- if (![self readI16:&fieldId error:error]) {
- return NO;
- }
- }
- else {
- // has a delta. add the delta to the last Read field id.
- fieldId = _lastFieldId + modifier;
- }
-
- UInt8 fieldType;
- if (![self ttype:&fieldType forCompactType:type error:error]) {
- return NO;
- }
-
- if (pname != NULL) {
- *pname = @"";
- }
- if (pfieldType != NULL) {
- *pfieldType = fieldType;
- }
- if (pfieldID != NULL) {
- *pfieldID = fieldId;
- }
-
- // if this happens to be a boolean field, the value is encoded in the type
- if (type == TCType_BOOLEAN_TRUE ||
- type == TCType_BOOLEAN_FALSE)
- {
- // save the boolean value in a special instance variable.
- _booleanValue = [NSNumber numberWithBool:type == TCType_BOOLEAN_TRUE];
- }
-
- // push the new field onto the field stack so we can keep the deltas going.
- _lastFieldId = fieldId;
-
- return YES;
-}
-
--(BOOL) readMapBeginReturningKeyType:(SInt32 *)pkeyType
- valueType:(SInt32 *)pvalueType
- size:(SInt32 *)psize
- error:(NSError *__autoreleasing *)error
-{
- UInt8 keyAndValueType = 0;
- UInt32 size;
- if (![self readVarint32:&size error:error]) {
- return NO;
- }
- if (size != 0) {
- if (![self readByte:&keyAndValueType error:error]) {
- return NO;
- }
- }
-
- UInt8 keyType;
- if (![self ttype:&keyType forCompactType:keyAndValueType >> 4 error:error]) {
- return NO;
- }
-
- UInt8 valueType;
- if (![self ttype:&valueType forCompactType:keyAndValueType & 0xf error:error]) {
- return NO;
- }
-
- if (pkeyType != NULL) {
- *pkeyType = keyType;
- }
- if (pvalueType != NULL) {
- *pvalueType = valueType;
- }
- if (psize != NULL) {
- *psize = size;
- }
-
- return YES;
-}
-
--(BOOL) readListBeginReturningElementType:(SInt32 *)pelementType
- size:(SInt32 *)psize
- error:(NSError *__autoreleasing *)error
-{
- UInt8 sizeAndType;
- if (![self readByte:&sizeAndType error:error]) {
- return NO;
- }
-
- UInt32 size = (sizeAndType >> 4) & 0x0f;
- if (size == 15) {
- if (![self readVarint32:&size error:error]) {
- return NO;
- }
- }
-
- UInt8 elementType;
- if (![self ttype:&elementType forCompactType:sizeAndType & 0x0f error:error]) {
- return NO;
- }
-
- if (pelementType != NULL) {
- *pelementType = elementType;
- }
- if (psize != NULL) {
- *psize = size;
- }
-
- return YES;
-}
-
--(BOOL) readSetBeginReturningElementType:(SInt32 *)pelementType
- size:(SInt32 *)psize
- error:(NSError *__autoreleasing *)error
-{
- return [self readListBeginReturningElementType:pelementType size:psize error:error];
-}
-
--(BOOL) readBool:(BOOL *)value error:(NSError *__autoreleasing *)error
-{
- if (_booleanValue != nil) {
-
- BOOL result = _booleanValue.boolValue;
- _booleanValue = nil;
-
- *value = result;
- }
- else {
-
- UInt8 result;
- if (![self readByte:&result error:error]) {
- return NO;
- }
-
- *value = result == TCType_BOOLEAN_TRUE;
- }
-
- return YES;
-}
-
--(BOOL) readByte:(UInt8 *)value error:(NSError *__autoreleasing *)error
-{
- if (![_transport readAll:value offset:0 length:1 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
- return YES;
-}
-
--(BOOL) readI16:(SInt16 *)value error:(NSError *__autoreleasing *)error
-{
- UInt32 v;
- if (![self readVarint32:&v error:error]) {
- return NO;
- }
-
- if (value) {
- *value = (SInt16)[self zigZagToi32:v];
- }
-
- return YES;
-}
-
--(BOOL) readI32:(SInt32 *)value error:(NSError *__autoreleasing *)error
-{
- UInt32 v;
- if (![self readVarint32:&v error:error]) {
- return NO;
- }
-
- if (value) {
- *value = [self zigZagToi32:v];
- }
-
- return YES;
-}
-
--(BOOL) readI64:(SInt64 *)value error:(NSError *__autoreleasing *)error
-{
- UInt64 v;
- if (![self readVarint64:&v error:error]) {
- return NO;
- }
-
- if (value) {
- *value = [self zigZagToi64:v];
- }
-
- return YES;
-}
-
--(BOOL) readDouble:(double *)value error:(NSError *__autoreleasing *)error
-{
- UInt64 bits;
- if (![_transport readAll:(UInt8 *)&bits offset:0 length:8 error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- bits = OSSwapLittleToHostInt64(bits);
-
- if (value) {
- memcpy(value, &bits, sizeof(bits));
- }
-
- return YES;
-}
-
--(BOOL) readString:(NSString *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- UInt32 length;
- if (![self readVarint32:&length error:error]) {
- return NO;
- }
-
- NSString *result;
-
- if (length != 0) {
-
- NSData *data;
- if (![self readBinaryOfLength:length data:&data error:error]) {
- return NO;
- }
-
- result = [[NSString alloc] initWithData:data
- encoding:NSUTF8StringEncoding];
- }
- else {
- result = @"";
- }
-
- if (value) {
- *value = result;
- }
-
- return YES;
-}
-
--(BOOL) readBinary:(NSData *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- UInt32 length;
- if (![self readVarint32:&length error:error]) {
- return NO;
- }
-
- return [self readBinaryOfLength:length data:value error:error];
-}
-
--(BOOL) readBinaryOfLength:(UInt32)length data:(NSData *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- NSData *result;
-
- if (length != 0) {
-
- NSMutableData *buf = [NSMutableData dataWithLength:length];
- if (![_transport readAll:buf.mutableBytes offset:0 length:length error:error]) {
- PROTOCOL_TRANSPORT_ERROR(NO, error, @"Transport read failed");
- }
-
- result = buf;
- }
- else {
-
- result = [NSData data];
-
- }
-
- if (value) {
- *value = result;
- }
-
- return YES;
-}
-
--(BOOL) readMessageEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
--(BOOL) readFieldEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
--(BOOL) readMapEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
--(BOOL) readListEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
--(BOOL) readSetEnd:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(BOOL) readVarint32:(UInt32 *)value error:(NSError *__autoreleasing *)error
-{
- UInt32 result = 0;
- int shift = 0;
-
- while (true) {
-
- UInt8 byte;
- if (![self readByte:&byte error:error]) {
- return NO;
- }
-
- result |= (UInt32)(byte & 0x7f) << shift;
- if (!(byte & 0x80)) {
- break;
- }
-
- shift += 7;
- }
-
- if (value) {
- *value = result;
- }
-
- return YES;
-}
-
--(BOOL) readVarint64:(UInt64 *)value error:(NSError *__autoreleasing *)error
-{
- int shift = 0;
- UInt64 result = 0;
-
- while (true) {
-
- UInt8 byte;
- if (![self readByte:&byte error:error]) {
- return NO;
- }
-
- result |= (UInt64)(byte & 0x7f) << shift;
- if (!(byte & 0x80)) {
- break;
- }
-
- shift += 7;
- }
-
- if (value) {
- *value = result;
- }
-
- return YES;
-}
-
--(SInt32) zigZagToi32:(UInt32)n
-{
- return (SInt32)(n >> 1) ^ (-(SInt32)(n & 1));
-}
-
--(SInt64) zigZagToi64:(UInt64)n
-{
- return (SInt64)(n >> 1) ^ (-(SInt64)(n & 1));
-}
-
--(BOOL) ttype:(UInt8 *)ttype forCompactType:(UInt8)ctype error:(NSError *__autoreleasing *)error
-{
- switch (ctype & 0x0f) {
- case TCType_STOP:
- *ttype = TTypeSTOP;
- return YES;
-
- case TCType_BOOLEAN_FALSE:
- case TCType_BOOLEAN_TRUE:
- *ttype = TTypeBOOL;
- return YES;
-
- case TCType_BYTE:
- *ttype = TTypeBYTE;
- return YES;
-
- case TCType_I16:
- *ttype = TTypeI16;
- return YES;
-
- case TCType_I32:
- *ttype = TTypeI32;
- return YES;
-
- case TCType_I64:
- *ttype = TTypeI64;
- return YES;
-
- case TCType_DOUBLE:
- *ttype = TTypeDOUBLE;
- return YES;
-
- case TCType_BINARY:
- *ttype = TTypeSTRING;
- return YES;
-
- case TCType_LIST:
- *ttype = TTypeLIST;
- return YES;
-
- case TCType_SET:
- *ttype = TTypeSET;
- return YES;
-
- case TCType_MAP:
- *ttype = TTypeMAP;
- return YES;
-
- case TCType_STRUCT:
- *ttype = TTypeSTRUCT;
- return YES;
-
- default:
- if (error) {
- *error = [NSError errorWithDomain:TProtocolErrorDomain
- code:TProtocolErrorUnknown
- userInfo:@{TProtocolErrorTypeKey: @((UInt8)(ctype & 0x0F))}];
- }
- return NO;
- }
-}
-
--(UInt8) compactTypeForTType:(UInt8)ttype
-{
- static UInt8 ttypeToCompactType[] = {
- [TTypeSTOP] = TCType_STOP,
- [TTypeBOOL] = TCType_BOOLEAN_FALSE,
- [TTypeBYTE] = TCType_BYTE,
- [TTypeDOUBLE] = TCType_DOUBLE,
- [TTypeI16] = TCType_I16,
- [TTypeI32] = TCType_I32,
- [TTypeI64] = TCType_I64,
- [TTypeSTRING] = TCType_BINARY,
- [TTypeSTRUCT] = TCType_STRUCT,
- [TTypeMAP] = TCType_MAP,
- [TTypeSET] = TCType_SET,
- [TTypeLIST] = TCType_LIST
- };
-
- return ttypeToCompactType[ttype];
-}
-
-@end
diff --git a/lib/cocoa/src/protocol/TMultiplexedProtocol.h b/lib/cocoa/src/protocol/TMultiplexedProtocol.h
deleted file mode 100644
index b8ce361f5..000000000
--- a/lib/cocoa/src/protocol/TMultiplexedProtocol.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-#import "TProtocolDecorator.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-extern NSString *TMultiplexedProtocolSeperator;
-
-
-@interface TMultiplexedProtocol : TProtocolDecorator
-
--(id) initWithProtocol:(id <TProtocol>)protocol
- serviceName:(NSString *)name;
-
-@end
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/protocol/TMultiplexedProtocol.m b/lib/cocoa/src/protocol/TMultiplexedProtocol.m
deleted file mode 100644
index 5838c576b..000000000
--- a/lib/cocoa/src/protocol/TMultiplexedProtocol.m
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TMultiplexedProtocol.h"
-
-#import "TProtocol.h"
-
-NSString *TMultiplexedProtocolSeperator = @":";
-
-
-@interface TMultiplexedProtocol ()
-
-@property(strong, nonatomic) NSString *serviceName;
-
-@end
-
-
-@implementation TMultiplexedProtocol
-
--(id) initWithProtocol:(id <TProtocol>)protocol
- serviceName:(NSString *)name
-{
- self = [super initWithProtocol:protocol];
- if (self) {
- _serviceName = name;
- }
- return self;
-}
-
--(BOOL) writeMessageBeginWithName:(NSString *)name
- type:(SInt32)messageType
- sequenceID:(SInt32)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- switch (messageType) {
- case TMessageTypeCALL:
- case TMessageTypeONEWAY: {
- NSMutableString *serviceFunction = [[NSMutableString alloc] initWithString:_serviceName];
- [serviceFunction appendString:TMultiplexedProtocolSeperator];
- [serviceFunction appendString:name];
- return [super writeMessageBeginWithName:serviceFunction type:messageType sequenceID:sequenceID error:error];
- }
- break;
-
- default:
- return [super writeMessageBeginWithName:name type:messageType sequenceID:sequenceID error:error];
- }
-}
-
-@end
diff --git a/lib/cocoa/src/protocol/TProtocol.h b/lib/cocoa/src/protocol/TProtocol.h
deleted file mode 100644
index 841059f51..000000000
--- a/lib/cocoa/src/protocol/TProtocol.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-#import "TTransport.h"
-
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-typedef NS_ENUM (int, TMessageType) {
- TMessageTypeCALL = 1,
- TMessageTypeREPLY = 2,
- TMessageTypeEXCEPTION = 3,
- TMessageTypeONEWAY = 4
-};
-
-typedef NS_ENUM (int, TType) {
- TTypeSTOP = 0,
- TTypeVOID = 1,
- TTypeBOOL = 2,
- TTypeBYTE = 3,
- TTypeDOUBLE = 4,
- TTypeI16 = 6,
- TTypeI32 = 8,
- TTypeI64 = 10,
- TTypeSTRING = 11,
- TTypeSTRUCT = 12,
- TTypeMAP = 13,
- TTypeSET = 14,
- TTypeLIST = 15
-};
-
-
-@protocol TProtocol <NSObject>
-
--(id <TTransport>) transport;
-
--(BOOL) readMessageBeginReturningName:(NSString *__nullable __autoreleasing *__nullable)name
- type:(nullable SInt32 *)type
- sequenceID:(nullable SInt32 *)sequenceID
- error:(NSError *__autoreleasing *)error;
--(BOOL) readMessageEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) readStructBeginReturningName:(NSString *__nullable __autoreleasing *__nullable)name
- error:(NSError *__autoreleasing *)error;
--(BOOL) readStructEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) readFieldBeginReturningName:(NSString *__nullable __autoreleasing *__nullable)name
- type:(SInt32 *)fieldType
- fieldID:(nullable SInt32 *)fieldID
- error:(NSError *__autoreleasing *)error;
--(BOOL) readFieldEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) readString:(NSString *__nonnull __autoreleasing *__nonnull)value error:(NSError **)error;
-
--(BOOL) readBool:(BOOL *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readByte:(UInt8 *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readI16:(SInt16 *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readI32:(SInt32 *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readI64:(SInt64 *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readDouble:(double *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) readBinary:(NSData *__nonnull __autoreleasing *__nonnull)value error:(NSError **)error;
-
--(BOOL) readMapBeginReturningKeyType:(nullable SInt32 *)keyType
- valueType:(nullable SInt32 *)valueType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error;
--(BOOL) readMapEnd:(NSError *__autoreleasing *)error;
-
-
--(BOOL) readSetBeginReturningElementType:(nullable SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error;
--(BOOL) readSetEnd:(NSError *__autoreleasing *)error;
-
-
--(BOOL) readListBeginReturningElementType:(nullable SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error;
--(BOOL) readListEnd:(NSError *__autoreleasing *)error;
-
-
--(BOOL) writeMessageBeginWithName:(NSString *)name
- type:(SInt32)messageType
- sequenceID:(SInt32)sequenceID
- error:(NSError *__autoreleasing *)error;
--(BOOL) writeMessageEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) writeStructBeginWithName:(NSString *)name error:(NSError **)error;
--(BOOL) writeStructEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) writeFieldBeginWithName:(NSString *)name
- type:(SInt32)fieldType
- fieldID:(SInt32)fieldID
- error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeI32:(SInt32)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeI64:(SInt64)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeI16:(short)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeByte:(UInt8)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeString:(NSString *)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeDouble:(double)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeBool:(BOOL)value error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeBinary:(NSData *)data error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeFieldStop:(NSError *__autoreleasing *)error;
-
--(BOOL) writeFieldEnd:(NSError *__autoreleasing *)error;
-
--(BOOL) writeMapBeginWithKeyType:(SInt32)keyType
- valueType:(SInt32)valueType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error;
--(BOOL) writeMapEnd:(NSError *__autoreleasing *)error;
-
-
--(BOOL) writeSetBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error;
--(BOOL) writeSetEnd:(NSError *__autoreleasing *)error;
-
-
--(BOOL) writeListBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error;
-
--(BOOL) writeListEnd:(NSError *__autoreleasing *)error;
-
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/protocol/TProtocolDecorator.h b/lib/cocoa/src/protocol/TProtocolDecorator.h
deleted file mode 100644
index 369b6a233..000000000
--- a/lib/cocoa/src/protocol/TProtocolDecorator.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-#import "TProtocol.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TProtocolDecorator : NSObject <TProtocol>
-
--(id) initWithProtocol:(id <TProtocol>)protocol;
-
-@end
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/protocol/TProtocolDecorator.m b/lib/cocoa/src/protocol/TProtocolDecorator.m
deleted file mode 100644
index 218f900c4..000000000
--- a/lib/cocoa/src/protocol/TProtocolDecorator.m
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocolDecorator.h"
-
-
-@interface TProtocolDecorator ()
-
-@property(strong, nonatomic) id<TProtocol> concreteProtocol;
-
-@end
-
-
-@implementation TProtocolDecorator
-
--(id) initWithProtocol:(id <TProtocol>)protocol
-{
- self = [super init];
- if (self) {
- _concreteProtocol = protocol;
- }
- return self;
-}
-
--(id <TTransport>) transport
-{
- return [_concreteProtocol transport];
-}
-
--(BOOL) readMessageBeginReturningName:(NSString **)name
- type:(SInt32 *)type
- sequenceID:(SInt32 *)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readMessageBeginReturningName:name
- type:type
- sequenceID:sequenceID
- error:error];
-}
-
--(BOOL) readMessageEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readMessageEnd:error];
-}
-
--(BOOL) readStructBeginReturningName:(NSString **)name
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readStructBeginReturningName:name error:error];
-}
-
--(BOOL) readStructEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readStructEnd:error];
-}
-
--(BOOL) readFieldBeginReturningName:(NSString **)name
- type:(SInt32 *)fieldType
- fieldID:(SInt32 *)fieldID
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readFieldBeginReturningName:name
- type:fieldType
- fieldID:fieldID
- error:error];
-}
--(BOOL) readFieldEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readFieldEnd:error];
-}
-
--(BOOL) readString:(NSString *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readString:value error:error];
-}
-
--(BOOL) readBool:(BOOL *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readBool:value error:error];
-}
-
--(BOOL) readByte:(UInt8 *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readByte:value error:error];
-}
-
--(BOOL) readI16:(SInt16 *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readI16:value error:error];
-}
-
--(BOOL) readI32:(SInt32 *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readI32:value error:error];
-}
-
--(BOOL) readI64:(SInt64 *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readI64:value error:error];
-}
-
--(BOOL) readDouble:(double *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readDouble:value error:error];
-}
-
--(BOOL) readBinary:(NSData *__autoreleasing *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readBinary:value error:error];
-}
-
--(BOOL) readMapBeginReturningKeyType:(SInt32 *)keyType
- valueType:(SInt32 *)valueType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readMapBeginReturningKeyType:keyType
- valueType:valueType
- size:size
- error:error];
-}
--(BOOL) readMapEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readMapEnd:error];
-}
-
-
--(BOOL) readSetBeginReturningElementType:(SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readSetBeginReturningElementType:elementType
- size:size
- error:error];
-}
--(BOOL) readSetEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readSetEnd:error];
-}
-
--(BOOL) readListBeginReturningElementType:(SInt32 *)elementType
- size:(SInt32 *)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readListBeginReturningElementType:elementType
- size:size
- error:error];
-}
--(BOOL) readListEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol readListEnd:error];
-}
-
--(BOOL) writeMessageBeginWithName:(NSString *)name
- type:(SInt32)messageType
- sequenceID:(SInt32)sequenceID
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeMessageBeginWithName:name
- type:messageType
- sequenceID:sequenceID
- error:error];
-}
--(BOOL) writeMessageEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeMessageEnd:error];
-}
-
--(BOOL) writeStructBeginWithName:(NSString *)name error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeStructBeginWithName:name error:error];
-}
--(BOOL) writeStructEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeStructEnd:error];
-}
-
--(BOOL) writeFieldBeginWithName:(NSString *)name
- type:(SInt32)fieldType
- fieldID:(SInt32)fieldID
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeFieldBeginWithName:name
- type:fieldType
- fieldID:fieldID
- error:error];
-}
-
--(BOOL) writeI32:(SInt32)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeI32:value error:error];
-}
-
--(BOOL) writeI64:(SInt64)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeI64:value error:error];
-}
-
--(BOOL) writeI16:(SInt16)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeI16:value error:error];
-}
-
--(BOOL) writeByte:(UInt8)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeByte:value error:error];
-}
-
--(BOOL) writeString:(NSString *)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeString:value error:error];
-}
-
--(BOOL) writeDouble:(double)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeDouble:value error:error];
-}
-
--(BOOL) writeBool:(BOOL)value error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeBool:value error:error];
-}
-
--(BOOL) writeBinary:(NSData *)data error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeBinary:data error:error];
-}
-
--(BOOL) writeFieldStop:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeFieldStop:error];
-}
-
--(BOOL) writeFieldEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeFieldEnd:error];
-}
-
--(BOOL) writeMapBeginWithKeyType:(SInt32)keyType
- valueType:(SInt32)valueType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeMapBeginWithKeyType:keyType
- valueType:valueType
- size:size
- error:error];
-}
-
--(BOOL) writeMapEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeMapEnd:error];
-}
-
--(BOOL) writeSetBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeSetBeginWithElementType:elementType size:size error:error];
-}
-
--(BOOL) writeSetEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeSetEnd:error];
-}
-
--(BOOL) writeListBeginWithElementType:(SInt32)elementType
- size:(SInt32)size
- error:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeListBeginWithElementType:elementType size:size error:error];
-}
-
--(BOOL) writeListEnd:(NSError *__autoreleasing *)error
-{
- return [_concreteProtocol writeListEnd:error];
-}
-
-@end
diff --git a/lib/cocoa/src/protocol/TProtocolError.h b/lib/cocoa/src/protocol/TProtocolError.h
deleted file mode 100644
index ab0bc40da..000000000
--- a/lib/cocoa/src/protocol/TProtocolError.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TError.h"
-
-
-extern NSString *TProtocolErrorDomain;
-
-typedef NS_ENUM (int, TProtocolError) {
- TProtocolErrorUnknown = 0,
- TProtocolErrorInvalidData = 1,
- TProtocolErrorNegativeSize = 2,
- TProtocolErrorSizeLimit = 3,
- TProtocolErrorBadVersion = 4,
- TProtocolErrorNotImplemented = 5,
- TProtocolErrorDepthLimit = 6,
-};
-
-
-typedef NS_ENUM(int, TProtocolExtendedError) {
- TProtocolExtendedErrorMissingRequiredField = 1001,
- TProtocolExtendedErrorUnexpectedType = 1002,
- TProtocolExtendedErrorMismatchedProtocol = 1003,
-};
-
-extern NSString *TProtocolErrorExtendedErrorKey;
-extern NSString *TProtocolErrorFieldNameKey;
-extern NSString *TProtocolErrorExpectedIdKey;
-extern NSString *TProtocolErrorExpectedVersionKey;
-extern NSString *TProtocolErrorTypeKey;
-extern NSString *TProtocolErrorSourceLineKey;
-extern NSString *TProtocolErrorSourceFileKey;
-extern NSString *TProtocolErrorSourceMethodKey;
-extern NSString *TProtocolErrorMessageNameKey;
-
-
-#define PROTOCOL_ERROR(ret, err, ...) \
- if (error) { \
- *error = [NSError errorWithDomain:TProtocolErrorDomain \
- code:TProtocolError ## err \
- userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:__VA_ARGS__], \
- @"SourceFile": [NSString stringWithUTF8String:__FILE__], \
- @"SourceLine": @(__LINE__), \
- @"SourceFunction": [NSString stringWithUTF8String:__PRETTY_FUNCTION__], \
- @"Message": self.currentMessageName ? self.currentMessageName : @""}]; \
- } \
- return ret
-
-#define PROTOCOL_TRANSPORT_ERROR(ret, errorPtr, ...) \
- if (errorPtr) { \
- *error = [NSError errorWithDomain:TProtocolErrorDomain \
- code:TProtocolErrorUnknown \
- userInfo:@{NSLocalizedDescriptionKey: [[NSString stringWithFormat:__VA_ARGS__] stringByAppendingFormat:@": %@", [(*errorPtr) localizedDescription]], \
- TProtocolErrorSourceFileKey: [NSString stringWithUTF8String:__FILE__], \
- TProtocolErrorSourceLineKey: @(__LINE__), \
- TProtocolErrorSourceMethodKey: [NSString stringWithUTF8String:__PRETTY_FUNCTION__], \
- TProtocolErrorMessageNameKey: self.currentMessageName ? self.currentMessageName : @"", \
- NSUnderlyingErrorKey: *errorPtr}]; \
- } \
- return ret
diff --git a/lib/cocoa/src/protocol/TProtocolError.m b/lib/cocoa/src/protocol/TProtocolError.m
deleted file mode 100644
index 953673b0a..000000000
--- a/lib/cocoa/src/protocol/TProtocolError.m
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocolError.h"
-
-
-NSString *TProtocolErrorDomain = @"TProtocolErrorDomain";
-
-NSString *TProtocolErrorExtendedErrorKey = @"extendedError";
-NSString *TProtocolErrorFieldNameKey = @"field";
-NSString *TProtocolErrorExpectedIdKey = @"expectedId";
-NSString *TProtocolErrorExpectedVersionKey = @"expectedVersion";
-NSString *TProtocolErrorTypeKey = @"type";
-NSString *TProtocolErrorSourceLineKey = @"sourceLine";
-NSString *TProtocolErrorSourceFileKey = @"sourceFile";
-NSString *TProtocolErrorSourceMethodKey = @"sourceMethod";
-NSString *TProtocolErrorMessageNameKey = @"messageName";
diff --git a/lib/cocoa/src/protocol/TProtocolFactory.h b/lib/cocoa/src/protocol/TProtocolFactory.h
deleted file mode 100644
index a022a7f9f..000000000
--- a/lib/cocoa/src/protocol/TProtocolFactory.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TProtocol.h"
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@protocol TProtocolFactory <NSObject>
-
-@property (readonly, nonatomic) NSString *protocolName;
-
--(id<TProtocol>) newProtocolOnTransport:(id<TTransport>)transport;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/protocol/TProtocolUtil.h b/lib/cocoa/src/protocol/TProtocolUtil.h
deleted file mode 100644
index 82510cfca..000000000
--- a/lib/cocoa/src/protocol/TProtocolUtil.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocol.h"
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TProtocolUtil : NSObject
-
-+(BOOL) skipType:(int)type onProtocol:(id <TProtocol>)protocol error:(NSError **)error;
-
-@end;
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/protocol/TProtocolUtil.m b/lib/cocoa/src/protocol/TProtocolUtil.m
deleted file mode 100644
index c0d65acea..000000000
--- a/lib/cocoa/src/protocol/TProtocolUtil.m
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TProtocolUtil.h"
-
-@implementation TProtocolUtil
-
-+(BOOL) skipType:(int)type onProtocol:(id <TProtocol>)protocol error:(NSError **)error
-{
- switch (type) {
- case TTypeBOOL: {
- BOOL val;
- if (![protocol readBool:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeBYTE: {
- UInt8 val;
- if (![protocol readByte:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeI16: {
- SInt16 val;
- if (![protocol readI16:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeI32: {
- SInt32 val;
- if (![protocol readI32:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeI64: {
- SInt64 val;
- if (![protocol readI64:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeDOUBLE: {
- double val;
- if (![protocol readDouble:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeSTRING: {
- NSString *val;
- if (![protocol readString:&val error:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeSTRUCT: {
- if (![protocol readStructBeginReturningName:NULL error:error]) {
- return NO;
- }
- while (true) {
- SInt32 fieldType;
- if (![protocol readFieldBeginReturningName:nil type:&fieldType fieldID:nil error:error]) {
- return NO;
- }
- if (fieldType == TTypeSTOP) {
- break;
- }
- if (![self skipType:fieldType onProtocol:protocol error:error]) {
- return NO;
- }
- if (![protocol readFieldEnd:error]) {
- return NO;
- }
- }
- if (![protocol readStructEnd:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeMAP: {
- SInt32 keyType;
- SInt32 valueType;
- SInt32 size;
- if (![protocol readMapBeginReturningKeyType:&keyType valueType:&valueType size:&size error:error]) {
- return NO;
- }
- int i;
- for (i = 0; i < size; i++) {
- if (![TProtocolUtil skipType:keyType onProtocol:protocol error:error]) {
- return NO;
- }
- if (![TProtocolUtil skipType:valueType onProtocol:protocol error:error]) {
- return NO;
- }
- }
- if (![protocol readMapEnd:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeSET: {
- SInt32 elemType;
- SInt32 size;
- if (![protocol readSetBeginReturningElementType:&elemType size:&size error:error]) {
- return NO;
- }
- int i;
- for (i = 0; i < size; i++) {
- if (![TProtocolUtil skipType:elemType onProtocol:protocol error:error]) {
- return NO;
- }
- }
- if (![protocol readSetEnd:error]) {
- return NO;
- }
- }
- break;
-
- case TTypeLIST: {
- SInt32 elemType;
- SInt32 size;
- if (![protocol readListBeginReturningElementType:&elemType size:&size error:error]) {
- return NO;
- }
- int i;
- for (i = 0; i < size; i++) {
- if (![TProtocolUtil skipType:elemType onProtocol:protocol error:error]) {
- return NO;
- }
- }
- if (![protocol readListEnd:error]) {
- return NO;
- }
- }
- break;
-
- }
-
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/server/TSocketServer.h b/lib/cocoa/src/server/TSocketServer.h
deleted file mode 100644
index 95b0d3c19..000000000
--- a/lib/cocoa/src/server/TSocketServer.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TProtocolFactory.h"
-#import "TProcessorFactory.h"
-
-#if !TARGET_OS_IPHONE
-#import <CoreServices/CoreServices.h>
-#else
-#import <CFNetwork/CFNetwork.h>
-#endif
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-extern NSString *const TSocketServerClientConnectionFinished;
-extern NSString *const TSocketServerProcessorKey;
-extern NSString *const TSockerServerTransportKey;
-
-
-@interface TSocketServer : NSObject
-
--(instancetype) initWithPort:(int)port
- protocolFactory:(id <TProtocolFactory>)protocolFactory
- processorFactory:(id <TProcessorFactory>)processorFactory;
-
-- (instancetype) initWithPath: (NSString *) path
- protocolFactory: (id <TProtocolFactory>) protocolFactory
- processorFactory: (id <TProcessorFactory>) processorFactory;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/server/TSocketServer.m b/lib/cocoa/src/server/TSocketServer.m
deleted file mode 100644
index 09b603cf4..000000000
--- a/lib/cocoa/src/server/TSocketServer.m
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TSocketServer.h"
-#import "TNSFileHandleTransport.h"
-#import "TProtocol.h"
-#import "TTransportError.h"
-
-#import <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-
-
-NSString *const TSocketServerClientConnectionFinished = @"TSocketServerClientConnectionFinished";
-NSString *const TSocketServerProcessorKey = @"TSocketServerProcessor";
-NSString *const TSockerServerTransportKey = @"TSockerServerTransport";
-
-
-@interface TSocketServer ()
-
-@property(strong, nonatomic) id<TProtocolFactory> inputProtocolFactory;
-@property(strong, nonatomic) id<TProtocolFactory> outputProtocolFactory;
-@property(strong, nonatomic) id<TProcessorFactory> processorFactory;
-@property(strong, nonatomic) NSFileHandle *socketFileHandle;
-@property(strong, nonatomic) dispatch_queue_t processingQueue;
-@property(strong, nonatomic) NSString *domainSocketPath;
-
-@end
-
-
-@implementation TSocketServer
-
--(instancetype) initWithSocket:(CFSocketRef)socket
- protocolFactory:(id <TProtocolFactory>)protocolFactory
- processorFactory:(id <TProcessorFactory>)processorFactory;
-{
- self = [super init];
-
- _inputProtocolFactory = protocolFactory;
- _outputProtocolFactory = protocolFactory;
- _processorFactory = processorFactory;
-
- dispatch_queue_attr_t processingQueueAttr =
- dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_BACKGROUND, 0);
-
- _processingQueue = dispatch_queue_create("TSocketServer.processing", processingQueueAttr);
-
- // create a socket.
- int fd = CFSocketGetNative(socket);
-
- // wrap it in a file handle so we can get messages from it
- _socketFileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
- closeOnDealloc:YES];
-
- // throw away our socket
- CFSocketInvalidate(socket);
- CFRelease(socket);
-
- // register for notifications of accepted incoming connections
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(connectionAccepted:)
- name:NSFileHandleConnectionAcceptedNotification
- object:_socketFileHandle];
-
- // tell socket to listen
- [_socketFileHandle acceptConnectionInBackgroundAndNotify];
-
- return self;
-}
-
-- (id) initWithPort: (int) port
- protocolFactory: (id <TProtocolFactory>) protocolFactory
- processorFactory: (id <TProcessorFactory>) processorFactory
-{
- CFSocketRef socket = [[self class] createSocketWithPort:port];
- if (socket == NULL) {
- return nil;
- }
-
- if (self = [self initWithSocket:socket protocolFactory:protocolFactory processorFactory:processorFactory]) {
- NSLog(@"TSocketServer: Listening on TCP port %d", port);
- }
- return self;
-}
-
-
-+(CFSocketRef) createSocketWithPort:(int)port
-{
- CFSocketRef socket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL);
- if (socket) {
- CFSocketSetSocketFlags(socket, CFSocketGetSocketFlags(socket) & ~kCFSocketCloseOnInvalidate);
- int fd = CFSocketGetNative(socket);
- int yes = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
-
- struct sockaddr_in addr;
- memset(&addr, 0, sizeof(addr));
- addr.sin_len = sizeof(addr);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];
- if (CFSocketSetAddress(socket, (__bridge CFDataRef)address) != kCFSocketSuccess) {
- CFSocketInvalidate(socket);
- CFRelease(socket);
- NSLog(@"TSocketServer: Could not bind to address");
- return NULL;
- }
-
- return socket;
- }
- else {
- NSLog(@"TSocketServer: No server socket");
- return NULL;
- }
-}
-
-- (id) initWithPath: (NSString *) path
- protocolFactory: (id <TProtocolFactory>) protocolFactory
- processorFactory: (id <TProcessorFactory>) processorFactory
-{
- _domainSocketPath = path;
- CFSocketRef socket = [[self class] createSocketWithPath:path];
- if (socket == NULL) {
- return nil;
- }
-
- if (self = [self initWithSocket:socket protocolFactory:protocolFactory processorFactory:processorFactory]) {
- NSLog(@"TSocketServer: Listening on path %@", path);
- }
- return self;
-}
-
-+ (CFSocketRef) createSocketWithPath: (NSString *) path
-{
- CFSocketRef socket = CFSocketCreate(kCFAllocatorDefault, PF_LOCAL, SOCK_STREAM, IPPROTO_IP, 0, NULL, NULL);
- if (socket) {
- CFSocketSetSocketFlags(socket, CFSocketGetSocketFlags(socket) & ~kCFSocketCloseOnInvalidate);
- int fd = CFSocketGetNative(socket);
- int yes = 1;
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes));
-
- size_t nullTerminatedPathLength = path.length + 1;
- struct sockaddr_un addr;
- if (nullTerminatedPathLength> sizeof(addr.sun_path)) {
- NSLog(@"TSocketServer: Unable to create socket at path %@. Path is too long.", path);
- return NULL;
- }
-
- addr.sun_family = AF_LOCAL;
- memcpy(addr.sun_path, path.UTF8String, nullTerminatedPathLength);
- addr.sun_len = SUN_LEN(&addr);
-
- NSData *address = [NSData dataWithBytes:&addr length:sizeof(addr)];
- if (CFSocketSetAddress(socket, (__bridge CFDataRef)address) != kCFSocketSuccess) {
- CFSocketInvalidate(socket);
- CFRelease(socket);
- NSLog(@"TSocketServer: Could not bind to address");
- return NULL;
- }
-
- return socket;
- } else {
- NSLog(@"TSocketServer: No server socket");
- return NULL;
- }
-}
-
--(void) dealloc
-{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- if (_domainSocketPath != nil) {
- unlink(_domainSocketPath.UTF8String);
- }
-}
-
-
--(void) connectionAccepted:(NSNotification *)notification
-{
- NSFileHandle *socket = [notification.userInfo objectForKey:NSFileHandleNotificationFileHandleItem];
-
- // Now that we have a client connected, handle request on queue
- dispatch_async(_processingQueue, ^{
-
- [self handleClientConnection:socket];
-
- });
-
- // Continue accepting connections
- [_socketFileHandle acceptConnectionInBackgroundAndNotify];
-}
-
-
--(void) handleClientConnection:(NSFileHandle *)clientSocket
-{
- @autoreleasepool {
-
- TNSFileHandleTransport *transport = [[TNSFileHandleTransport alloc] initWithFileHandle:clientSocket];
- id<TProcessor> processor = [_processorFactory processorForTransport:transport];
-
- id <TProtocol> inProtocol = [_inputProtocolFactory newProtocolOnTransport:transport];
- id <TProtocol> outProtocol = [_outputProtocolFactory newProtocolOnTransport:transport];
-
- NSError *error;
- if (![processor processOnInputProtocol:inProtocol outputProtocol:outProtocol error:&error]) {
- // Handle error
- NSLog(@"Error processing request: %@", error);
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [NSNotificationCenter.defaultCenter postNotificationName:TSocketServerClientConnectionFinished
- object:self
- userInfo:@{TSocketServerProcessorKey: processor,
- TSockerServerTransportKey: transport}];
- });
-
- }
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TAsyncTransport.h b/lib/cocoa/src/transport/TAsyncTransport.h
deleted file mode 100644
index bab4fbdcd..000000000
--- a/lib/cocoa/src/transport/TAsyncTransport.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@protocol TAsyncTransport;
-
-
-@protocol TAsyncTransportFactory <NSObject>
-
--(id<TAsyncTransport>) newTransport;
-
-@end
-
-
-typedef void (^TAsyncCompletionBlock)();
-typedef void (^TAsyncFailureBlock)(NSError * __nonnull);
-
-
-@protocol TAsyncTransport <TTransport>
-
--(void) flushWithCompletion:(TAsyncCompletionBlock)completed failure:(TAsyncFailureBlock)failure;
-
-@end
-
-
-NS_ASSUME_NONNULL_END \ No newline at end of file
diff --git a/lib/cocoa/src/transport/TFramedTransport.h b/lib/cocoa/src/transport/TFramedTransport.h
deleted file mode 100644
index ea68ac44d..000000000
--- a/lib/cocoa/src/transport/TFramedTransport.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TFramedTransport : NSObject <TTransport>
-
--(id) initWithTransport:(id <TTransport>)transport;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TFramedTransport.m b/lib/cocoa/src/transport/TFramedTransport.m
deleted file mode 100644
index 4db65c41c..000000000
--- a/lib/cocoa/src/transport/TFramedTransport.m
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TFramedTransport.h"
-#import "TTransportError.h"
-
-#define HEADER_SIZE 4
-#define INIT_FRAME_SIZE 1024
-
-
-@interface TFramedTransport ()
-
-@property(strong, nonatomic) id<TTransport> transport;
-@property(strong, nonatomic) NSMutableData *writeBuffer;
-@property(strong, nonatomic) NSMutableData *readBuffer;
-@property(assign, nonatomic) NSUInteger readOffset;
-
-@end
-
-
-@implementation TFramedTransport
-
--(id) initWithTransport:(id <TTransport>)aTransport
-{
- if ((self = [self init])) {
- _transport = aTransport;
- _readBuffer = nil;
- _readOffset = 0;
- _writeBuffer = [NSMutableData dataWithLength:HEADER_SIZE];
- }
- return self;
-}
-
--(BOOL) flush:(NSError **)error
-{
- int len = (int)[_writeBuffer length];
- int data_len = len - HEADER_SIZE;
- if (data_len < 0) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{}];
- }
- return NO;
- }
-
- UInt8 i32rd[HEADER_SIZE];
- i32rd[0] = (UInt8)(0xff & (data_len >> 24));
- i32rd[1] = (UInt8)(0xff & (data_len >> 16));
- i32rd[2] = (UInt8)(0xff & (data_len >> 8));
- i32rd[3] = (UInt8)(0xff & (data_len));
-
- // should we make a copy of the writeBuffer instead? Better for threaded
- // operations!
- [_writeBuffer replaceBytesInRange:NSMakeRange(0, HEADER_SIZE)
- withBytes:i32rd length:HEADER_SIZE];
-
- if (![_transport write:_writeBuffer.mutableBytes offset:0 length:len error:error]) {
- return NO;
- }
-
- if (![_transport flush:error]) {
- return NO;
- }
-
- _writeBuffer.length = HEADER_SIZE;
-
- return YES;
-}
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- [_writeBuffer appendBytes:data+offset length:length];
-
- return YES;
-}
-
--(BOOL) readAll:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = [self readAvail:outBuffer offset:outBufferOffset maxLength:length error:error];
- if (got != length) {
-
- // Report underflow only if readAvail didn't report error already
- if (error && !*error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:nil];
- }
-
- return NO;
- }
-
- return YES;
-}
-
--(UInt32) readAvail:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset maxLength:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- while (got < length) {
-
- NSUInteger avail = _readBuffer.length - _readOffset;
- if (avail == 0) {
- if (![self readFrame:error]) {
- return 0;
- }
- avail = _readBuffer.length;
- }
-
- NSRange range;
- range.location = _readOffset;
- range.length = MIN(length - got, avail);
-
- [_readBuffer getBytes:outBuffer+outBufferOffset+got range:range];
- _readOffset += range.length;
- got += range.length;
- }
-
- return got;
-}
-
--(BOOL) readFrame:(NSError **)error
-{
- UInt8 i32rd[HEADER_SIZE];
- if (![_transport readAll:i32rd offset:0 length:HEADER_SIZE error:error]) {
- return NO;
- }
-
- SInt32 size =
- ((i32rd[0] & 0xff) << 24) |
- ((i32rd[1] & 0xff) << 16) |
- ((i32rd[2] & 0xff) << 8) |
- ((i32rd[3] & 0xff));
-
- if (_readBuffer == nil) {
-
- _readBuffer = [NSMutableData dataWithLength:size];
-
- }
- else {
-
- SInt32 len = (SInt32)_readBuffer.length;
- if (len >= size) {
-
- _readBuffer.length = size;
-
- }
- else {
-
- // increase length of data buffer
- [_readBuffer increaseLengthBy:size-len];
-
- }
-
- }
-
- // copy into internal memory buffer
- if (![_transport readAll:_readBuffer.mutableBytes offset:0 length:size error:error]) {
- return NO;
- }
-
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/transport/THTTPSessionTransport.h b/lib/cocoa/src/transport/THTTPSessionTransport.h
deleted file mode 100644
index 003499b80..000000000
--- a/lib/cocoa/src/transport/THTTPSessionTransport.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TAsyncTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-typedef NSError *__nullable (^THTTPSessionTransportResponseValidateBlock) (NSHTTPURLResponse *response, NSData *responseData);
-
-
-@interface THTTPSessionTransportFactory : NSObject<TAsyncTransportFactory>
-
-@property (strong, nonatomic) THTTPSessionTransportResponseValidateBlock responseValidate;
-
-+(void) setupDefaultsForSessionConfiguration:(NSURLSessionConfiguration *)config
- withProtocolName:(NSString *)protocolName;
-
--(id) initWithSession:(NSURLSession *)session
- URL:(NSURL *)aURL;
-
-@end
-
-
-@interface THTTPSessionTransport : NSObject <TAsyncTransport>
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/THTTPSessionTransport.m b/lib/cocoa/src/transport/THTTPSessionTransport.m
deleted file mode 100644
index c10b7fc3f..000000000
--- a/lib/cocoa/src/transport/THTTPSessionTransport.m
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "THTTPSessionTransport.h"
-#import "TTransportError.h"
-
-
-@interface THTTPSessionTransportFactory ()
-
-@property (strong, nonatomic) NSURLSession *session;
-@property (strong, nonatomic) NSURL *url;
-
-@end
-
-
-@interface THTTPSessionTransport ()
-
-@property (strong, nonatomic) THTTPSessionTransportFactory *factory;
-@property (strong, nonatomic) NSMutableData *requestData;
-@property (strong, nonatomic) NSData *responseData;
-@property (assign, nonatomic) NSUInteger responseDataOffset;
-
--(instancetype) initWithFactory:(THTTPSessionTransportFactory *)factory;
-
-@end
-
-
-@implementation THTTPSessionTransportFactory
-
-+(void) setupDefaultsForSessionConfiguration:(NSURLSessionConfiguration *)config withProtocolName:(NSString *)protocolName
-{
- NSString *thriftContentType = @"application/x-thrift";
- if (protocolName.length) {
- thriftContentType = [thriftContentType stringByAppendingFormat:@"; p=%@", protocolName];
- }
-
- config.requestCachePolicy = NSURLRequestReloadIgnoringCacheData;
- config.HTTPShouldUsePipelining = YES;
- config.HTTPShouldSetCookies = NO;
- config.URLCache = nil;
- config.HTTPAdditionalHeaders = @{@"Content-Type":thriftContentType,
- @"Accept":thriftContentType,
- @"User-Agent":@"Thrift/Cocoa (Session)"};
-}
-
-
--(id) initWithSession:(NSURLSession *)session URL:(NSURL *)url
-{
- self = [super init];
- if (self) {
- _session = session;
- _url = url;
- }
-
- return self;
-}
-
--(id<TAsyncTransport>) newTransport
-{
- return [[THTTPSessionTransport alloc] initWithFactory:self];
-}
-
--(NSURLSessionDataTask *) taskWithRequest:(NSURLRequest *)request
- completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError *error))completionHandler
- error:(NSError *__autoreleasing *)error
-{
- NSURLSessionDataTask *newTask = [_session dataTaskWithRequest:request completionHandler:completionHandler];
- if (!newTask) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{NSLocalizedDescriptionKey:@"Failed to create session data task"}];
- }
- return nil;
- }
-
- return newTask;
-}
-
--(NSError *) validateResponse:(NSHTTPURLResponse *)response data:(NSData *)data
-{
- if (_responseValidate) {
- return _responseValidate(response, data);
- }
- return nil;
-}
-
-@end
-
-
-
-@implementation THTTPSessionTransport
-
--(instancetype) initWithFactory:(THTTPSessionTransportFactory *)factory
-{
- self = [super init];
- if (self) {
- _factory = factory;
- }
- return self;
-}
-
--(BOOL) readAll:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = [self readAvail:outBuffer offset:outBufferOffset maxLength:length error:error];
- if (got != length) {
-
- // Report underflow only if readAvail didn't report error already
- if (error && !*error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:nil];
- }
-
- return NO;
- }
-
- return YES;
-}
-
--(UInt32) readAvail:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset maxLength:(UInt32)maxLength error:(NSError *__autoreleasing *)error
-{
- NSUInteger avail = _responseData.length - _responseDataOffset;
-
- NSRange range;
- range.location = _responseDataOffset;
- range.length = MIN(maxLength, avail);
-
- [_responseData getBytes:outBuffer+outBufferOffset range:range];
- _responseDataOffset += range.length;
-
- return (UInt32)range.length;
-}
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- if (!_requestData) {
- _requestData = [NSMutableData dataWithCapacity:256];
- }
-
- [_requestData appendBytes:data+offset length:length];
-
- return YES;
-}
-
--(void) flushWithCompletion:(TAsyncCompletionBlock)completed failure:(TAsyncFailureBlock)failure
-{
- NSError *error;
-
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:_factory.url];
- request.HTTPMethod = @"POST";
- request.HTTPBody = _requestData;
-
- _requestData = nil;
-
- NSURLSessionDataTask *task = [_factory taskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
-
- // Check response type
- if (!error && ![response isKindOfClass:NSHTTPURLResponse.class]) {
-
- error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{TTransportErrorHttpErrorKey: @(THttpTransportErrorInvalidResponse)}];
-
- }
-
- // Check status code
- NSHTTPURLResponse *httpResponse = (id)response;
- if (!error && httpResponse.statusCode != 200) {
-
- THttpTransportError code;
- if (httpResponse.statusCode == 401) {
- code = THttpTransportErrorAuthentication;
- }
- else {
- code = THttpTransportErrorInvalidStatus;
- }
-
- error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{TTransportErrorHttpErrorKey: @(code),
- @"statusCode":@(httpResponse.statusCode)}];
- }
-
- // Allow factory to check
- if (!error) {
- error = [_factory validateResponse:httpResponse data:data];
- }
-
- _responseDataOffset = 0;
-
- if (error) {
-
- _responseData = nil;
-
- failure(error);
-
- }
- else {
-
- if (data == nil) {
- data = [NSData data];
- }
-
- _responseData = data;
-
- completed(self);
- }
-
- } error:&error];
-
- if (!task) {
- failure(error);
- return;
- }
-
- [task resume];
-}
-
--(BOOL) flush:(NSError *__autoreleasing *)error
-{
- dispatch_semaphore_t completed = dispatch_semaphore_create(0);
-
- __block BOOL result;
- __block NSError *internalError;
-
- [self flushWithCompletion:^(id < TAsyncTransport > transport) {
-
- result = YES;
-
- dispatch_semaphore_signal(completed);
-
- } failure:^(NSError *error) {
-
- internalError = error;
-
- result = NO;
-
- dispatch_semaphore_signal(completed);
-
- }];
-
- dispatch_semaphore_wait(completed, DISPATCH_TIME_FOREVER);
-
- if (error) {
- *error = internalError;
- }
-
- return result;
-}
-
-@end
diff --git a/lib/cocoa/src/transport/THTTPTransport.h b/lib/cocoa/src/transport/THTTPTransport.h
deleted file mode 100644
index 3c35daf9e..000000000
--- a/lib/cocoa/src/transport/THTTPTransport.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface THTTPTransport : NSObject <TTransport>
-
--(id) initWithURL:(NSURL *)aURL;
-
--(id) initWithURL:(NSURL *)aURL
- userAgent:(nullable NSString *)userAgent
- timeout:(int)timeout;
-
--(void) setURL:(NSURL *)aURL;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/THTTPTransport.m b/lib/cocoa/src/transport/THTTPTransport.m
deleted file mode 100644
index e4046c6ca..000000000
--- a/lib/cocoa/src/transport/THTTPTransport.m
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "THTTPTransport.h"
-#import "TTransportError.h"
-
-
-@interface THTTPTransport ()
-
-@property (strong, nonatomic) NSURL *url;
-@property (strong, nonatomic) NSMutableURLRequest *request;
-@property (strong, nonatomic) NSMutableData *requestData;
-@property (strong, nonatomic) NSData *responseData;
-@property (assign, nonatomic) NSUInteger responseDataOffset;
-@property (strong, nonatomic) NSString *userAgent;
-@property (assign, nonatomic) NSTimeInterval timeout;
-
-@end
-
-
-@implementation THTTPTransport
-
--(void) setupRequest
-{
- // set up our request object that we'll use for each request
- _request = [[NSMutableURLRequest alloc] initWithURL:_url];
- [_request setHTTPMethod:@"POST"];
- [_request setValue:@"application/x-thrift" forHTTPHeaderField:@"Content-Type"];
- [_request setValue:@"application/x-thrift" forHTTPHeaderField:@"Accept"];
-
- NSString *userAgent = _userAgent;
- if (!userAgent) {
- userAgent = @"Thrift/Cocoa";
- }
- [_request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
-
- [_request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
- if (_timeout) {
- [_request setTimeoutInterval:_timeout];
- }
-}
-
-
--(id) initWithURL:(NSURL *)aURL
-{
- return [self initWithURL:aURL
- userAgent:nil
- timeout:0];
-}
-
-
--(id) initWithURL:(NSURL *)aURL
- userAgent:(NSString *)aUserAgent
- timeout:(int)aTimeout
-{
- self = [super init];
- if (!self) {
- return nil;
- }
-
- _timeout = aTimeout;
- _userAgent = aUserAgent;
- _url = aURL;
-
- [self setupRequest];
-
- // create our request data buffer
- _requestData = [[NSMutableData alloc] initWithCapacity:1024];
-
- return self;
-}
-
--(void) setURL:(NSURL *)aURL
-{
- _url = aURL;
-
- [self setupRequest];
-}
-
--(BOOL) readAll:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = [self readAvail:outBuffer offset:outBufferOffset maxLength:length error:error];
- if (got != length) {
-
- // Report underflow only if readAvail didn't report error already
- if (error && !*error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:nil];
- }
-
- return NO;
- }
-
- return YES;
-}
-
--(UInt32) readAvail:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset maxLength:(UInt32)maxLength error:(NSError *__autoreleasing *)error
-{
- NSUInteger avail = _responseData.length - _responseDataOffset;
-
- NSRange range;
- range.location = _responseDataOffset;
- range.length = MIN(maxLength, avail);
-
- [_responseData getBytes:outBuffer+outBufferOffset range:range];
- _responseDataOffset += range.length;
-
- return (UInt32)range.length;
-}
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- [_requestData appendBytes:data+offset length:length];
-
- return YES;
-}
-
--(BOOL) flush:(NSError *__autoreleasing *)error
-{
- [_request setHTTPBody:_requestData];
-
- _responseDataOffset = 0;
-
- // make the HTTP request
- NSURLResponse *response;
- _responseData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:error];
- if (!_responseData) {
- return NO;
- }
-
- [_requestData setLength:0];
-
- if (![response isKindOfClass:NSHTTPURLResponse.class]) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{TTransportErrorHttpErrorKey: @(THttpTransportErrorInvalidResponse)}];
- }
- return NO;
- }
-
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
- if ([httpResponse statusCode] != 200) {
- if (error) {
-
- THttpTransportError code;
- if (httpResponse.statusCode == 401) {
- code = THttpTransportErrorAuthentication;
- }
- else {
- code = THttpTransportErrorInvalidStatus;
- }
-
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorUnknown
- userInfo:@{TTransportErrorHttpErrorKey: @(code),
- @"statusCode":@(httpResponse.statusCode)}];
- }
- return NO;
- }
-
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TMemoryBuffer.h b/lib/cocoa/src/transport/TMemoryBuffer.h
deleted file mode 100644
index 6249d3209..000000000
--- a/lib/cocoa/src/transport/TMemoryBuffer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TMemoryBuffer : NSObject <TTransport>
-
--(NSData *) buffer;
-
--(id) initWithData:(NSData *)data;
-
--(id) initWithDataNoCopy:(NSMutableData *)data;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TMemoryBuffer.m b/lib/cocoa/src/transport/TMemoryBuffer.m
deleted file mode 100644
index ec19cc808..000000000
--- a/lib/cocoa/src/transport/TMemoryBuffer.m
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TMemoryBuffer.h"
-#import "TTransportError.h"
-
-
-#define GARBAGE_BUFFER_SIZE 4096 // 4KiB
-
-
-@interface TMemoryBuffer ()
-
-@property(strong, nonatomic) NSMutableData *buffer;
-@property(assign, nonatomic) UInt32 bufferOffset;
-
-@end
-
-
-@implementation TMemoryBuffer
-
--(id) init
-{
- if ((self = [super init])) {
- _buffer = [NSMutableData new];
- _bufferOffset = 0;
- }
- return self;
-}
-
--(id) initWithData:(NSData *)data
-{
- if (self = [super init]) {
- _buffer = [data mutableCopy];
- _bufferOffset = 0;
- }
- return self;
-}
-
--(id) initWithDataNoCopy:(NSMutableData *)data
-{
- if (self = [super init]) {
- _buffer = data;
- _bufferOffset = 0;
- }
- return self;
-}
-
--(BOOL) readAll:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = [self readAvail:outBuffer offset:outBufferOffset maxLength:length error:error];
- if (got != length) {
-
- // Report underflow only if readAvail didn't report error already
- if (error && !*error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:nil];
- }
-
- return NO;
- }
-
- return YES;
-}
-
--(UInt32) readAvail:(UInt8 *)outBuffer offset:(UInt32)outBufferOffset maxLength:(UInt32)maxLength error:(NSError *__autoreleasing *)error
-{
- UInt32 avail = (UInt32)_buffer.length - _bufferOffset;
- if (avail == 0) {
- return 0;
- }
-
- NSRange range;
- range.location = _bufferOffset;
- range.length = MIN(maxLength, avail);
-
- [_buffer getBytes:outBuffer + outBufferOffset range:range];
- _bufferOffset += range.length;
-
- if (_bufferOffset >= GARBAGE_BUFFER_SIZE) {
- [_buffer replaceBytesInRange:NSMakeRange(0, _bufferOffset) withBytes:NULL length:0];
- _bufferOffset = 0;
- }
-
- return (UInt32)range.length;
-}
-
--(BOOL) write:(const UInt8 *)inBuffer offset:(UInt32)inBufferOffset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- [_buffer appendBytes:inBuffer + inBufferOffset length:length];
-
- return YES;
-}
-
--(NSData *) buffer
-{
- return _buffer;
-}
-
--(BOOL) flush:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TNSFileHandleTransport.h b/lib/cocoa/src/transport/TNSFileHandleTransport.h
deleted file mode 100644
index db6edf383..000000000
--- a/lib/cocoa/src/transport/TNSFileHandleTransport.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-
-#import <Foundation/Foundation.h>
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TNSFileHandleTransport : NSObject <TTransport>
-
--(id) initWithFileHandle:(NSFileHandle *)fileHandle;
-
--(id) initWithInputFileHandle:(NSFileHandle *)inputFileHandle
- outputFileHandle:(NSFileHandle *)outputFileHandle;
-
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TNSFileHandleTransport.m b/lib/cocoa/src/transport/TNSFileHandleTransport.m
deleted file mode 100644
index c907f87da..000000000
--- a/lib/cocoa/src/transport/TNSFileHandleTransport.m
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-
-#import "TNSFileHandleTransport.h"
-#import "TTransportError.h"
-
-
-@interface TNSFileHandleTransport ()
-
-@property(strong, nonatomic) NSFileHandle *inputFileHandle;
-@property(strong, nonatomic) NSFileHandle *outputFileHandle;
-
-@end
-
-
-@implementation TNSFileHandleTransport
-
--(id) initWithFileHandle:(NSFileHandle *)fileHandle
-{
- return [self initWithInputFileHandle:fileHandle
- outputFileHandle:fileHandle];
-}
-
-
--(id) initWithInputFileHandle:(NSFileHandle *)aInputFileHandle
- outputFileHandle:(NSFileHandle *)aOutputFileHandle
-{
- self = [super init];
- if (self) {
- _inputFileHandle = aInputFileHandle;
- _outputFileHandle = aOutputFileHandle;
- }
- return self;
-}
-
-
--(BOOL) readAll:(UInt8 *)buf offset:(UInt32)off length:(UInt32)len error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- while (got < len) {
-
- NSData *d = [_inputFileHandle readDataOfLength:len-got];
- if (d.length == 0) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:nil];
- }
- return NO;
- }
-
- [d getBytes:buf+got length:d.length];
- got += d.length;
- }
- return YES;
-}
-
-
--(UInt32) readAvail:(UInt8 *)buf offset:(UInt32)off maxLength:(UInt32)len error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- while (got < len) {
-
- NSData *d = [_inputFileHandle readDataOfLength:len-got];
- if (d.length == 0) {
- break;
- }
-
- [d getBytes:buf+got length:d.length];
- got += d.length;
- }
- return got;
-}
-
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- void *pos = (void *)data + offset;
-
- @try {
- [_outputFileHandle writeData:[NSData dataWithBytesNoCopy:pos length:length freeWhenDone:NO]];
- }
- @catch (NSException *e) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorNotOpen
- userInfo:@{}];
- }
- return NO;
- }
-
- return YES;
-}
-
-
--(BOOL) flush:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TNSStreamTransport.h b/lib/cocoa/src/transport/TNSStreamTransport.h
deleted file mode 100644
index 54c488444..000000000
--- a/lib/cocoa/src/transport/TNSStreamTransport.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TNSStreamTransport : NSObject <TTransport>
-
-@property (strong, nonatomic) NSInputStream *input;
-@property (strong, nonatomic) NSOutputStream *output;
-
--(id) initWithInputStream:(nullable NSInputStream *)input
- outputStream:(nullable NSOutputStream *)output;
-
--(id) initWithInputStream:(NSInputStream *)input;
-
--(id) initWithOutputStream:(NSOutputStream *)output;
-
--(void) close;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TNSStreamTransport.m b/lib/cocoa/src/transport/TNSStreamTransport.m
deleted file mode 100644
index 18c41d3d9..000000000
--- a/lib/cocoa/src/transport/TNSStreamTransport.m
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TNSStreamTransport.h"
-#import "TTransportError.h"
-
-
-@interface TNSStreamTransport ()
-@end
-
-
-@implementation TNSStreamTransport
-
--(id) initWithInputStream:(NSInputStream *)input
- outputStream:(NSOutputStream *)output
-{
- self = [super init];
- if (self) {
- _input = input;
- _output = output;
- }
- return self;
-}
-
--(id) initWithInputStream:(NSInputStream *)input
-{
- return [self initWithInputStream:input outputStream:nil];
-}
-
--(id) initWithOutputStream:(NSOutputStream *)output
-{
- return [self initWithInputStream:nil outputStream:output];
-}
-
--(void) dealloc
-{
- [self close];
-}
-
--(BOOL) readAll:(UInt8 *)buf offset:(UInt32)off length:(UInt32)len error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- while (got < len) {
-
- UInt32 read = (UInt32)[_input read:buf+off+got maxLength:len-got];
- if (read <= 0) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorNotOpen
- userInfo:@{}];
- }
- return NO;
- }
-
- got += read;
- }
-
- return YES;
-}
-
-
--(UInt32) readAvail:(UInt8 *)buf offset:(UInt32)off maxLength:(UInt32)len error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- while (got < len) {
-
- UInt32 read = (UInt32)[_input read:buf+off+got maxLength:len-got];
- if (read <= 0) {
- break;
- }
-
- got += read;
- }
-
- return got;
-}
-
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error
-{
- UInt32 got = 0;
- NSInteger total = 0;
- while (got < length) {
-
- total = [_output write:data+offset+got maxLength:length-got];
- if (total == -1) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorNotOpen
- userInfo:@{}];
- }
- return NO;
- }
- else if (total == 0) {
- if (error) {
- *error = [NSError errorWithDomain:TTransportErrorDomain
- code:TTransportErrorEndOfFile
- userInfo:@{}];
- }
- return NO;
- }
-
- got += total;
- }
-
- return YES;
-}
-
--(BOOL) flush:(NSError *__autoreleasing *)error
-{
- return YES;
-}
-
--(void) close
-{
- NSInputStream *input = self.input;
- if (input) {
- // Close and reset inputstream
- CFReadStreamSetProperty((__bridge CFReadStreamRef)(input), kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
- [input setDelegate:nil];
- [input close];
- [input removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- input = nil;
- }
-
- NSOutputStream *output = self.output;
- if (output) {
- // Close and reset outputstream
- CFWriteStreamSetProperty((__bridge CFWriteStreamRef)(output), kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
- [output setDelegate:nil];
- [output close];
- [output removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- output = nil;
- }
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TSSLSocketTransport.h b/lib/cocoa/src/transport/TSSLSocketTransport.h
deleted file mode 100644
index b606c4a33..000000000
--- a/lib/cocoa/src/transport/TSSLSocketTransport.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TNSStreamTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TSSLSocketTransport : TNSStreamTransport <NSStreamDelegate>
-
--(id) initWithHostname:(NSString *)hostname
- port:(int)port
- error:(NSError **)error;
-
--(BOOL) isOpen;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TSSLSocketTransport.m b/lib/cocoa/src/transport/TSSLSocketTransport.m
deleted file mode 100644
index 1b1214fe4..000000000
--- a/lib/cocoa/src/transport/TSSLSocketTransport.m
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-#import <Foundation/Foundation.h>
-#import <CoreFoundation/CoreFoundation.h>
-#import "TSSLSocketTransport.h"
-#import "TSSLSocketTransportError.h"
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-
-#if !TARGET_OS_IPHONE
-#import <CoreServices/CoreServices.h>
-#else
-#import <CFNetwork/CFNetwork.h>
-#endif
-
-@interface TSSLSocketTransport ()
-
-@property(strong, nonatomic) NSString *sslHostname;
-@property(assign, nonatomic) int sd;
-
-@end
-
-
-@implementation TSSLSocketTransport
-
--(id) initWithHostname:(NSString *)hostname
- port:(int)port
- error:(NSError **)error
-{
- _sslHostname = hostname;
- CFReadStreamRef readStream = NULL;
- CFWriteStreamRef writeStream = NULL;
-
-
- /* create a socket structure */
- struct sockaddr_in pin;
- struct hostent *hp = NULL;
- for (int i = 0; i < 10; i++) {
-
-
-
- if ((hp = gethostbyname([hostname UTF8String])) == NULL) {
- NSLog(@"failed to resolve hostname %@", hostname);
- herror("resolv");
- if (i == 9) {
- if (error) {
- *error = [NSError errorWithDomain:TSSLSocketTransportErrorDomain
- code:TSSLSocketTransportErrorHostanameResolution
- userInfo:nil];
- }
- return nil;
- }
- [NSThread sleepForTimeInterval:0.2];
- }
- else {
- break;
- }
- }
-
- memset(&pin, 0, sizeof(pin));
- pin.sin_family = AF_INET;
- memcpy(&pin.sin_addr, hp->h_addr, sizeof(struct in_addr));
- pin.sin_port = htons(port);
-
- /* create the socket */
- if ((_sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) {
- NSLog(@"failed to create socket for host %@:%d", hostname, port);
- if (error) {
- *error = [NSError errorWithDomain:TSSLSocketTransportErrorDomain
- code:TSSLSocketTransportErrorSocketCreate
- userInfo:nil];
- }
- return nil;
- }
-
- /* open a connection */
- if (connect(_sd, (struct sockaddr *)&pin, sizeof(pin)) == -1) {
- NSLog(@"failed to create conenct to host %@:%d", hostname, port);
- if (error) {
- *error = [NSError errorWithDomain:TSSLSocketTransportErrorDomain
- code:TSSLSocketTransportErrorConnect
- userInfo:nil];
- }
- return nil;
- }
- CFStreamCreatePairWithSocket(kCFAllocatorDefault, _sd, &readStream, &writeStream);
-
- CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
- CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
-
- NSInputStream *inputStream;
- NSOutputStream *outputStream;
-
- if (readStream && writeStream) {
-
- CFReadStreamSetProperty(readStream,
- kCFStreamPropertySocketSecurityLevel,
- kCFStreamSocketSecurityLevelTLSv1);
-
- NSDictionary *settings = @{(__bridge NSString *)kCFStreamSSLValidatesCertificateChain: @YES};
-
- CFReadStreamSetProperty((CFReadStreamRef)readStream,
- kCFStreamPropertySSLSettings,
- (CFTypeRef)settings);
-
- CFWriteStreamSetProperty((CFWriteStreamRef)writeStream,
- kCFStreamPropertySSLSettings,
- (CFTypeRef)settings);
-
- inputStream = (__bridge NSInputStream *)readStream;
- [inputStream setDelegate:self];
- [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- [inputStream open];
-
- outputStream = (__bridge NSOutputStream *)writeStream;
- [outputStream setDelegate:self];
- [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
- [outputStream open];
-
- CFRelease(readStream);
- CFRelease(writeStream);
- }
-
- self = [super initWithInputStream:inputStream outputStream:outputStream];
-
- return self;
-}
-
--(void) dealloc
-{
- [self close];
-}
-
-#pragma mark -
-#pragma mark NSStreamDelegate
-
--(void) stream:(NSStream *)aStream
- handleEvent:(NSStreamEvent)eventCode
-{
- switch (eventCode) {
- case NSStreamEventNone:
- break;
-
- case NSStreamEventHasBytesAvailable:
- break;
-
- case NSStreamEventOpenCompleted:
- break;
-
- case NSStreamEventHasSpaceAvailable: {
-
- BOOL proceed = NO;
- SecTrustResultType trustResult = kSecTrustResultInvalid;
- CFMutableArrayRef newPolicies = NULL;
-
- do {
-
- SecTrustRef trust = (__bridge SecTrustRef)[aStream propertyForKey:(NSString *)kCFStreamPropertySSLPeerTrust];
-
- // Add new policy to current list of policies
- SecPolicyRef policy = SecPolicyCreateSSL(NO, (__bridge CFStringRef)(_sslHostname));
- if (!policy) {
- break;
- }
-
- CFArrayRef policies;
- if (SecTrustCopyPolicies(trust, &policies) != errSecSuccess) {
- CFRelease(policy);
- break;
- }
-
- newPolicies = CFArrayCreateMutableCopy(NULL, 0, policies);
- CFArrayAppendValue(newPolicies, policy);
-
- CFRelease(policies);
- CFRelease(policy);
-
- // Update trust policies
- if (SecTrustSetPolicies(trust, newPolicies) != errSecSuccess) {
- break;
- }
-
- // Evaluate the trust chain
- if (SecTrustEvaluate(trust, &trustResult) != errSecSuccess) {
- break;
- }
-
- switch (trustResult) {
- case kSecTrustResultProceed:
- // NSLog(@"Trusted by USER");
- proceed = YES;
- break;
-
- case kSecTrustResultUnspecified:
- // NSLog(@"Trusted by OS");
- proceed = YES;
- break;
-
- case kSecTrustResultRecoverableTrustFailure:
- proceed = recoverFromTrustFailure(trust, trustResult);
- break;
-
- case kSecTrustResultDeny:
- // NSLog(@"Deny");
- break;
-
- case kSecTrustResultFatalTrustFailure:
- // NSLog(@"FatalTrustFailure");
- break;
-
- case kSecTrustResultOtherError:
- // NSLog(@"OtherError");
- break;
-
- case kSecTrustResultInvalid:
- // NSLog(@"Invalid");
- break;
-
- default:
- // NSLog(@"Default");
- break;
- }
-
- }
- while (NO);
-
- if (!proceed) {
- NSLog(@"TSSLSocketTransport: Cannot trust certificate. Result: %u", trustResult);
- [aStream close];
- }
-
- if (newPolicies) {
- CFRelease(newPolicies);
- }
-
- }
- break;
-
- case NSStreamEventErrorOccurred: {
- NSLog(@"TSSLSocketTransport: Error occurred opening stream: %@", [aStream streamError]);
- break;
- }
-
- case NSStreamEventEndEncountered:
- break;
- }
-}
-
-BOOL recoverFromTrustFailure(SecTrustRef myTrust, SecTrustResultType lastTrustResult)
-{
- CFAbsoluteTime trustTime = SecTrustGetVerifyTime(myTrust);
- CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent();
-
- CFAbsoluteTime timeIncrement = 31536000;
- CFAbsoluteTime newTime = currentTime - timeIncrement;
-
- if (trustTime - newTime) {
-
- CFDateRef newDate = CFDateCreate(NULL, newTime);
- SecTrustSetVerifyDate(myTrust, newDate);
- CFRelease(newDate);
-
- if (SecTrustEvaluate(myTrust, &lastTrustResult) != errSecSuccess) {
- return NO;
- }
-
- }
-
- if (lastTrustResult == kSecTrustResultProceed || lastTrustResult == kSecTrustResultUnspecified) {
- return YES;
- }
-
- NSLog(@"TSSLSocketTransport: Unable to recover certificate trust failure");
- return YES;
-}
-
--(BOOL) isOpen
-{
- if (_sd > 0) {
- return TRUE;
- }
- else {
- return FALSE;
- }
-}
-
-@end
diff --git a/lib/cocoa/src/transport/TSSLSocketTransportError.h b/lib/cocoa/src/transport/TSSLSocketTransportError.h
deleted file mode 100644
index e17f39e32..000000000
--- a/lib/cocoa/src/transport/TSSLSocketTransportError.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TTransportError.h"
-
-
-extern NSString *TSSLSocketTransportErrorDomain;
-
-
-typedef NS_ENUM (int, TSSLSocketTransportError) {
- TSSLSocketTransportErrorHostanameResolution = -10000,
- TSSLSocketTransportErrorSocketCreate = -10001,
- TSSLSocketTransportErrorConnect = -10002,
-};
diff --git a/lib/cocoa/src/transport/TSSLSocketTransportError.m b/lib/cocoa/src/transport/TSSLSocketTransportError.m
deleted file mode 100644
index bcf941cc4..000000000
--- a/lib/cocoa/src/transport/TSSLSocketTransportError.m
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TSSLSocketTransportError.h"
-
-
-NSString *TSSLSocketTransportErrorDomain = @"TSSLSocketTransportErrorDomain";
diff --git a/lib/cocoa/src/transport/TSocketTransport.h b/lib/cocoa/src/transport/TSocketTransport.h
deleted file mode 100644
index a7b91a2c9..000000000
--- a/lib/cocoa/src/transport/TSocketTransport.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-#import "TNSStreamTransport.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@interface TSocketTransport : TNSStreamTransport
-
--(id) initWithHostname:(NSString *)hostname
- port:(int)port;
-
--(id) initWithPath:(NSString *)path;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TSocketTransport.m b/lib/cocoa/src/transport/TSocketTransport.m
deleted file mode 100644
index 9c58abb6d..000000000
--- a/lib/cocoa/src/transport/TSocketTransport.m
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-#import "TSocketTransport.h"
-
-#if !TARGET_OS_IPHONE
-#import <CoreServices/CoreServices.h>
-#else
-#import <CFNetwork/CFNetwork.h>
-#endif
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-
-@interface TSocketTransport () <NSStreamDelegate>
-@end
-
-
-@implementation TSocketTransport
-
-- (id) initWithReadStream: (CFReadStreamRef) readStream writeStream: (CFWriteStreamRef) writeStream
-{
- NSInputStream *inputStream = nil;
- NSOutputStream *outputStream = nil;
-
- if (readStream && writeStream) {
-
- CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
- CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
-
- inputStream = (__bridge NSInputStream *)readStream;
- [inputStream setDelegate:self];
- [inputStream scheduleInRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode];
- [inputStream open];
-
- outputStream = (__bridge NSOutputStream *)writeStream;
- [outputStream setDelegate:self];
- [outputStream scheduleInRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode];
- [outputStream open];
- }
- else {
-
- if (readStream) {
- CFRelease(readStream);
- }
-
- if (writeStream) {
- CFRelease(writeStream);
- }
-
- return nil;
- }
-
- return [super initWithInputStream:inputStream outputStream:outputStream];
-}
-
-- (id) initWithHostname: (NSString *) hostname
- port: (int) port
-{
- CFReadStreamRef readStream = NULL;
- CFWriteStreamRef writeStream = NULL;
- CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)hostname, port, &readStream, &writeStream);
- return [self initWithReadStream:readStream writeStream:writeStream];
-}
-
-- (id) initWithPath: (NSString *) path
-{
- CFSocketNativeHandle sockfd = socket(AF_LOCAL, SOCK_STREAM, IPPROTO_IP);
- int yes = 1;
- if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
- {
- NSLog(@"TSocketTransport: Unable to set REUSEADDR property of socket.");
- return nil;
- }
-
- NSData *serverAddress = [[self class] createAddressWithPath:path];
-
- CFReadStreamRef readStream = NULL;
- CFWriteStreamRef writeStream = NULL;
- CFStreamCreatePairWithSocket(kCFAllocatorDefault, sockfd, &readStream, &writeStream);
- if (!readStream || !writeStream)
- {
- NSLog(@"TSocketTransport: Unable to create read/write stream pair for socket.");
- return nil;
- }
-
- if (connect(sockfd, (struct sockaddr *)serverAddress.bytes, (socklen_t) serverAddress.length) < 0)
- {
- NSLog(@"TSocketTransport: Connect error: %s\n", strerror(errno));
- return nil;
- }
-
- return [self initWithReadStream:readStream writeStream:writeStream];
-}
-
-+ (NSData *) createAddressWithPath: (NSString *)path
-{
- struct sockaddr_un servaddr;
-
- size_t nullTerminatedPathLength = path.length + 1;
- if (nullTerminatedPathLength> sizeof(servaddr.sun_path)) {
- NSLog(@"TSocketTransport: Unable to create socket at path %@. Path is too long.", path);
- return nil;
- }
-
- bzero(&servaddr,sizeof(servaddr));
- servaddr.sun_family = AF_LOCAL;
- memcpy(servaddr.sun_path, path.UTF8String, nullTerminatedPathLength);
- servaddr.sun_len = SUN_LEN(&servaddr);
-
- return [NSData dataWithBytes:&servaddr length:sizeof(servaddr)];
-}
-
-
-@end
diff --git a/lib/cocoa/src/transport/TTransport.h b/lib/cocoa/src/transport/TTransport.h
deleted file mode 100644
index 558cf60fb..000000000
--- a/lib/cocoa/src/transport/TTransport.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import <Foundation/Foundation.h>
-
-
-NS_ASSUME_NONNULL_BEGIN
-
-
-@protocol TTransport <NSObject>
-
-/**
- * Guarantees that all of len bytes are read
- *
- * @param buf Buffer to read into
- * @param off Index in buffer to start storing bytes at
- * @param len Maximum number of bytes to read
- * @return YES if succeeded, NO if failed
- * @throws TTransportError if there was an error reading data
- */
--(BOOL) readAll:(UInt8 *)buf offset:(UInt32)off length:(UInt32)len error:(NSError *__autoreleasing *)error;
-
--(UInt32) readAvail:(UInt8 *)buf offset:(UInt32)off maxLength:(UInt32)maxLen error:(NSError *__autoreleasing *)error;
-
--(BOOL) write:(const UInt8 *)data offset:(UInt32)offset length:(UInt32)length error:(NSError *__autoreleasing *)error;
-
--(BOOL) flush:(NSError *__autoreleasing *)error;
-
-@end
-
-
-NS_ASSUME_NONNULL_END
diff --git a/lib/cocoa/src/transport/TTransportError.h b/lib/cocoa/src/transport/TTransportError.h
deleted file mode 100644
index c8c9f067f..000000000
--- a/lib/cocoa/src/transport/TTransportError.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TError.h"
-
-
-extern NSString *TTransportErrorDomain;
-
-
-typedef NS_ENUM (int, TTransportError) {
- TTransportErrorUnknown = 0,
- TTransportErrorNotOpen = 1,
- TTransportErrorAlreadyOpen = 2,
- TTransportErrorTimedOut = 3,
- TTransportErrorEndOfFile = 4,
-};
-
-
-extern NSString *TTransportErrorExtendedErrorKey;
-extern NSString *TTransportErrorHttpErrorKey;
-
-
-typedef NS_ENUM(int, THttpTransportError) {
- THttpTransportErrorInvalidResponse = 1001,
- THttpTransportErrorInvalidStatus = 1002,
- THttpTransportErrorAuthentication = 1003,
-};
diff --git a/lib/cocoa/src/transport/TTransportError.m b/lib/cocoa/src/transport/TTransportError.m
deleted file mode 100644
index b1af076b2..000000000
--- a/lib/cocoa/src/transport/TTransportError.m
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-#import "TTransportError.h"
-
-
-NSString *TTransportErrorDomain = @"TTransportErrorDomain";
-
-
-NSString *TTransportErrorExtendedErrorKey = @"extendedError";
-NSString *TTransportErrorHttpErrorKey = @"httpError";
diff --git a/lib/cpp/test/OneWayTest.thrift b/lib/cpp/test/OneWayTest.thrift
index 127e9ffa3..102cf26e5 100644
--- a/lib/cpp/test/OneWayTest.thrift
+++ b/lib/cpp/test/OneWayTest.thrift
@@ -34,7 +34,6 @@ namespace py.twisted OneWayTest
namespace go onewaytest
namespace php OneWayTest
namespace delphi Onewaytest
-namespace cocoa OneWayTest
namespace lua OneWayTest
namespace xsd test (uri = 'http://thrift.apache.org/ns/OneWayTest')
namespace netcore ThriftAsync.OneWayTest
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index 3499ab5f8..e025b7f54 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -22,22 +22,21 @@
*/
namespace c_glib TTest
-namespace java thrift.test
namespace cpp thrift.test
-namespace rb Thrift.Test
-namespace perl ThriftTest
namespace csharp Thrift.Test
+namespace delphi Thrift.Test
+namespace go thrifttest
+namespace java thrift.test
namespace js ThriftTest
-namespace st ThriftTest
+namespace lua ThriftTest
+namespace netcore ThriftTest
+namespace perl ThriftTest
+namespace php ThriftTest
namespace py ThriftTest
namespace py.twisted ThriftTest
-namespace go thrifttest
-namespace php ThriftTest
-namespace delphi Thrift.Test
-namespace cocoa ThriftTest
-namespace lua ThriftTest
+namespace rb Thrift.Test
+namespace st ThriftTest
namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')
-namespace netcore ThriftTest
// Presence of namespaces and sub-namespaces for which there is
// no generator should compile with warnings only