auser-poolparty 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. data/VERSION.yml +1 -1
  2. data/examples/monitored_cloud.rb +1 -1
  3. data/examples/thrift/thrift_example.rb +1 -1
  4. data/lib/proto/command_interface_handler.rb +1 -1
  5. data/vendor/gems/thrift/CHANGES +35 -0
  6. data/vendor/gems/thrift/CONTRIBUTORS +77 -0
  7. data/vendor/gems/thrift/DISCLAIMER +6 -0
  8. data/vendor/gems/thrift/LICENSE +202 -0
  9. data/vendor/gems/thrift/Makefile.am +28 -0
  10. data/vendor/gems/thrift/NEWS +79 -0
  11. data/vendor/gems/thrift/NOTICE +26 -0
  12. data/vendor/gems/thrift/README +137 -0
  13. data/vendor/gems/thrift/aclocal/ax_boost_base.m4 +198 -0
  14. data/vendor/gems/thrift/aclocal/ax_javac_and_java.m4 +107 -0
  15. data/vendor/gems/thrift/aclocal/ax_lib_event.m4 +194 -0
  16. data/vendor/gems/thrift/aclocal/ax_lib_zlib.m4 +173 -0
  17. data/vendor/gems/thrift/aclocal/ax_signed_right_shift.m4 +127 -0
  18. data/vendor/gems/thrift/aclocal/ax_thrift_internal.m4 +39 -0
  19. data/vendor/gems/thrift/bootstrap.sh +35 -0
  20. data/vendor/gems/thrift/cleanup.sh +58 -0
  21. data/vendor/gems/thrift/compiler/cpp/Makefile.am +136 -0
  22. data/vendor/gems/thrift/compiler/cpp/README +39 -0
  23. data/vendor/gems/thrift/compiler/cpp/src/generate/t_cocoa_generator.cc +2331 -0
  24. data/vendor/gems/thrift/compiler/cpp/src/generate/t_cpp_generator.cc +3003 -0
  25. data/vendor/gems/thrift/compiler/cpp/src/generate/t_csharp_generator.cc +1700 -0
  26. data/vendor/gems/thrift/compiler/cpp/src/generate/t_erl_generator.cc +932 -0
  27. data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.cc +173 -0
  28. data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.h +321 -0
  29. data/vendor/gems/thrift/compiler/cpp/src/generate/t_hs_generator.cc +1445 -0
  30. data/vendor/gems/thrift/compiler/cpp/src/generate/t_html_generator.cc +637 -0
  31. data/vendor/gems/thrift/compiler/cpp/src/generate/t_java_generator.cc +3069 -0
  32. data/vendor/gems/thrift/compiler/cpp/src/generate/t_ocaml_generator.cc +1673 -0
  33. data/vendor/gems/thrift/compiler/cpp/src/generate/t_oop_generator.h +77 -0
  34. data/vendor/gems/thrift/compiler/cpp/src/generate/t_perl_generator.cc +1812 -0
  35. data/vendor/gems/thrift/compiler/cpp/src/generate/t_php_generator.cc +2281 -0
  36. data/vendor/gems/thrift/compiler/cpp/src/generate/t_py_generator.cc +2310 -0
  37. data/vendor/gems/thrift/compiler/cpp/src/generate/t_rb_generator.cc +1114 -0
  38. data/vendor/gems/thrift/compiler/cpp/src/generate/t_st_generator.cc +1071 -0
  39. data/vendor/gems/thrift/compiler/cpp/src/generate/t_xsd_generator.cc +354 -0
  40. data/vendor/gems/thrift/compiler/cpp/src/globals.h +117 -0
  41. data/vendor/gems/thrift/compiler/cpp/src/main.cc +1207 -0
  42. data/vendor/gems/thrift/compiler/cpp/src/main.h +103 -0
  43. data/vendor/gems/thrift/compiler/cpp/src/md5.c +381 -0
  44. data/vendor/gems/thrift/compiler/cpp/src/md5.h +91 -0
  45. data/vendor/gems/thrift/compiler/cpp/src/parse/t_base_type.h +137 -0
  46. data/vendor/gems/thrift/compiler/cpp/src/parse/t_const.h +59 -0
  47. data/vendor/gems/thrift/compiler/cpp/src/parse/t_const_value.h +121 -0
  48. data/vendor/gems/thrift/compiler/cpp/src/parse/t_container.h +56 -0
  49. data/vendor/gems/thrift/compiler/cpp/src/parse/t_doc.h +51 -0
  50. data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum.h +59 -0
  51. data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum_value.h +64 -0
  52. data/vendor/gems/thrift/compiler/cpp/src/parse/t_field.h +150 -0
  53. data/vendor/gems/thrift/compiler/cpp/src/parse/t_function.h +93 -0
  54. data/vendor/gems/thrift/compiler/cpp/src/parse/t_list.h +56 -0
  55. data/vendor/gems/thrift/compiler/cpp/src/parse/t_map.h +64 -0
  56. data/vendor/gems/thrift/compiler/cpp/src/parse/t_program.h +223 -0
  57. data/vendor/gems/thrift/compiler/cpp/src/parse/t_scope.h +86 -0
  58. data/vendor/gems/thrift/compiler/cpp/src/parse/t_service.h +68 -0
  59. data/vendor/gems/thrift/compiler/cpp/src/parse/t_set.h +55 -0
  60. data/vendor/gems/thrift/compiler/cpp/src/parse/t_struct.h +127 -0
  61. data/vendor/gems/thrift/compiler/cpp/src/parse/t_type.h +176 -0
  62. data/vendor/gems/thrift/compiler/cpp/src/parse/t_typedef.h +70 -0
  63. data/vendor/gems/thrift/compiler/cpp/src/platform.h +36 -0
  64. data/vendor/gems/thrift/compiler/cpp/src/thriftl.ll +303 -0
  65. data/vendor/gems/thrift/compiler/cpp/src/thrifty.yy +1140 -0
  66. data/vendor/gems/thrift/configure.ac +255 -0
  67. data/vendor/gems/thrift/contrib/fb303/LICENSE +16 -0
  68. data/vendor/gems/thrift/contrib/fb303/Makefile.am +31 -0
  69. data/vendor/gems/thrift/contrib/fb303/README +37 -0
  70. data/vendor/gems/thrift/contrib/fb303/acinclude.m4 +258 -0
  71. data/vendor/gems/thrift/contrib/fb303/aclocal/ax_boost_base.m4 +198 -0
  72. data/vendor/gems/thrift/contrib/fb303/bootstrap.sh +26 -0
  73. data/vendor/gems/thrift/contrib/fb303/configure.ac +115 -0
  74. data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.cpp +124 -0
  75. data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.h +103 -0
  76. data/vendor/gems/thrift/contrib/fb303/cpp/Makefile.am +84 -0
  77. data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.cpp +481 -0
  78. data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.h +215 -0
  79. data/vendor/gems/thrift/contrib/fb303/global_footer.mk +21 -0
  80. data/vendor/gems/thrift/contrib/fb303/global_header.mk +38 -0
  81. data/vendor/gems/thrift/contrib/fb303/if/fb303.thrift +112 -0
  82. data/vendor/gems/thrift/contrib/fb303/java/FacebookBase.java +103 -0
  83. data/vendor/gems/thrift/contrib/fb303/java/build.xml +84 -0
  84. data/vendor/gems/thrift/contrib/fb303/php/FacebookBase.php +89 -0
  85. data/vendor/gems/thrift/contrib/fb303/py/Makefile.am +44 -0
  86. data/vendor/gems/thrift/contrib/fb303/py/fb303/FacebookBase.py +82 -0
  87. data/vendor/gems/thrift/contrib/fb303/py/fb303_scripts/__init__.py +20 -0
  88. data/vendor/gems/thrift/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py +195 -0
  89. data/vendor/gems/thrift/contrib/fb303/py/setup.py +27 -0
  90. data/vendor/gems/thrift/contrib/thrift.el +126 -0
  91. data/vendor/gems/thrift/contrib/thrift.spec +206 -0
  92. data/vendor/gems/thrift/contrib/thrift.vim +91 -0
  93. data/vendor/gems/thrift/contrib/thrift_dump.cpp +91 -0
  94. data/vendor/gems/thrift/doc/lgpl-2.1.txt +504 -0
  95. data/vendor/gems/thrift/doc/otp-base-license.txt +20 -0
  96. data/vendor/gems/thrift/doc/thrift.bnf +96 -0
  97. data/vendor/gems/thrift/doc/thrift.tex +1057 -0
  98. data/vendor/gems/thrift/lib/Makefile.am +55 -0
  99. data/vendor/gems/thrift/lib/cocoa/README +21 -0
  100. data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.h +44 -0
  101. data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.m +130 -0
  102. data/vendor/gems/thrift/lib/cocoa/src/TException.h +34 -0
  103. data/vendor/gems/thrift/lib/cocoa/src/TException.m +64 -0
  104. data/vendor/gems/thrift/lib/cocoa/src/TProcessor.h +29 -0
  105. data/vendor/gems/thrift/lib/cocoa/src/TProcessorFactory.h +27 -0
  106. data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.h +27 -0
  107. data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.m +51 -0
  108. data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.h +51 -0
  109. data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.m +477 -0
  110. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocol.h +148 -0
  111. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolException.h +25 -0
  112. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolException.m +23 -0
  113. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolFactory.h +29 -0
  114. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.h +29 -0
  115. data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.m +104 -0
  116. data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.h +50 -0
  117. data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.m +153 -0
  118. data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.h +42 -0
  119. data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.m +159 -0
  120. data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.h +35 -0
  121. data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.m +91 -0
  122. data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.h +38 -0
  123. data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.m +89 -0
  124. data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.h +32 -0
  125. data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.m +58 -0
  126. data/vendor/gems/thrift/lib/cocoa/src/transport/TTransport.h +36 -0
  127. data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.h +30 -0
  128. data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.m +43 -0
  129. data/vendor/gems/thrift/lib/cpp/Makefile.am +158 -0
  130. data/vendor/gems/thrift/lib/cpp/README +67 -0
  131. data/vendor/gems/thrift/lib/cpp/src/TLogging.h +163 -0
  132. data/vendor/gems/thrift/lib/cpp/src/TProcessor.h +53 -0
  133. data/vendor/gems/thrift/lib/cpp/src/TReflectionLocal.h +96 -0
  134. data/vendor/gems/thrift/lib/cpp/src/Thrift.cpp +148 -0
  135. data/vendor/gems/thrift/lib/cpp/src/Thrift.h +191 -0
  136. data/vendor/gems/thrift/lib/cpp/src/concurrency/Exception.h +60 -0
  137. data/vendor/gems/thrift/lib/cpp/src/concurrency/FunctionRunner.h +77 -0
  138. data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.cpp +137 -0
  139. data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.h +84 -0
  140. data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.cpp +160 -0
  141. data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.h +114 -0
  142. data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.cpp +314 -0
  143. data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.h +130 -0
  144. data/vendor/gems/thrift/lib/cpp/src/concurrency/Thread.h +125 -0
  145. data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.cpp +493 -0
  146. data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.h +169 -0
  147. data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.cpp +284 -0
  148. data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.h +122 -0
  149. data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.cpp +55 -0
  150. data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.h +100 -0
  151. data/vendor/gems/thrift/lib/cpp/src/concurrency/test/Tests.cpp +155 -0
  152. data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadFactoryTests.h +354 -0
  153. data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadManagerTests.h +379 -0
  154. data/vendor/gems/thrift/lib/cpp/src/concurrency/test/TimerManagerTests.h +155 -0
  155. data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.cpp +122 -0
  156. data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.h +77 -0
  157. data/vendor/gems/thrift/lib/cpp/src/processor/StatsProcessor.h +264 -0
  158. data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.cpp +79 -0
  159. data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.h +42 -0
  160. data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.cpp +394 -0
  161. data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.h +254 -0
  162. data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.cpp +736 -0
  163. data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.h +279 -0
  164. data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.cpp +346 -0
  165. data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.h +225 -0
  166. data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.cpp +762 -0
  167. data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.h +253 -0
  168. data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.cpp +998 -0
  169. data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.h +340 -0
  170. data/vendor/gems/thrift/lib/cpp/src/protocol/TOneWayProtocol.h +304 -0
  171. data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocol.h +438 -0
  172. data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolException.h +104 -0
  173. data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolTap.h +187 -0
  174. data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.cpp +750 -0
  175. data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.h +435 -0
  176. data/vendor/gems/thrift/lib/cpp/src/server/TServer.cpp +38 -0
  177. data/vendor/gems/thrift/lib/cpp/src/server/TServer.h +213 -0
  178. data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.cpp +118 -0
  179. data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.h +70 -0
  180. data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.cpp +217 -0
  181. data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.h +79 -0
  182. data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.cpp +243 -0
  183. data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.h +74 -0
  184. data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.cpp +370 -0
  185. data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.h +667 -0
  186. data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.cpp +77 -0
  187. data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.h +73 -0
  188. data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.cpp +953 -0
  189. data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.h +442 -0
  190. data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.cpp +348 -0
  191. data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.h +111 -0
  192. data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.cpp +368 -0
  193. data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.h +76 -0
  194. data/vendor/gems/thrift/lib/cpp/src/transport/TServerTransport.h +92 -0
  195. data/vendor/gems/thrift/lib/cpp/src/transport/TShortReadTransport.h +96 -0
  196. data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.cpp +54 -0
  197. data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.h +41 -0
  198. data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.cpp +591 -0
  199. data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.h +242 -0
  200. data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.cpp +235 -0
  201. data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.h +191 -0
  202. data/vendor/gems/thrift/lib/cpp/src/transport/TTransport.h +224 -0
  203. data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.cpp +31 -0
  204. data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.h +117 -0
  205. data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.cpp +178 -0
  206. data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.h +287 -0
  207. data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.cpp +299 -0
  208. data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.h +219 -0
  209. data/vendor/gems/thrift/lib/cpp/thrift-nb.pc.in +30 -0
  210. data/vendor/gems/thrift/lib/cpp/thrift-z.pc.in +30 -0
  211. data/vendor/gems/thrift/lib/cpp/thrift.pc.in +29 -0
  212. data/vendor/gems/thrift/lib/csharp/Makefile.am +70 -0
  213. data/vendor/gems/thrift/lib/csharp/README +26 -0
  214. data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs +55 -0
  215. data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs +242 -0
  216. data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj +62 -0
  217. data/vendor/gems/thrift/lib/csharp/src/Collections/THashSet.cs +142 -0
  218. data/vendor/gems/thrift/lib/csharp/src/Protocol/TBase.cs +34 -0
  219. data/vendor/gems/thrift/lib/csharp/src/Protocol/TBinaryProtocol.cs +392 -0
  220. data/vendor/gems/thrift/lib/csharp/src/Protocol/TField.cs +58 -0
  221. data/vendor/gems/thrift/lib/csharp/src/Protocol/TList.cs +50 -0
  222. data/vendor/gems/thrift/lib/csharp/src/Protocol/TMap.cs +58 -0
  223. data/vendor/gems/thrift/lib/csharp/src/Protocol/TMessage.cs +58 -0
  224. data/vendor/gems/thrift/lib/csharp/src/Protocol/TMessageType.cs +31 -0
  225. data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocol.cs +87 -0
  226. data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolException.cs +61 -0
  227. data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolFactory.cs +29 -0
  228. data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolUtil.cs +94 -0
  229. data/vendor/gems/thrift/lib/csharp/src/Protocol/TSet.cs +50 -0
  230. data/vendor/gems/thrift/lib/csharp/src/Protocol/TStruct.cs +42 -0
  231. data/vendor/gems/thrift/lib/csharp/src/Protocol/TType.cs +40 -0
  232. data/vendor/gems/thrift/lib/csharp/src/Server/TServer.cs +135 -0
  233. data/vendor/gems/thrift/lib/csharp/src/Server/TSimpleServer.cs +148 -0
  234. data/vendor/gems/thrift/lib/csharp/src/Server/TThreadPoolServer.cs +186 -0
  235. data/vendor/gems/thrift/lib/csharp/src/Server/TThreadedServer.cs +234 -0
  236. data/vendor/gems/thrift/lib/csharp/src/TApplicationException.cs +131 -0
  237. data/vendor/gems/thrift/lib/csharp/src/TProcessor.cs +29 -0
  238. data/vendor/gems/thrift/lib/csharp/src/Thrift.csproj +73 -0
  239. data/vendor/gems/thrift/lib/csharp/src/Thrift.sln +35 -0
  240. data/vendor/gems/thrift/lib/csharp/src/Transport/TBufferedTransport.cs +100 -0
  241. data/vendor/gems/thrift/lib/csharp/src/Transport/TServerSocket.cs +157 -0
  242. data/vendor/gems/thrift/lib/csharp/src/Transport/TServerTransport.cs +39 -0
  243. data/vendor/gems/thrift/lib/csharp/src/Transport/TSocket.cs +144 -0
  244. data/vendor/gems/thrift/lib/csharp/src/Transport/TStreamTransport.cs +103 -0
  245. data/vendor/gems/thrift/lib/csharp/src/Transport/TTransport.cs +66 -0
  246. data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportException.cs +64 -0
  247. data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportFactory.cs +38 -0
  248. data/vendor/gems/thrift/lib/erl/Makefile +37 -0
  249. data/vendor/gems/thrift/lib/erl/README +56 -0
  250. data/vendor/gems/thrift/lib/erl/build/beamver +59 -0
  251. data/vendor/gems/thrift/lib/erl/build/buildtargets.mk +15 -0
  252. data/vendor/gems/thrift/lib/erl/build/colors.mk +24 -0
  253. data/vendor/gems/thrift/lib/erl/build/docs.mk +12 -0
  254. data/vendor/gems/thrift/lib/erl/build/mime.types +98 -0
  255. data/vendor/gems/thrift/lib/erl/build/otp.mk +146 -0
  256. data/vendor/gems/thrift/lib/erl/build/otp_subdir.mk +85 -0
  257. data/vendor/gems/thrift/lib/erl/build/raw_test.mk +29 -0
  258. data/vendor/gems/thrift/lib/erl/include/thrift_constants.hrl +54 -0
  259. data/vendor/gems/thrift/lib/erl/include/thrift_protocol.hrl +31 -0
  260. data/vendor/gems/thrift/lib/erl/src/Makefile +116 -0
  261. data/vendor/gems/thrift/lib/erl/src/test_handler.erl +26 -0
  262. data/vendor/gems/thrift/lib/erl/src/test_service.erl +29 -0
  263. data/vendor/gems/thrift/lib/erl/src/thrift.app.src +44 -0
  264. data/vendor/gems/thrift/lib/erl/src/thrift.appup.src +1 -0
  265. data/vendor/gems/thrift/lib/erl/src/thrift_base64_transport.erl +64 -0
  266. data/vendor/gems/thrift/lib/erl/src/thrift_binary_protocol.erl +325 -0
  267. data/vendor/gems/thrift/lib/erl/src/thrift_buffered_transport.erl +180 -0
  268. data/vendor/gems/thrift/lib/erl/src/thrift_client.erl +384 -0
  269. data/vendor/gems/thrift/lib/erl/src/thrift_disk_log_transport.erl +118 -0
  270. data/vendor/gems/thrift/lib/erl/src/thrift_file_transport.erl +87 -0
  271. data/vendor/gems/thrift/lib/erl/src/thrift_framed_transport.erl +208 -0
  272. data/vendor/gems/thrift/lib/erl/src/thrift_http_transport.erl +199 -0
  273. data/vendor/gems/thrift/lib/erl/src/thrift_memory_buffer.erl +164 -0
  274. data/vendor/gems/thrift/lib/erl/src/thrift_processor.erl +188 -0
  275. data/vendor/gems/thrift/lib/erl/src/thrift_protocol.erl +356 -0
  276. data/vendor/gems/thrift/lib/erl/src/thrift_server.erl +183 -0
  277. data/vendor/gems/thrift/lib/erl/src/thrift_service.erl +25 -0
  278. data/vendor/gems/thrift/lib/erl/src/thrift_socket_server.erl +249 -0
  279. data/vendor/gems/thrift/lib/erl/src/thrift_socket_transport.erl +119 -0
  280. data/vendor/gems/thrift/lib/erl/src/thrift_transport.erl +57 -0
  281. data/vendor/gems/thrift/lib/erl/vsn.mk +1 -0
  282. data/vendor/gems/thrift/lib/hs/README +82 -0
  283. data/vendor/gems/thrift/lib/hs/Setup.lhs +23 -0
  284. data/vendor/gems/thrift/lib/hs/TODO +2 -0
  285. data/vendor/gems/thrift/lib/hs/Thrift.cabal +20 -0
  286. data/vendor/gems/thrift/lib/hs/src/Thrift.hs +111 -0
  287. data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol.hs +191 -0
  288. data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol/Binary.hs +147 -0
  289. data/vendor/gems/thrift/lib/hs/src/Thrift/Server.hs +65 -0
  290. data/vendor/gems/thrift/lib/hs/src/Thrift/Transport.hs +60 -0
  291. data/vendor/gems/thrift/lib/hs/src/Thrift/Transport/Handle.hs +58 -0
  292. data/vendor/gems/thrift/lib/java/Makefile.am +38 -0
  293. data/vendor/gems/thrift/lib/java/README +43 -0
  294. data/vendor/gems/thrift/lib/java/build.xml +195 -0
  295. data/vendor/gems/thrift/lib/java/ivy.xml +8 -0
  296. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/IntRangeSet.java +171 -0
  297. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TApplicationException.java +123 -0
  298. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBase.java +66 -0
  299. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBaseHelper.java +102 -0
  300. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TByteArrayOutputStream.java +46 -0
  301. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TDeserializer.java +94 -0
  302. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TException.java +45 -0
  303. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TFieldRequirementType.java +30 -0
  304. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessor.java +32 -0
  305. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessorFactory.java +39 -0
  306. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TSerializer.java +110 -0
  307. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldMetaData.java +69 -0
  308. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldValueMetaData.java +42 -0
  309. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/ListMetaData.java +29 -0
  310. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/MapMetaData.java +31 -0
  311. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/SetMetaData.java +29 -0
  312. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/StructMetaData.java +31 -0
  313. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBase64Utils.java +128 -0
  314. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java +331 -0
  315. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java +741 -0
  316. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TField.java +48 -0
  317. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java +927 -0
  318. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TList.java +38 -0
  319. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMap.java +40 -0
  320. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessage.java +48 -0
  321. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessageType.java +31 -0
  322. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocol.java +146 -0
  323. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolException.java +81 -0
  324. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolFactory.java +30 -0
  325. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolUtil.java +158 -0
  326. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSet.java +42 -0
  327. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java +384 -0
  328. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TStruct.java +36 -0
  329. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TType.java +40 -0
  330. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/THsHaServer.java +304 -0
  331. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TNonblockingServer.java +772 -0
  332. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TServer.java +126 -0
  333. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TSimpleServer.java +145 -0
  334. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java +271 -0
  335. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TFramedTransport.java +126 -0
  336. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/THttpClient.java +157 -0
  337. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TIOStreamTransport.java +159 -0
  338. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TMemoryBuffer.java +98 -0
  339. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerSocket.java +160 -0
  340. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerTransport.java +31 -0
  341. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java +213 -0
  342. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingTransport.java +31 -0
  343. data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TServerSocket.java +145 -0
  344. metadata +348 -37
  345. data/vendor/gems/trollop/FAQ.txt +0 -35
  346. data/vendor/gems/trollop/History.txt +0 -84
  347. data/vendor/gems/trollop/Manifest.txt +0 -7
  348. data/vendor/gems/trollop/README.txt +0 -38
  349. data/vendor/gems/trollop/Rakefile +0 -36
  350. data/vendor/gems/trollop/lib/trollop.rb +0 -695
  351. data/vendor/gems/trollop/release-script.txt +0 -13
  352. data/vendor/gems/trollop/test/test_trollop.rb +0 -957
  353. data/vendor/gems/trollop/www/index.html +0 -167
@@ -0,0 +1,1700 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ #include <string>
21
+ #include <fstream>
22
+ #include <iostream>
23
+ #include <vector>
24
+
25
+ #include <stdlib.h>
26
+ #include <sys/stat.h>
27
+ #include <sstream>
28
+
29
+ #include "platform.h"
30
+ #include "t_oop_generator.h"
31
+ using namespace std;
32
+
33
+
34
+ class t_csharp_generator : public t_oop_generator
35
+ {
36
+ public:
37
+ t_csharp_generator(
38
+ t_program* program,
39
+ const std::map<std::string, std::string>& parsed_options,
40
+ const std::string& option_string)
41
+ : t_oop_generator(program)
42
+ {
43
+ out_dir_base_ = "gen-csharp";
44
+ }
45
+ void init_generator();
46
+ void close_generator();
47
+
48
+ void generate_consts(std::vector<t_const*> consts);
49
+
50
+ void generate_typedef (t_typedef* ttypedef);
51
+ void generate_enum (t_enum* tenum);
52
+ void generate_struct (t_struct* tstruct);
53
+ void generate_xception (t_struct* txception);
54
+ void generate_service (t_service* tservice);
55
+ void generate_property(ofstream& out, t_field* tfield, bool isPublic);
56
+ bool print_const_value (std::ofstream& out, std::string name, t_type* type, t_const_value* value, bool in_static, bool defval=false, bool needtype=false);
57
+ std::string render_const_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value);
58
+ void print_const_constructor(std::ofstream& out, std::vector<t_const*> consts);
59
+ void print_const_def_value(std::ofstream& out, std::string name, t_type* type, t_const_value* value);
60
+
61
+ void generate_csharp_struct(t_struct* tstruct, bool is_exception);
62
+ void generate_csharp_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false, bool in_class=false, bool is_result=false);
63
+ void generate_csharp_struct_reader(std::ofstream& out, t_struct* tstruct);
64
+ void generate_csharp_struct_result_writer(std::ofstream& out, t_struct* tstruct);
65
+ void generate_csharp_struct_writer(std::ofstream& out, t_struct* tstruct);
66
+ void generate_csharp_struct_tostring(std::ofstream& out, t_struct* tstruct);
67
+
68
+ void generate_function_helpers(t_function* tfunction);
69
+ void generate_service_interface (t_service* tservice);
70
+ void generate_service_helpers (t_service* tservice);
71
+ void generate_service_client (t_service* tservice);
72
+ void generate_service_server (t_service* tservice);
73
+ void generate_process_function (t_service* tservice, t_function* function);
74
+
75
+ void generate_deserialize_field (std::ofstream& out, t_field* tfield, std::string prefix="");
76
+ void generate_deserialize_struct (std::ofstream& out, t_struct* tstruct, std::string prefix="");
77
+ void generate_deserialize_container (std::ofstream& out, t_type* ttype, std::string prefix="");
78
+ void generate_deserialize_set_element (std::ofstream& out, t_set* tset, std::string prefix="");
79
+ void generate_deserialize_map_element (std::ofstream& out, t_map* tmap, std::string prefix="");
80
+ void generate_deserialize_list_element (std::ofstream& out, t_list* list, std::string prefix="");
81
+ void generate_serialize_field (std::ofstream& out, t_field* tfield, std::string prefix="");
82
+ void generate_serialize_struct (std::ofstream& out, t_struct* tstruct, std::string prefix="");
83
+ void generate_serialize_container (std::ofstream& out, t_type* ttype, std::string prefix="");
84
+ void generate_serialize_map_element (std::ofstream& out, t_map* tmap, std::string iter, std::string map);
85
+ void generate_serialize_set_element (std::ofstream& out, t_set* tmap, std::string iter);
86
+ void generate_serialize_list_element (std::ofstream& out, t_list* tlist, std::string iter);
87
+
88
+ void start_csharp_namespace (std::ofstream& out);
89
+ void end_csharp_namespace (std::ofstream& out);
90
+
91
+ std::string csharp_type_usings();
92
+ std::string csharp_thrift_usings();
93
+
94
+ std::string type_name(t_type* ttype, bool in_countainer=false, bool in_init=false);
95
+ std::string base_type_name(t_base_type* tbase, bool in_container=false);
96
+ std::string declare_field(t_field* tfield, bool init=false);
97
+ std::string function_signature(t_function* tfunction, std::string prefix="");
98
+ std::string argument_list(t_struct* tstruct);
99
+ std::string type_to_enum(t_type* ttype);
100
+ std::string prop_name(t_field* tfield);
101
+
102
+ bool type_can_be_null(t_type* ttype) {
103
+ while (ttype->is_typedef()) {
104
+ ttype = ((t_typedef*)ttype)->get_type();
105
+ }
106
+
107
+ return ttype->is_container() ||
108
+ ttype->is_struct() ||
109
+ ttype->is_xception() ||
110
+ ttype->is_string();
111
+ }
112
+
113
+ private:
114
+ std::string namespace_name_;
115
+ std::ofstream f_service_;
116
+ std::string namespace_dir_;
117
+ };
118
+
119
+
120
+ void t_csharp_generator::init_generator() {
121
+ MKDIR(get_out_dir().c_str());
122
+ namespace_name_ = program_->get_namespace("csharp");
123
+
124
+ string dir = namespace_name_;
125
+ string subdir = get_out_dir().c_str();
126
+ string::size_type loc;
127
+
128
+ while ((loc = dir.find(".")) != string::npos) {
129
+ subdir = subdir + "/" + dir.substr(0, loc);
130
+ MKDIR(subdir.c_str());
131
+ dir = dir.substr(loc + 1);
132
+ }
133
+ if (dir.size() > 0) {
134
+ subdir = subdir + "/" + dir;
135
+ MKDIR(subdir.c_str());
136
+ }
137
+
138
+ namespace_dir_ = subdir;
139
+ }
140
+
141
+ void t_csharp_generator::start_csharp_namespace(ofstream& out) {
142
+ if (!namespace_name_.empty()) {
143
+ out <<
144
+ "namespace " << namespace_name_ << "\n";
145
+ scope_up(out);
146
+ }
147
+ }
148
+
149
+ void t_csharp_generator::end_csharp_namespace(ofstream& out) {
150
+ if (!namespace_name_.empty()) {
151
+ scope_down(out);
152
+ }
153
+ }
154
+
155
+ string t_csharp_generator::csharp_type_usings() {
156
+ return string() +
157
+ "using System;\n" +
158
+ "using System.Collections;\n" +
159
+ "using System.Collections.Generic;\n" +
160
+ "using System.Text;\n" +
161
+ "using System.IO;\n" +
162
+ "using Thrift;\n" +
163
+ "using Thrift.Collections;\n";
164
+ }
165
+
166
+ string t_csharp_generator::csharp_thrift_usings() {
167
+ return string() +
168
+ "using Thrift.Protocol;\n" +
169
+ "using Thrift.Transport;\n";
170
+ }
171
+
172
+ void t_csharp_generator::close_generator() { }
173
+ void t_csharp_generator::generate_typedef(t_typedef* ttypedef) {}
174
+
175
+ void t_csharp_generator::generate_enum(t_enum* tenum) {
176
+ string f_enum_name = namespace_dir_+"/" + (tenum->get_name())+".cs";
177
+ ofstream f_enum;
178
+ f_enum.open(f_enum_name.c_str());
179
+
180
+ f_enum <<
181
+ autogen_comment() << endl;
182
+
183
+ start_csharp_namespace(f_enum);
184
+
185
+ indent(f_enum) <<
186
+ "public enum " << tenum->get_name() << "\n";
187
+ scope_up(f_enum);
188
+
189
+ vector<t_enum_value*> constants = tenum->get_constants();
190
+ vector<t_enum_value*>::iterator c_iter;
191
+ int value = -1;
192
+ for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter)
193
+ {
194
+ if ((*c_iter)->has_value()) {
195
+ value = (*c_iter)->get_value();
196
+ } else {
197
+ ++value;
198
+ }
199
+
200
+ indent(f_enum) <<
201
+ (*c_iter)->get_name() <<
202
+ " = " << value << "," << endl;
203
+ }
204
+
205
+ scope_down(f_enum);
206
+
207
+ end_csharp_namespace(f_enum);
208
+
209
+ f_enum.close();
210
+ }
211
+
212
+ void t_csharp_generator::generate_consts(std::vector<t_const*> consts) {
213
+ if (consts.empty()){
214
+ return;
215
+ }
216
+ string f_consts_name = namespace_dir_ + "/Constants.cs";
217
+ ofstream f_consts;
218
+ f_consts.open(f_consts_name.c_str());
219
+
220
+ f_consts <<
221
+ autogen_comment() <<
222
+ csharp_type_usings() << endl;
223
+
224
+ start_csharp_namespace(f_consts);
225
+
226
+ indent(f_consts) <<
227
+ "public class Constants" << endl;
228
+ scope_up(f_consts);
229
+
230
+ vector<t_const*>::iterator c_iter;
231
+ bool need_static_constructor = false;
232
+ for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
233
+ if (print_const_value(f_consts, (*c_iter)->get_name(), (*c_iter)->get_type(), (*c_iter)->get_value(), false)) {
234
+ need_static_constructor = true;
235
+ }
236
+ }
237
+
238
+ if (need_static_constructor) {
239
+ print_const_constructor(f_consts, consts);
240
+ }
241
+
242
+ scope_down(f_consts);
243
+ end_csharp_namespace(f_consts);
244
+ f_consts.close();
245
+ }
246
+
247
+ void t_csharp_generator::print_const_def_value(std::ofstream& out, string name, t_type* type, t_const_value* value)
248
+ {
249
+ if (type->is_struct() || type->is_xception()) {
250
+ const vector<t_field*>& fields = ((t_struct*)type)->get_members();
251
+ vector<t_field*>::const_iterator f_iter;
252
+ const map<t_const_value*, t_const_value*>& val = value->get_map();
253
+ map<t_const_value*, t_const_value*>::const_iterator v_iter;
254
+ for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
255
+ t_type* field_type = NULL;
256
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
257
+ if ((*f_iter)->get_name() == v_iter->first->get_string()) {
258
+ field_type = (*f_iter)->get_type();
259
+ }
260
+ }
261
+ if (field_type == NULL) {
262
+ throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
263
+ }
264
+ string val = render_const_value(out, name, field_type, v_iter->second);
265
+ indent(out) << name << "." << v_iter->first->get_string() << " = " << val << ";" << endl;
266
+ }
267
+ } else if (type->is_map()) {
268
+ t_type* ktype = ((t_map*)type)->get_key_type();
269
+ t_type* vtype = ((t_map*)type)->get_val_type();
270
+ const map<t_const_value*, t_const_value*>& val = value->get_map();
271
+ map<t_const_value*, t_const_value*>::const_iterator v_iter;
272
+ for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
273
+ string key = render_const_value(out, name, ktype, v_iter->first);
274
+ string val = render_const_value(out, name, vtype, v_iter->second);
275
+ indent(out) << name << "[" << key << "]" << " = " << val << ";" << endl;
276
+ }
277
+ } else if (type->is_list() || type->is_set()) {
278
+ t_type* etype;
279
+ if (type->is_list()) {
280
+ etype = ((t_list*)type)->get_elem_type();
281
+ } else {
282
+ etype = ((t_set*)type)->get_elem_type();
283
+ }
284
+
285
+ const vector<t_const_value*>& val = value->get_list();
286
+ vector<t_const_value*>::const_iterator v_iter;
287
+ for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
288
+ string val = render_const_value(out, name, etype, *v_iter);
289
+ indent(out) << name << ".Add(" << val << ");" << endl;
290
+ }
291
+ }
292
+ }
293
+
294
+ void t_csharp_generator::print_const_constructor(std::ofstream& out, std::vector<t_const*> consts) {
295
+ indent(out) << "static Constants()" << endl;
296
+ scope_up(out);
297
+ vector<t_const*>::iterator c_iter;
298
+ for (c_iter = consts.begin(); c_iter != consts.end(); ++c_iter) {
299
+ string name = (*c_iter)->get_name();
300
+ t_type* type = (*c_iter)->get_type();
301
+ t_const_value* value = (*c_iter)->get_value();
302
+
303
+ print_const_def_value(out, name, type, value);
304
+ }
305
+ scope_down(out);
306
+ }
307
+
308
+
309
+ //it seems like all that methods that call this are using in_static to be the opposite of what it would imply
310
+ bool t_csharp_generator::print_const_value(std::ofstream& out, string name, t_type* type, t_const_value* value, bool in_static, bool defval, bool needtype) {
311
+ indent(out);
312
+ bool need_static_construction = !in_static;
313
+ if (!defval || needtype) {
314
+ out <<
315
+ (in_static ? "" : "public static ") <<
316
+ type_name(type) << " ";
317
+ }
318
+ if (type->is_base_type()) {
319
+ string v2 = render_const_value(out, name, type, value);
320
+ out << name << " = " << v2 << ";" << endl;
321
+ need_static_construction = false;
322
+ } else if (type->is_enum()) {
323
+ out << name << " = (" << type_name(type, false, true) << ")" << value->get_integer() << ";" << endl;
324
+ need_static_construction = false;
325
+ } else if (type->is_struct() || type->is_xception()) {
326
+ out << name << " = new " << type_name(type) << "();" << endl;
327
+ } else if (type->is_map()) {
328
+ out << name << " = new " << type_name(type, true, true) << "();" << endl;
329
+ } else if (type->is_list() || type->is_set()) {
330
+ out << name << " = new " << type_name(type) << "();" << endl;
331
+ }
332
+
333
+ if (defval && !type->is_base_type() && !type->is_enum()) {
334
+ print_const_def_value(out, name, type, value);
335
+ }
336
+
337
+ return need_static_construction;
338
+ }
339
+
340
+ std::string t_csharp_generator::render_const_value(ofstream& out, string name, t_type* type, t_const_value* value) {
341
+ std::ostringstream render;
342
+
343
+ if (type->is_base_type()) {
344
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
345
+ switch (tbase) {
346
+ case t_base_type::TYPE_STRING:
347
+ render << '"' << get_escaped_string(value) << '"';
348
+ break;
349
+ case t_base_type::TYPE_BOOL:
350
+ render << ((value->get_integer() > 0) ? "true" : "false");
351
+ break;
352
+ case t_base_type::TYPE_BYTE:
353
+ case t_base_type::TYPE_I16:
354
+ case t_base_type::TYPE_I32:
355
+ case t_base_type::TYPE_I64:
356
+ render << value->get_integer();
357
+ break;
358
+ case t_base_type::TYPE_DOUBLE:
359
+ if (value->get_type() == t_const_value::CV_INTEGER) {
360
+ render << value->get_integer();
361
+ } else {
362
+ render << value->get_double();
363
+ }
364
+ break;
365
+ default:
366
+ throw "compiler error: no const of base type " + tbase;
367
+ }
368
+ } else if (type->is_enum()) {
369
+ render << "(" << type->get_name() << ")" << value->get_integer();
370
+ } else {
371
+ string t = tmp("tmp");
372
+ print_const_value(out, t, type, value, true, true, true);
373
+ render << t;
374
+ }
375
+
376
+ return render.str();
377
+ }
378
+
379
+ void t_csharp_generator::generate_struct(t_struct* tstruct) {
380
+ generate_csharp_struct(tstruct, false);
381
+ }
382
+
383
+ void t_csharp_generator::generate_xception(t_struct* txception) {
384
+ generate_csharp_struct(txception, true);
385
+ }
386
+
387
+ void t_csharp_generator::generate_csharp_struct(t_struct* tstruct, bool is_exception) {
388
+ string f_struct_name = namespace_dir_ + "/" + (tstruct->get_name()) + ".cs";
389
+ ofstream f_struct;
390
+
391
+ f_struct.open(f_struct_name.c_str());
392
+
393
+ f_struct <<
394
+ autogen_comment() <<
395
+ csharp_type_usings() <<
396
+ csharp_thrift_usings();
397
+
398
+ generate_csharp_struct_definition(f_struct, tstruct, is_exception);
399
+
400
+ f_struct.close();
401
+ }
402
+
403
+ void t_csharp_generator::generate_csharp_struct_definition(ofstream &out, t_struct* tstruct, bool is_exception, bool in_class, bool is_result) {
404
+
405
+ if (!in_class) {
406
+ start_csharp_namespace(out);
407
+ }
408
+
409
+ out << endl;
410
+ indent(out) << "[Serializable]" << endl;
411
+ bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
412
+
413
+ indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " << tstruct->get_name() << " : ";
414
+
415
+ if (is_exception) {
416
+ out << "Exception, ";
417
+ }
418
+ out << "TBase";
419
+
420
+ out << endl;
421
+
422
+ scope_up(out);
423
+
424
+ const vector<t_field*>& members = tstruct->get_members();
425
+ vector<t_field*>::const_iterator m_iter;
426
+
427
+ //make private members with public Properties
428
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
429
+ indent(out) <<
430
+ "private " << declare_field(*m_iter, false) << endl;
431
+ }
432
+ out << endl;
433
+
434
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
435
+ generate_property(out, *m_iter, true);
436
+ }
437
+
438
+ if (members.size() > 0) {
439
+ out <<
440
+ endl <<
441
+ indent() << "public Isset __isset;" << endl <<
442
+ indent() << "[Serializable]" << endl <<
443
+ indent() << "public struct Isset {" << endl;
444
+ indent_up();
445
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
446
+ indent(out) <<
447
+ "public bool " << (*m_iter)->get_name() << ";" << endl;
448
+ }
449
+
450
+ indent_down();
451
+ indent(out) << "}" << endl << endl;
452
+ }
453
+
454
+ indent(out) <<
455
+ "public " << tstruct->get_name() << "() {" << endl;
456
+ indent_up();
457
+ for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
458
+ t_type* t = (*m_iter)->get_type();
459
+ while (t->is_typedef()) {
460
+ t = ((t_typedef*)t)->get_type();
461
+ }
462
+ if ((*m_iter)->get_value() != NULL) {
463
+ print_const_value(out, "this." + (*m_iter)->get_name(), t, (*m_iter)->get_value(), true, true);
464
+ }
465
+ }
466
+
467
+ indent_down();
468
+ indent(out) << "}" << endl << endl;
469
+
470
+ generate_csharp_struct_reader(out, tstruct);
471
+ if (is_result) {
472
+ generate_csharp_struct_result_writer(out, tstruct);
473
+ } else {
474
+ generate_csharp_struct_writer(out, tstruct);
475
+ }
476
+ generate_csharp_struct_tostring(out, tstruct);
477
+ scope_down(out);
478
+ out << endl;
479
+
480
+ if (!in_class)
481
+ {
482
+ end_csharp_namespace(out);
483
+ }
484
+ }
485
+
486
+ void t_csharp_generator::generate_csharp_struct_reader(ofstream& out, t_struct* tstruct) {
487
+ indent(out) <<
488
+ "public void Read (TProtocol iprot)" << endl;
489
+ scope_up(out);
490
+
491
+ const vector<t_field*>& fields = tstruct->get_members();
492
+ vector<t_field*>::const_iterator f_iter;
493
+
494
+ indent(out) <<
495
+ "TField field;" << endl <<
496
+ indent() << "iprot.ReadStructBegin();" << endl;
497
+
498
+ indent(out) <<
499
+ "while (true)" << endl;
500
+ scope_up(out);
501
+
502
+ indent(out) <<
503
+ "field = iprot.ReadFieldBegin();" << endl;
504
+
505
+ indent(out) <<
506
+ "if (field.Type == TType.Stop) { " << endl;
507
+ indent_up();
508
+ indent(out) <<
509
+ "break;" << endl;
510
+ indent_down();
511
+ indent(out) <<
512
+ "}" << endl;
513
+
514
+ indent(out) <<
515
+ "switch (field.ID)" << endl;
516
+
517
+ scope_up(out);
518
+
519
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
520
+ indent(out) <<
521
+ "case " << (*f_iter)->get_key() << ":" << endl;
522
+ indent_up();
523
+ indent(out) <<
524
+ "if (field.Type == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
525
+ indent_up();
526
+
527
+ generate_deserialize_field(out, *f_iter, "this.");
528
+ indent(out) <<
529
+ "this.__isset." << (*f_iter)->get_name() << " = true;" << endl;
530
+ indent_down();
531
+ out <<
532
+ indent() << "} else { " << endl <<
533
+ indent() << " TProtocolUtil.Skip(iprot, field.Type);" << endl <<
534
+ indent() << "}" << endl <<
535
+ indent() << "break;" << endl;
536
+ indent_down();
537
+ }
538
+
539
+ indent(out) <<
540
+ "default: " << endl;
541
+ indent_up();
542
+ indent(out) << "TProtocolUtil.Skip(iprot, field.Type);" << endl;
543
+ indent(out) << "break;" << endl;
544
+ indent_down();
545
+
546
+ scope_down(out);
547
+
548
+ indent(out) <<
549
+ "iprot.ReadFieldEnd();" << endl;
550
+
551
+ scope_down(out);
552
+
553
+ indent(out) <<
554
+ "iprot.ReadStructEnd();" << endl;
555
+
556
+ indent_down();
557
+
558
+ indent(out) << "}" << endl << endl;
559
+
560
+ }
561
+
562
+ void t_csharp_generator::generate_csharp_struct_writer(ofstream& out, t_struct* tstruct) {
563
+ out <<
564
+ indent() << "public void Write(TProtocol oprot) {" << endl;
565
+ indent_up();
566
+
567
+ string name = tstruct->get_name();
568
+ const vector<t_field*>& fields = tstruct->get_sorted_members();
569
+ vector<t_field*>::const_iterator f_iter;
570
+
571
+ indent(out) <<
572
+ "TStruct struc = new TStruct(\"" << name << "\");" << endl;
573
+ indent(out) <<
574
+ "oprot.WriteStructBegin(struc);" << endl;
575
+
576
+ if (fields.size() > 0) {
577
+ indent(out) << "TField field = new TField();" << endl;
578
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
579
+ bool null_allowed = type_can_be_null((*f_iter)->get_type());
580
+ if (null_allowed) {
581
+ indent(out) <<
582
+ "if (this." << (*f_iter)->get_name() << " != null && __isset." << (*f_iter)->get_name() << ") {" << endl;
583
+ indent_up();
584
+ }
585
+ else
586
+ {
587
+ indent(out) <<
588
+ "if (__isset." << (*f_iter)->get_name() << ") {" << endl;
589
+ indent_up();
590
+ }
591
+
592
+ indent(out) <<
593
+ "field.Name = \"" << (*f_iter)->get_name() << "\";" << endl;
594
+ indent(out) <<
595
+ "field.Type = " << type_to_enum((*f_iter)->get_type()) << ";" << endl;
596
+ indent(out) <<
597
+ "field.ID = " << (*f_iter)->get_key() << ";" << endl;
598
+ indent(out) <<
599
+ "oprot.WriteFieldBegin(field);" << endl;
600
+
601
+ generate_serialize_field(out, *f_iter, "this.");
602
+
603
+ indent(out) <<
604
+ "oprot.WriteFieldEnd();" << endl;
605
+
606
+ indent_down();
607
+ indent(out) << "}" << endl;
608
+ }
609
+ }
610
+
611
+ indent(out) <<
612
+ "oprot.WriteFieldStop();" << endl;
613
+ indent(out) <<
614
+ "oprot.WriteStructEnd();" << endl;
615
+
616
+ indent_down();
617
+
618
+ indent(out) <<
619
+ "}" << endl << endl;
620
+ }
621
+
622
+ void t_csharp_generator::generate_csharp_struct_result_writer(ofstream& out, t_struct* tstruct) {
623
+ indent(out) <<
624
+ "public void Write(TProtocol oprot) {" << endl;
625
+ indent_up();
626
+
627
+ string name = tstruct->get_name();
628
+ const vector<t_field*>& fields = tstruct->get_sorted_members();
629
+ vector<t_field*>::const_iterator f_iter;
630
+
631
+ indent(out) <<
632
+ "TStruct struc = new TStruct(\"" << name << "\");" << endl;
633
+ indent(out) <<
634
+ "oprot.WriteStructBegin(struc);" << endl;
635
+
636
+ if (fields.size() > 0) {
637
+ indent(out) << "TField field = new TField();" << endl;
638
+ bool first = true;
639
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
640
+ if (first) {
641
+ first = false;
642
+ out <<
643
+ endl << indent() << "if ";
644
+ } else {
645
+ out <<
646
+ " else if ";
647
+ }
648
+
649
+ out <<
650
+ "(this.__isset." << (*f_iter)->get_name() << ") {" << endl;
651
+ indent_up();
652
+
653
+ bool null_allowed = type_can_be_null((*f_iter)->get_type());
654
+ if (null_allowed) {
655
+ indent(out) <<
656
+ "if (this." << (*f_iter)->get_name() << " != null) {" << endl;
657
+ indent_up();
658
+ }
659
+
660
+ indent(out) <<
661
+ "field.Name = \"" << (*f_iter)->get_name() << "\";" << endl;
662
+ indent(out) <<
663
+ "field.Type = " << type_to_enum((*f_iter)->get_type()) << ";" << endl;
664
+ indent(out) <<
665
+ "field.ID = " << (*f_iter)->get_key() << ";" << endl;
666
+ indent(out) <<
667
+ "oprot.WriteFieldBegin(field);" << endl;
668
+
669
+ generate_serialize_field(out, *f_iter, "this.");
670
+
671
+ indent(out) <<
672
+ "oprot.WriteFieldEnd();" << endl;
673
+
674
+ if (null_allowed) {
675
+ indent_down();
676
+ indent(out) << "}" << endl;
677
+ }
678
+
679
+ indent_down();
680
+ indent(out) << "}";
681
+ }
682
+ }
683
+
684
+ out <<
685
+ endl <<
686
+ indent() << "oprot.WriteFieldStop();" << endl <<
687
+ indent() << "oprot.WriteStructEnd();" << endl;
688
+
689
+ indent_down();
690
+
691
+ indent(out) <<
692
+ "}" << endl << endl;
693
+ }
694
+
695
+ void t_csharp_generator::generate_csharp_struct_tostring(ofstream& out, t_struct* tstruct) {
696
+ indent(out) <<
697
+ "public override string ToString() {" << endl;
698
+ indent_up();
699
+
700
+ indent(out) <<
701
+ "StringBuilder sb = new StringBuilder(\"" << tstruct->get_name() << "(\");" << endl;
702
+
703
+ const vector<t_field*>& fields = tstruct->get_members();
704
+ vector<t_field*>::const_iterator f_iter;
705
+
706
+ bool first = true;
707
+
708
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
709
+ if (first) {
710
+ first = false;
711
+ indent(out) <<
712
+ "sb.Append(\"" << (*f_iter)->get_name() << ": \");" << endl;
713
+ } else {
714
+ indent(out) <<
715
+ "sb.Append(\"," << (*f_iter)->get_name() << ": \");" << endl;
716
+ }
717
+ t_type* ttype = (*f_iter)->get_type();
718
+ if (ttype->is_xception() || ttype->is_struct()) {
719
+ indent(out) <<
720
+ "sb.Append(this." << (*f_iter)->get_name() << "== null ? \"<null>\" : "<< "this." << (*f_iter)->get_name() << ".ToString());" << endl;
721
+ } else {
722
+ indent(out) <<
723
+ "sb.Append(this." << (*f_iter)->get_name() << ");" << endl;
724
+ }
725
+ }
726
+
727
+ indent(out) <<
728
+ "sb.Append(\")\");" << endl;
729
+ indent(out) <<
730
+ "return sb.ToString();" << endl;
731
+
732
+ indent_down();
733
+ indent(out) << "}" << endl << endl;
734
+ }
735
+
736
+ void t_csharp_generator::generate_service(t_service* tservice) {
737
+ string f_service_name = namespace_dir_ + "/" + service_name_ + ".cs";
738
+ f_service_.open(f_service_name.c_str());
739
+
740
+ f_service_ <<
741
+ autogen_comment() <<
742
+ csharp_type_usings() <<
743
+ csharp_thrift_usings();
744
+
745
+ start_csharp_namespace(f_service_);
746
+
747
+ indent(f_service_) <<
748
+ "public class " << service_name_ << " {" << endl;
749
+ indent_up();
750
+
751
+ generate_service_interface(tservice);
752
+ generate_service_client(tservice);
753
+ generate_service_server(tservice);
754
+ generate_service_helpers(tservice);
755
+
756
+ indent_down();
757
+
758
+ indent(f_service_) <<
759
+ "}" << endl;
760
+ end_csharp_namespace(f_service_);
761
+ f_service_.close();
762
+ }
763
+
764
+ void t_csharp_generator::generate_service_interface(t_service* tservice) {
765
+ string extends = "";
766
+ string extends_iface = "";
767
+ if (tservice->get_extends() != NULL) {
768
+ extends = type_name(tservice->get_extends());
769
+ extends_iface = " : " + extends + ".Iface";
770
+ }
771
+
772
+ indent(f_service_) <<
773
+ "public interface Iface" << extends_iface << " {" << endl;
774
+ indent_up();
775
+ vector<t_function*> functions = tservice->get_functions();
776
+ vector<t_function*>::iterator f_iter;
777
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter)
778
+ {
779
+ indent(f_service_) <<
780
+ function_signature(*f_iter) << ";" << endl;
781
+ }
782
+ indent_down();
783
+ f_service_ <<
784
+ indent() << "}" << endl << endl;
785
+ }
786
+
787
+ void t_csharp_generator::generate_service_helpers(t_service* tservice) {
788
+ vector<t_function*> functions = tservice->get_functions();
789
+ vector<t_function*>::iterator f_iter;
790
+
791
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
792
+ t_struct* ts = (*f_iter)->get_arglist();
793
+ generate_csharp_struct_definition(f_service_, ts, false, true);
794
+ generate_function_helpers(*f_iter);
795
+ }
796
+ }
797
+
798
+ void t_csharp_generator::generate_service_client(t_service* tservice) {
799
+ string extends = "";
800
+ string extends_client = "";
801
+ if (tservice->get_extends() != NULL) {
802
+ extends = type_name(tservice->get_extends());
803
+ extends_client = extends + ".Client, ";
804
+ }
805
+
806
+ indent(f_service_) <<
807
+ "public class Client : " << extends_client << "Iface {" << endl;
808
+ indent_up();
809
+ indent(f_service_) <<
810
+ "public Client(TProtocol prot) : this(prot, prot)" << endl;
811
+ scope_up(f_service_);
812
+ scope_down(f_service_);
813
+ f_service_ << endl;
814
+
815
+ indent(f_service_) <<
816
+ "public Client(TProtocol iprot, TProtocol oprot)";
817
+ if (!extends.empty()) {
818
+ f_service_ << " : base(iprot, oprot)";
819
+ }
820
+ f_service_ << endl;
821
+
822
+ scope_up(f_service_);
823
+ if (extends.empty()) {
824
+ f_service_ <<
825
+ indent() << "iprot_ = iprot;" << endl <<
826
+ indent() << "oprot_ = oprot;" << endl;
827
+ }
828
+ scope_down(f_service_);
829
+
830
+ f_service_ << endl;
831
+
832
+ if (extends.empty()) {
833
+ f_service_ <<
834
+ indent() << "protected TProtocol iprot_;" << endl <<
835
+ indent() << "protected TProtocol oprot_;" << endl <<
836
+ indent() << "protected int seqid_;" << endl << endl;
837
+
838
+ f_service_ << indent() << "public TProtocol InputProtocol" << endl;
839
+ scope_up(f_service_);
840
+ indent(f_service_) << "get { return iprot_; }" << endl;
841
+ scope_down(f_service_);
842
+
843
+ f_service_ << indent() << "public TProtocol OutputProtocol" << endl;
844
+ scope_up(f_service_);
845
+ indent(f_service_) << "get { return oprot_; }" << endl;
846
+ scope_down(f_service_);
847
+ f_service_ << endl << endl;
848
+ }
849
+
850
+ vector<t_function*> functions = tservice->get_functions();
851
+ vector<t_function*>::const_iterator f_iter;
852
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
853
+ string funname = (*f_iter)->get_name();
854
+
855
+ indent(f_service_) <<
856
+ "public " << function_signature(*f_iter) << endl;
857
+ scope_up(f_service_);
858
+ indent(f_service_) <<
859
+ "send_" << funname << "(";
860
+
861
+ t_struct* arg_struct = (*f_iter)->get_arglist();
862
+
863
+ const vector<t_field*>& fields = arg_struct->get_members();
864
+ vector<t_field*>::const_iterator fld_iter;
865
+ bool first = true;
866
+ for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
867
+ if (first) {
868
+ first = false;
869
+ } else {
870
+ f_service_ << ", ";
871
+ }
872
+ f_service_ << (*fld_iter)->get_name();
873
+ }
874
+ f_service_ << ");" << endl;
875
+
876
+ if (!(*f_iter)->is_oneway()) {
877
+ f_service_ << indent();
878
+ if (!(*f_iter)->get_returntype()->is_void()) {
879
+ f_service_ << "return ";
880
+ }
881
+ f_service_ <<
882
+ "recv_" << funname << "();" << endl;
883
+ }
884
+ scope_down(f_service_);
885
+ f_service_ << endl;
886
+
887
+ t_function send_function(g_type_void,
888
+ string("send_") + (*f_iter)->get_name(),
889
+ (*f_iter)->get_arglist());
890
+
891
+ string argsname = (*f_iter)->get_name() + "_args";
892
+
893
+ indent(f_service_) <<
894
+ "public " << function_signature(&send_function) << endl;
895
+ scope_up(f_service_);
896
+
897
+ f_service_ <<
898
+ indent() << "oprot_.WriteMessageBegin(new TMessage(\"" << funname << "\", TMessageType.Call, seqid_));" << endl <<
899
+ indent() << argsname << " args = new " << argsname << "();" << endl;
900
+
901
+ for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
902
+ f_service_ <<
903
+ indent() << "args." << prop_name(*fld_iter) << " = " << (*fld_iter)->get_name() << ";" << endl;
904
+ }
905
+
906
+ f_service_ <<
907
+ indent() << "args.Write(oprot_);" << endl <<
908
+ indent() << "oprot_.WriteMessageEnd();" << endl <<
909
+ indent() << "oprot_.Transport.Flush();" << endl;
910
+
911
+ scope_down(f_service_);
912
+ f_service_ << endl;
913
+
914
+ if (!(*f_iter)->is_oneway()) {
915
+ string resultname = (*f_iter)->get_name() + "_result";
916
+
917
+ t_struct noargs(program_);
918
+ t_function recv_function((*f_iter)->get_returntype(),
919
+ string("recv_") + (*f_iter)->get_name(),
920
+ &noargs,
921
+ (*f_iter)->get_xceptions());
922
+ indent(f_service_) <<
923
+ "public " << function_signature(&recv_function) << endl;
924
+ scope_up(f_service_);
925
+
926
+ f_service_ <<
927
+ indent() << "TMessage msg = iprot_.ReadMessageBegin();" << endl <<
928
+ indent() << "if (msg.Type == TMessageType.Exception) {" << endl;
929
+ indent_up();
930
+ f_service_ <<
931
+ indent() << "TApplicationException x = TApplicationException.Read(iprot_);" << endl <<
932
+ indent() << "iprot_.ReadMessageEnd();" << endl <<
933
+ indent() << "throw x;" << endl;
934
+ indent_down();
935
+ f_service_ <<
936
+ indent() << "}" << endl <<
937
+ indent() << resultname << " result = new " << resultname << "();" << endl <<
938
+ indent() << "result.Read(iprot_);" << endl <<
939
+ indent() << "iprot_.ReadMessageEnd();" << endl;
940
+
941
+ if (!(*f_iter)->get_returntype()->is_void()) {
942
+ f_service_ <<
943
+ indent() << "if (result.__isset.success) {" << endl <<
944
+ indent() << " return result.Success;" << endl <<
945
+ indent() << "}" << endl;
946
+ }
947
+
948
+ t_struct *xs = (*f_iter)->get_xceptions();
949
+
950
+ const std::vector<t_field*>& xceptions = xs->get_members();
951
+ vector<t_field*>::const_iterator x_iter;
952
+ for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
953
+ f_service_ <<
954
+ indent() << "if (result.__isset." << (*x_iter)->get_name() << ") {" << endl <<
955
+ indent() << " throw result." << prop_name(*x_iter) << ";" << endl <<
956
+ indent() << "}" << endl;
957
+ }
958
+
959
+ if ((*f_iter)->get_returntype()->is_void()) {
960
+ indent(f_service_) <<
961
+ "return;" << endl;
962
+ } else {
963
+ f_service_ <<
964
+ indent() << "throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, \"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
965
+ }
966
+
967
+ scope_down(f_service_);
968
+ f_service_ << endl;
969
+ }
970
+ }
971
+
972
+ indent_down();
973
+ indent(f_service_) <<
974
+ "}" << endl;
975
+ }
976
+
977
+ void t_csharp_generator::generate_service_server(t_service* tservice) {
978
+ vector<t_function*> functions = tservice->get_functions();
979
+ vector<t_function*>::iterator f_iter;
980
+
981
+ string extends = "";
982
+ string extends_processor = "";
983
+ if (tservice->get_extends() != NULL) {
984
+ extends = type_name(tservice->get_extends());
985
+ extends_processor = extends + ".Processor, ";
986
+ }
987
+
988
+ indent(f_service_) <<
989
+ "public class Processor : " << extends_processor << "TProcessor {" << endl;
990
+ indent_up();
991
+
992
+ indent(f_service_) <<
993
+ "public Processor(Iface iface)" ;
994
+ if (!extends.empty()) {
995
+ f_service_ << " : base(iface)";
996
+ }
997
+ f_service_ << endl;
998
+ scope_up(f_service_);
999
+ f_service_ <<
1000
+ indent() << "iface_ = iface;" << endl;
1001
+
1002
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
1003
+ f_service_ <<
1004
+ indent() << "processMap_[\"" << (*f_iter)->get_name() << "\"] = " << (*f_iter)->get_name() << "_Process;" << endl;
1005
+ }
1006
+
1007
+ scope_down(f_service_);
1008
+ f_service_ << endl;
1009
+
1010
+ if (extends.empty()) {
1011
+ f_service_ <<
1012
+ indent() << "protected delegate void ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot);" << endl;
1013
+ }
1014
+
1015
+ f_service_ <<
1016
+ indent() << "private Iface iface_;" << endl;
1017
+
1018
+ if (extends.empty()) {
1019
+ f_service_ <<
1020
+ indent() << "protected Dictionary<string, ProcessFunction> processMap_ = new Dictionary<string, ProcessFunction>();" << endl;
1021
+ }
1022
+
1023
+ f_service_ << endl;
1024
+
1025
+ if (extends.empty()) {
1026
+ indent(f_service_) <<
1027
+ "public bool Process(TProtocol iprot, TProtocol oprot)" << endl;
1028
+ }
1029
+ else
1030
+ {
1031
+ indent(f_service_) <<
1032
+ "public new bool Process(TProtocol iprot, TProtocol oprot)" << endl;
1033
+ }
1034
+ scope_up(f_service_);
1035
+
1036
+ f_service_ << indent() << "try" << endl;
1037
+ scope_up(f_service_);
1038
+
1039
+ f_service_ <<
1040
+ indent() << "TMessage msg = iprot.ReadMessageBegin();" << endl;
1041
+
1042
+ f_service_ <<
1043
+ indent() << "ProcessFunction fn;" << endl <<
1044
+ indent() << "processMap_.TryGetValue(msg.Name, out fn);" << endl <<
1045
+ indent() << "if (fn == null) {" << endl <<
1046
+ indent() << " TProtocolUtil.Skip(iprot, TType.Struct);" << endl <<
1047
+ indent() << " iprot.ReadMessageEnd();" << endl <<
1048
+ indent() << " TApplicationException x = new TApplicationException (TApplicationException.ExceptionType.UnknownMethod, \"Invalid method name: '\" + msg.Name + \"'\");" << endl <<
1049
+ indent() << " oprot.WriteMessageBegin(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID));" << endl <<
1050
+ indent() << " x.Write(oprot);" << endl <<
1051
+ indent() << " oprot.WriteMessageEnd();" << endl <<
1052
+ indent() << " oprot.Transport.Flush();" << endl <<
1053
+ indent() << " return true;" << endl <<
1054
+ indent() << "}" << endl <<
1055
+ indent() << "fn(msg.SeqID, iprot, oprot);" << endl;
1056
+
1057
+ scope_down(f_service_);
1058
+
1059
+ f_service_ <<
1060
+ indent() << "catch (IOException)" << endl;
1061
+ scope_up(f_service_);
1062
+ f_service_ <<
1063
+ indent() << "return false;" << endl;
1064
+ scope_down(f_service_);
1065
+
1066
+ f_service_ <<
1067
+ indent() << "return true;" << endl;
1068
+
1069
+ scope_down(f_service_);
1070
+ f_service_ << endl;
1071
+
1072
+ for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter)
1073
+ {
1074
+ generate_process_function(tservice, *f_iter);
1075
+ }
1076
+
1077
+ indent_down();
1078
+ indent(f_service_) <<
1079
+ "}" << endl << endl;
1080
+ }
1081
+
1082
+ void t_csharp_generator::generate_function_helpers(t_function* tfunction) {
1083
+ if (tfunction->is_oneway()) {
1084
+ return;
1085
+ }
1086
+
1087
+ t_struct result(program_, tfunction->get_name() + "_result");
1088
+ t_field success(tfunction->get_returntype(), "success", 0);
1089
+ if (!tfunction->get_returntype()->is_void()) {
1090
+ result.append(&success);
1091
+ }
1092
+
1093
+ t_struct *xs = tfunction->get_xceptions();
1094
+ const vector<t_field*>& fields = xs->get_members();
1095
+ vector<t_field*>::const_iterator f_iter;
1096
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
1097
+ result.append(*f_iter);
1098
+ }
1099
+
1100
+ generate_csharp_struct_definition(f_service_, &result, false, true, true);
1101
+ }
1102
+
1103
+ void t_csharp_generator::generate_process_function(t_service* tservice, t_function* tfunction) {
1104
+ indent(f_service_) <<
1105
+ "public void " << tfunction->get_name() << "_Process(int seqid, TProtocol iprot, TProtocol oprot)" << endl;
1106
+ scope_up(f_service_);
1107
+
1108
+ string argsname = tfunction->get_name() + "_args";
1109
+ string resultname = tfunction->get_name() + "_result";
1110
+
1111
+ f_service_ <<
1112
+ indent() << argsname << " args = new " << argsname << "();" << endl <<
1113
+ indent() << "args.Read(iprot);" << endl <<
1114
+ indent() << "iprot.ReadMessageEnd();" << endl;
1115
+
1116
+ t_struct* xs = tfunction->get_xceptions();
1117
+ const std::vector<t_field*>& xceptions = xs->get_members();
1118
+ vector<t_field*>::const_iterator x_iter;
1119
+
1120
+ if (!tfunction->is_oneway()) {
1121
+ f_service_ <<
1122
+ indent() << resultname << " result = new " << resultname << "();" << endl;
1123
+ }
1124
+
1125
+ if (xceptions.size() > 0) {
1126
+ f_service_ <<
1127
+ indent() << "try {" << endl;
1128
+ indent_up();
1129
+ }
1130
+
1131
+ t_struct* arg_struct = tfunction->get_arglist();
1132
+ const std::vector<t_field*>& fields = arg_struct->get_members();
1133
+ vector<t_field*>::const_iterator f_iter;
1134
+
1135
+ f_service_ << indent();
1136
+ if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
1137
+ f_service_ << "result.Success = ";
1138
+ }
1139
+ f_service_ <<
1140
+ "iface_." << tfunction->get_name() << "(";
1141
+ bool first = true;
1142
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
1143
+ if (first) {
1144
+ first = false;
1145
+ } else {
1146
+ f_service_ << ", ";
1147
+ }
1148
+ f_service_ << "args." << prop_name(*f_iter);
1149
+ }
1150
+ f_service_ << ");" << endl;
1151
+
1152
+ if (!tfunction->is_oneway() && xceptions.size() > 0) {
1153
+ indent_down();
1154
+ f_service_ << indent() << "}";
1155
+ for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
1156
+ f_service_ << " catch (" << type_name((*x_iter)->get_type(), false, false) << " " << (*x_iter)->get_name() << ") {" << endl;
1157
+ if (!tfunction->is_oneway()) {
1158
+ indent_up();
1159
+ f_service_ <<
1160
+ indent() << "result." << prop_name(*x_iter) << " = " << (*x_iter)->get_name() << ";" << endl;
1161
+ indent_down();
1162
+ f_service_ << indent() << "}";
1163
+ } else {
1164
+ f_service_ << "}";
1165
+ }
1166
+ }
1167
+ f_service_ << endl;
1168
+ }
1169
+
1170
+ if (tfunction->is_oneway()) {
1171
+ f_service_ <<
1172
+ indent() << "return;" << endl;
1173
+ scope_down(f_service_);
1174
+
1175
+ return;
1176
+ }
1177
+
1178
+ f_service_ <<
1179
+ indent() << "oprot.WriteMessageBegin(new TMessage(\"" << tfunction->get_name() << "\", TMessageType.Reply, seqid)); " << endl <<
1180
+ indent() << "result.Write(oprot);" << endl <<
1181
+ indent() << "oprot.WriteMessageEnd();" << endl <<
1182
+ indent() << "oprot.Transport.Flush();" << endl;
1183
+
1184
+ scope_down(f_service_);
1185
+
1186
+ f_service_ << endl;
1187
+ }
1188
+
1189
+ void t_csharp_generator::generate_deserialize_field(ofstream& out, t_field* tfield, string prefix) {
1190
+ t_type* type = tfield->get_type();
1191
+ while(type->is_typedef()) {
1192
+ type = ((t_typedef*)type)->get_type();
1193
+ }
1194
+
1195
+ if (type->is_void()) {
1196
+ throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " + prefix + tfield->get_name();
1197
+ }
1198
+
1199
+ string name = prefix + tfield->get_name();
1200
+
1201
+ if (type->is_struct() || type->is_xception()) {
1202
+ generate_deserialize_struct(out, (t_struct*)type, name);
1203
+ } else if (type->is_container()) {
1204
+ generate_deserialize_container(out, type, name);
1205
+ } else if (type->is_base_type() || type->is_enum()) {
1206
+ indent(out) <<
1207
+ name << " = ";
1208
+
1209
+ if (type->is_enum())
1210
+ {
1211
+ out << "(" << type_name(type, false, true) << ")";
1212
+ }
1213
+
1214
+ out << "iprot.";
1215
+
1216
+ if (type->is_base_type()) {
1217
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
1218
+ switch (tbase) {
1219
+ case t_base_type::TYPE_VOID:
1220
+ throw "compiler error: cannot serialize void field in a struct: " + name;
1221
+ break;
1222
+ case t_base_type::TYPE_STRING:
1223
+ if (((t_base_type*)type)->is_binary()) {
1224
+ out << "ReadBinary();";
1225
+ } else {
1226
+ out << "ReadString();";
1227
+ }
1228
+ break;
1229
+ case t_base_type::TYPE_BOOL:
1230
+ out << "ReadBool();";
1231
+ break;
1232
+ case t_base_type::TYPE_BYTE:
1233
+ out << "ReadByte();";
1234
+ break;
1235
+ case t_base_type::TYPE_I16:
1236
+ out << "ReadI16();";
1237
+ break;
1238
+ case t_base_type::TYPE_I32:
1239
+ out << "ReadI32();";
1240
+ break;
1241
+ case t_base_type::TYPE_I64:
1242
+ out << "ReadI64();";
1243
+ break;
1244
+ case t_base_type::TYPE_DOUBLE:
1245
+ out << "ReadDouble();";
1246
+ break;
1247
+ default:
1248
+ throw "compiler error: no C# name for base type " + tbase;
1249
+ }
1250
+ } else if (type->is_enum()) {
1251
+ out << "ReadI32();";
1252
+ }
1253
+ out << endl;
1254
+ } else {
1255
+ printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n", tfield->get_name().c_str(), type_name(type).c_str());
1256
+ }
1257
+ }
1258
+
1259
+ void t_csharp_generator::generate_deserialize_struct(ofstream& out, t_struct* tstruct, string prefix) {
1260
+ out <<
1261
+ indent() << prefix << " = new " << type_name(tstruct) << "();" << endl <<
1262
+ indent() << prefix << ".Read(iprot);" << endl;
1263
+ }
1264
+
1265
+ void t_csharp_generator::generate_deserialize_container(ofstream& out, t_type* ttype, string prefix) {
1266
+ scope_up(out);
1267
+
1268
+ string obj;
1269
+
1270
+ if (ttype->is_map()) {
1271
+ obj = tmp("_map");
1272
+ } else if (ttype->is_set()) {
1273
+ obj = tmp("_set");
1274
+ } else if (ttype->is_list()) {
1275
+ obj = tmp("_list");
1276
+ }
1277
+
1278
+ indent(out) <<
1279
+ prefix << " = new " << type_name(ttype, false, true) << "();" <<endl;
1280
+ if (ttype->is_map()) {
1281
+ out <<
1282
+ indent() << "TMap " << obj << " = iprot.ReadMapBegin();" << endl;
1283
+ } else if (ttype->is_set()) {
1284
+ out <<
1285
+ indent() << "TSet " << obj << " = iprot.ReadSetBegin();" << endl;
1286
+ } else if (ttype->is_list()) {
1287
+ out <<
1288
+ indent() << "TList " << obj << " = iprot.ReadListBegin();" << endl;
1289
+ }
1290
+
1291
+ string i = tmp("_i");
1292
+ indent(out) <<
1293
+ "for( int " << i << " = 0; " << i << " < " << obj << ".Count" << "; " << "++" << i << ")" << endl;
1294
+ scope_up(out);
1295
+
1296
+ if (ttype->is_map()) {
1297
+ generate_deserialize_map_element(out, (t_map*)ttype, prefix);
1298
+ } else if (ttype->is_set()) {
1299
+ generate_deserialize_set_element(out, (t_set*)ttype, prefix);
1300
+ } else if (ttype->is_list()) {
1301
+ generate_deserialize_list_element(out, (t_list*)ttype, prefix);
1302
+ }
1303
+
1304
+ scope_down(out);
1305
+
1306
+ if (ttype->is_map()) {
1307
+ indent(out) << "iprot.ReadMapEnd();" << endl;
1308
+ } else if (ttype->is_set()) {
1309
+ indent(out) << "iprot.ReadSetEnd();" << endl;
1310
+ } else if (ttype->is_list()) {
1311
+ indent(out) << "iprot.ReadListEnd();" << endl;
1312
+ }
1313
+
1314
+ scope_down(out);
1315
+ }
1316
+
1317
+ void t_csharp_generator::generate_deserialize_map_element(ofstream& out, t_map* tmap, string prefix) {
1318
+ string key = tmp("_key");
1319
+ string val = tmp("_val");
1320
+
1321
+ t_field fkey(tmap->get_key_type(), key);
1322
+ t_field fval(tmap->get_val_type(), val);
1323
+
1324
+ indent(out) <<
1325
+ declare_field(&fkey) << endl;
1326
+ indent(out) <<
1327
+ declare_field(&fval) << endl;
1328
+
1329
+ generate_deserialize_field(out, &fkey);
1330
+ generate_deserialize_field(out, &fval);
1331
+
1332
+ indent(out) <<
1333
+ prefix << "[" << key << "] = " << val << ";" << endl;
1334
+ }
1335
+
1336
+ void t_csharp_generator::generate_deserialize_set_element(ofstream& out, t_set* tset, string prefix) {
1337
+ string elem = tmp("_elem");
1338
+ t_field felem(tset->get_elem_type(), elem);
1339
+
1340
+ indent(out) <<
1341
+ declare_field(&felem, true) << endl;
1342
+
1343
+ generate_deserialize_field(out, &felem);
1344
+
1345
+ indent(out) <<
1346
+ prefix << ".Add(" << elem << ");" << endl;
1347
+ }
1348
+
1349
+ void t_csharp_generator::generate_deserialize_list_element(ofstream& out, t_list* tlist, string prefix) {
1350
+ string elem = tmp("_elem");
1351
+ t_field felem(tlist->get_elem_type(), elem);
1352
+
1353
+ indent(out) <<
1354
+ declare_field(&felem, true) << endl;
1355
+
1356
+ generate_deserialize_field(out, &felem);
1357
+
1358
+ indent(out) <<
1359
+ prefix << ".Add(" << elem << ");" << endl;
1360
+ }
1361
+
1362
+ void t_csharp_generator::generate_serialize_field(ofstream& out, t_field* tfield, string prefix) {
1363
+ t_type* type = tfield->get_type();
1364
+ while (type->is_typedef()) {
1365
+ type = ((t_typedef*)type)->get_type();
1366
+ }
1367
+
1368
+ if (type->is_void()) {
1369
+ throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " + prefix + tfield->get_name();
1370
+ }
1371
+
1372
+ if (type->is_struct() || type->is_xception()) {
1373
+ generate_serialize_struct(out, (t_struct*)type, prefix + tfield->get_name());
1374
+ } else if (type->is_container()) {
1375
+ generate_serialize_container(out, type, prefix + tfield->get_name());
1376
+ } else if (type->is_base_type() || type->is_enum()) {
1377
+ string name = prefix + tfield->get_name();
1378
+ indent(out) <<
1379
+ "oprot.";
1380
+
1381
+ if (type->is_base_type()) {
1382
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
1383
+
1384
+ switch(tbase) {
1385
+ case t_base_type::TYPE_VOID:
1386
+ throw "compiler error: cannot serialize void field in a struct: " + name;
1387
+ break;
1388
+ case t_base_type::TYPE_STRING:
1389
+ if (((t_base_type*)type)->is_binary()) {
1390
+ out << "WriteBinary(";
1391
+ } else {
1392
+ out << "WriteString(";
1393
+ }
1394
+ out << name << ");";
1395
+ break;
1396
+ case t_base_type::TYPE_BOOL:
1397
+ out << "WriteBool(" << name << ");";
1398
+ break;
1399
+ case t_base_type::TYPE_BYTE:
1400
+ out << "WriteByte(" << name << ");";
1401
+ break;
1402
+ case t_base_type::TYPE_I16:
1403
+ out << "WriteI16(" << name << ");";
1404
+ break;
1405
+ case t_base_type::TYPE_I32:
1406
+ out << "WriteI32(" << name << ");";
1407
+ break;
1408
+ case t_base_type::TYPE_I64:
1409
+ out << "WriteI64(" << name << ");";
1410
+ break;
1411
+ case t_base_type::TYPE_DOUBLE:
1412
+ out << "WriteDouble(" << name << ");";
1413
+ break;
1414
+ default:
1415
+ throw "compiler error: no C# name for base type " + tbase;
1416
+ }
1417
+ } else if (type->is_enum()) {
1418
+ out << "WriteI32((int)" << name << ");";
1419
+ }
1420
+ out << endl;
1421
+ } else {
1422
+ printf("DO NOT KNOW HOW TO SERIALIZE '%s%s' TYPE '%s'\n",
1423
+ prefix.c_str(),
1424
+ tfield->get_name().c_str(),
1425
+ type_name(type).c_str());
1426
+ }
1427
+ }
1428
+
1429
+ void t_csharp_generator::generate_serialize_struct(ofstream& out, t_struct* tstruct, string prefix) {
1430
+ out <<
1431
+ indent() << prefix << ".Write(oprot);" << endl;
1432
+ }
1433
+
1434
+ void t_csharp_generator::generate_serialize_container(ofstream& out, t_type* ttype, string prefix) {
1435
+ scope_up(out);
1436
+
1437
+ if (ttype->is_map()) {
1438
+ indent(out) <<
1439
+ "oprot.WriteMapBegin(new TMap(" <<
1440
+ type_to_enum(((t_map*)ttype)->get_key_type()) << ", " <<
1441
+ type_to_enum(((t_map*)ttype)->get_val_type()) << ", " <<
1442
+ prefix << ".Count));" << endl;
1443
+ } else if (ttype->is_set()) {
1444
+ indent(out) <<
1445
+ "oprot.WriteSetBegin(new TSet(" <<
1446
+ type_to_enum(((t_set*)ttype)->get_elem_type()) << ", " <<
1447
+ prefix << ".Count));" << endl;
1448
+ } else if (ttype->is_list()) {
1449
+ indent(out) <<
1450
+ "oprot.WriteListBegin(new TList(" <<
1451
+ type_to_enum(((t_list*)ttype)->get_elem_type()) << ", " <<
1452
+ prefix << ".Count));" << endl;
1453
+ }
1454
+
1455
+ string iter = tmp("_iter");
1456
+ if (ttype->is_map()) {
1457
+ indent(out) <<
1458
+ "foreach (" <<
1459
+ type_name(((t_map*)ttype)->get_key_type()) << " " << iter <<
1460
+ " in " <<
1461
+ prefix << ".Keys)";
1462
+ } else if (ttype->is_set()) {
1463
+ indent(out) <<
1464
+ "foreach (" <<
1465
+ type_name(((t_set*)ttype)->get_elem_type()) << " " << iter <<
1466
+ " in " <<
1467
+ prefix << ")";
1468
+ } else if (ttype->is_list()) {
1469
+ indent(out) <<
1470
+ "foreach (" <<
1471
+ type_name(((t_list*)ttype)->get_elem_type()) << " " << iter <<
1472
+ " in " <<
1473
+ prefix << ")";
1474
+ }
1475
+
1476
+ out << endl;
1477
+ scope_up(out);
1478
+
1479
+ if (ttype->is_map()) {
1480
+ generate_serialize_map_element(out, (t_map*)ttype, iter, prefix);
1481
+ } else if (ttype->is_set()) {
1482
+ generate_serialize_set_element(out, (t_set*)ttype, iter);
1483
+ } else if (ttype->is_list()) {
1484
+ generate_serialize_list_element(out, (t_list*)ttype, iter);
1485
+ }
1486
+
1487
+ if (ttype->is_map()) {
1488
+ indent(out) << "oprot.WriteMapEnd();" << endl;
1489
+ } else if (ttype->is_set()) {
1490
+ indent(out) << "oprot.WriteSetEnd();" << endl;
1491
+ } else if (ttype->is_list()) {
1492
+ indent(out) << "oprot.WriteListEnd();" << endl;
1493
+ }
1494
+
1495
+ scope_down(out);
1496
+ scope_down(out);
1497
+ }
1498
+
1499
+ void t_csharp_generator::generate_serialize_map_element(ofstream& out, t_map* tmap, string iter, string map) {
1500
+ t_field kfield(tmap->get_key_type(), iter);
1501
+ generate_serialize_field(out, &kfield, "");
1502
+ t_field vfield(tmap->get_val_type(), map + "[" + iter + "]");
1503
+ generate_serialize_field(out, &vfield, "");
1504
+ }
1505
+
1506
+ void t_csharp_generator::generate_serialize_set_element(ofstream& out, t_set* tset, string iter) {
1507
+ t_field efield(tset->get_elem_type(), iter);
1508
+ generate_serialize_field(out, &efield, "");
1509
+ }
1510
+
1511
+ void t_csharp_generator::generate_serialize_list_element(ofstream& out, t_list* tlist, string iter) {
1512
+ t_field efield(tlist->get_elem_type(), iter);
1513
+ generate_serialize_field(out, &efield, "");
1514
+ }
1515
+
1516
+ void t_csharp_generator::generate_property(ofstream& out, t_field* tfield, bool isPublic) {
1517
+ indent(out) << (isPublic ? "public " : "private ") << type_name(tfield->get_type())
1518
+ << " " << prop_name(tfield) << endl;
1519
+ scope_up(out);
1520
+ indent(out) << "get" << endl;
1521
+ scope_up(out);
1522
+ indent(out) << "return " << tfield->get_name() << ";" << endl;
1523
+ scope_down(out);
1524
+ indent(out) << "set" << endl;
1525
+ scope_up(out);
1526
+ indent(out) << "__isset." << tfield->get_name() << " = true;" << endl;
1527
+ indent(out) << "this." << tfield->get_name() << " = value;" << endl;
1528
+ scope_down(out);
1529
+ scope_down(out);
1530
+ out << endl;
1531
+ }
1532
+
1533
+ std::string t_csharp_generator::prop_name(t_field* tfield) {
1534
+ string name (tfield->get_name());
1535
+ name[0] = toupper(name[0]);
1536
+ return name;
1537
+ }
1538
+
1539
+ string t_csharp_generator::type_name(t_type* ttype, bool in_container, bool in_init) {
1540
+ while (ttype->is_typedef()) {
1541
+ ttype = ((t_typedef*)ttype)->get_type();
1542
+ }
1543
+
1544
+ if (ttype->is_base_type()) {
1545
+ return base_type_name((t_base_type*)ttype, in_container);
1546
+ } else if (ttype->is_map()) {
1547
+ t_map *tmap = (t_map*) ttype;
1548
+ return "Dictionary<" + type_name(tmap->get_key_type(), true) +
1549
+ ", " + type_name(tmap->get_val_type(), true) + ">";
1550
+ } else if (ttype->is_set()) {
1551
+ t_set* tset = (t_set*) ttype;
1552
+ return "THashSet<" + type_name(tset->get_elem_type(), true) + ">";
1553
+ } else if (ttype->is_list()) {
1554
+ t_list* tlist = (t_list*) ttype;
1555
+ return "List<" + type_name(tlist->get_elem_type(), true) + ">";
1556
+ }
1557
+
1558
+ t_program* program = ttype->get_program();
1559
+ if (program != NULL && program != program_) {
1560
+ string ns = program->get_namespace("csharp");
1561
+ if (!ns.empty()) {
1562
+ return ns + "." + ttype->get_name();
1563
+ }
1564
+ }
1565
+
1566
+ return ttype->get_name();
1567
+ }
1568
+
1569
+ string t_csharp_generator::base_type_name(t_base_type* tbase, bool in_container) {
1570
+ switch (tbase->get_base()) {
1571
+ case t_base_type::TYPE_VOID:
1572
+ return "void";
1573
+ case t_base_type::TYPE_STRING:
1574
+ if (tbase->is_binary()) {
1575
+ return "byte[]";
1576
+ } else {
1577
+ return "string";
1578
+ }
1579
+ case t_base_type::TYPE_BOOL:
1580
+ return "bool";
1581
+ case t_base_type::TYPE_BYTE:
1582
+ return "byte";
1583
+ case t_base_type::TYPE_I16:
1584
+ return "short";
1585
+ case t_base_type::TYPE_I32:
1586
+ return "int";
1587
+ case t_base_type::TYPE_I64:
1588
+ return "long";
1589
+ case t_base_type::TYPE_DOUBLE:
1590
+ return "double";
1591
+ default:
1592
+ throw "compiler error: no C# name for base type " + tbase->get_base();
1593
+ }
1594
+ }
1595
+
1596
+ string t_csharp_generator::declare_field(t_field* tfield, bool init) {
1597
+ string result = type_name(tfield->get_type()) + " " + tfield->get_name();
1598
+ if (init) {
1599
+ t_type* ttype = tfield->get_type();
1600
+ while (ttype->is_typedef()) {
1601
+ ttype = ((t_typedef*)ttype)->get_type();
1602
+ }
1603
+ if (ttype->is_base_type() && tfield->get_value() != NULL) {
1604
+ ofstream dummy;
1605
+ result += " = " + render_const_value(dummy, tfield->get_name(), ttype, tfield->get_value());
1606
+ } else if (ttype->is_base_type()) {
1607
+ t_base_type::t_base tbase = ((t_base_type*)ttype)->get_base();
1608
+ switch (tbase) {
1609
+ case t_base_type::TYPE_VOID:
1610
+ throw "NO T_VOID CONSTRUCT";
1611
+ case t_base_type::TYPE_STRING:
1612
+ result += " = null";
1613
+ break;
1614
+ case t_base_type::TYPE_BOOL:
1615
+ result += " = false";
1616
+ break;
1617
+ case t_base_type::TYPE_BYTE:
1618
+ case t_base_type::TYPE_I16:
1619
+ case t_base_type::TYPE_I32:
1620
+ case t_base_type::TYPE_I64:
1621
+ result += " = 0";
1622
+ break;
1623
+ case t_base_type::TYPE_DOUBLE:
1624
+ result += " = (double)0";
1625
+ break;
1626
+ }
1627
+ } else if (ttype->is_enum()) {
1628
+ result += " = (" + type_name(ttype, false, true) + ")0";
1629
+ } else if (ttype->is_container()) {
1630
+ result += " = new " + type_name(ttype, false, true) + "()";
1631
+ } else {
1632
+ result += " = new " + type_name(ttype, false, true) + "()";
1633
+ }
1634
+ }
1635
+ return result + ";";
1636
+ }
1637
+
1638
+ string t_csharp_generator::function_signature(t_function* tfunction, string prefix) {
1639
+ t_type* ttype = tfunction->get_returntype();
1640
+ return type_name(ttype) + " " + prefix + tfunction->get_name() + "(" + argument_list(tfunction->get_arglist()) + ")";
1641
+ }
1642
+
1643
+ string t_csharp_generator::argument_list(t_struct* tstruct) {
1644
+ string result = "";
1645
+ const vector<t_field*>& fields = tstruct->get_members();
1646
+ vector<t_field*>::const_iterator f_iter;
1647
+ bool first = true;
1648
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
1649
+ if (first) {
1650
+ first = false;
1651
+ } else {
1652
+ result += ", ";
1653
+ }
1654
+ result += type_name((*f_iter)->get_type()) + " " + (*f_iter)->get_name();
1655
+ }
1656
+ return result;
1657
+ }
1658
+
1659
+ string t_csharp_generator::type_to_enum(t_type* type) {
1660
+ while (type->is_typedef()) {
1661
+ type = ((t_typedef*)type)->get_type();
1662
+ }
1663
+
1664
+ if (type->is_base_type()) {
1665
+ t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
1666
+ switch (tbase) {
1667
+ case t_base_type::TYPE_VOID:
1668
+ throw "NO T_VOID CONSTRUCT";
1669
+ case t_base_type::TYPE_STRING:
1670
+ return "TType.String";
1671
+ case t_base_type::TYPE_BOOL:
1672
+ return "TType.Bool";
1673
+ case t_base_type::TYPE_BYTE:
1674
+ return "TType.Byte";
1675
+ case t_base_type::TYPE_I16:
1676
+ return "TType.I16";
1677
+ case t_base_type::TYPE_I32:
1678
+ return "TType.I32";
1679
+ case t_base_type::TYPE_I64:
1680
+ return "TType.I64";
1681
+ case t_base_type::TYPE_DOUBLE:
1682
+ return "TType.Double";
1683
+ }
1684
+ } else if (type->is_enum()) {
1685
+ return "TType.I32";
1686
+ } else if (type->is_struct() || type->is_xception()) {
1687
+ return "TType.Struct";
1688
+ } else if (type->is_map()) {
1689
+ return "TType.Map";
1690
+ } else if (type->is_set()) {
1691
+ return "TType.Set";
1692
+ } else if (type->is_list()) {
1693
+ return "TType.List";
1694
+ }
1695
+
1696
+ throw "INVALID TYPE IN type_to_enum: " + type->get_name();
1697
+ }
1698
+
1699
+
1700
+ THRIFT_REGISTER_GENERATOR(csharp, "C#", "");