THRIFT-1973 TCompactProtocol in C# lib does not serialize and deserialize negative...
authorHenrique Mendonça <henrique@apache.org>
Fri, 31 May 2013 16:20:42 +0000 (18:20 +0200)
committerHenrique Mendonça <henrique@apache.org>
Fri, 31 May 2013 16:20:42 +0000 (18:20 +0200)
Patch: Eric Ding

lib/csharp/Makefile.am
lib/csharp/src/Protocol/TCompactProtocol.cs
lib/csharp/src/Thrift.sln
lib/csharp/src/Transport/TMemoryBuffer.cs
lib/csharp/test/ThriftTest/ThriftTest.csproj
lib/csharp/test/ThriftTest/maketest.sh [deleted file]
test/ThriftTest.thrift

index 7bc161d..ee71bc9 100644 (file)
@@ -61,7 +61,16 @@ THRIFTCODE= \
             src/TProcessor.cs \
             src/TApplicationException.cs
 
+THRIFTTESTCODE = \
+           test/ThriftTest/Program.cs \
+           test/ThriftTest/TestClient.cs \
+           test/ThriftTest/TestServer.cs \
+           test/ThriftTest/RoundTripTest.cs \
+           test/ThriftTest/Thrift/Test/*.cs
+
 CSC=gmcs
+NUNIT=nunit-console
+THRIFT=../../compiler/cpp/thrift
 
 if NET_2_0
 MONO_DEFINES=/d:NET_2_0
@@ -72,6 +81,15 @@ all-local: Thrift.dll
 Thrift.dll: $(THRIFTCODE)
        $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library /reference:System.Web $(MONO_DEFINES)
 
+test/ThriftTest/Thrift/Test/*.cs: ../../test/ThriftTest.thrift
+       $(THRIFT) -gen csharp:hashcode -out test/ThriftTest ../../test/ThriftTest.thrift
+
+ThriftTest.exe: Thrift.dll $(THRIFTTESTCODE)
+       $(CSC) $(THRIFTTESTCODE) /out:ThriftTest.exe /target:exe /reference:nunit.framework /reference:Thrift.dll $(MONO_DEFINES)
+
+check-local: ThriftTest.exe
+       $(NUNIT) ThriftTest.exe
+
 clean-local:
        $(RM) Thrift.dll
 
index 6e8cafd..a498577 100644 (file)
@@ -442,7 +442,7 @@ namespace Thrift.Protocol
          */
         private ulong longToZigzag(long n)
         {
-            return (ulong)(((ulong)n << 1) ^ ((ulong)n >> 63));
+            return (ulong)(n << 1) ^ (ulong)(n >> 63);
         }
 
         /**
@@ -451,7 +451,7 @@ namespace Thrift.Protocol
          */
         private uint intToZigZag(int n)
         {
-            return (uint)(((uint)n << 1) ^ ((uint)n >> 31));
+            return (uint)(n << 1) ^ (uint)(n >> 31);
         }
 
         /**
index ee0a3e7..5c210a5 100644 (file)
@@ -1,38 +1,35 @@
-\feff
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thrift", "Thrift.csproj", "{499EB63C-D74C-47E8-AE48-A2FC94538E9D}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "..\test\ThriftTest\ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}"
-       ProjectSection(ProjectDependencies) = postProject
-               {499EB63C-D74C-47E8-AE48-A2FC94538E9D} = {499EB63C-D74C-47E8-AE48-A2FC94538E9D}
-       EndProjectSection
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftMSBuildTask", "..\ThriftMSBuildTask\ThriftMSBuildTask.csproj", "{EC0A0231-66EA-4593-A792-C6CA3BB8668E}"
-EndProject
-Global
-       GlobalSection(SolutionConfigurationPlatforms) = preSolution
-               Debug|Any CPU = Debug|Any CPU
-               Release|Any CPU = Release|Any CPU
-       EndGlobalSection
-       GlobalSection(ProjectConfigurationPlatforms) = postSolution
-               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
-               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
-               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU
-               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
-               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
-               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU
-               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU
-               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU
-               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU
-       EndGlobalSection
-       GlobalSection(MonoDevelopProperties) = preSolution
-               StartupItem = Thrift.csproj
-       EndGlobalSection
-       GlobalSection(SolutionProperties) = preSolution
-               HideSolutionNode = FALSE
-       EndGlobalSection
-EndGlobal
+\feff\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Visual Studio 2010\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thrift", "Thrift.csproj", "{499EB63C-D74C-47E8-AE48-A2FC94538E9D}"\r
+EndProject\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftMSBuildTask", "..\ThriftMSBuildTask\ThriftMSBuildTask.csproj", "{EC0A0231-66EA-4593-A792-C6CA3BB8668E}"\r
+EndProject\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "..\test\ThriftTest\ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|Any CPU = Debug|Any CPU\r
+               Release|Any CPU = Release|Any CPU\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r
+               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU\r
+               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU\r
+               {48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}.Release|Any CPU.Build.0 = Release|Any CPU\r
+               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r
+               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU\r
+               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU\r
+               {499EB63C-D74C-47E8-AE48-A2FC94538E9D}.Release|Any CPU.Build.0 = Release|Any CPU\r
+               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r
+               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Debug|Any CPU.Build.0 = Debug|Any CPU\r
+               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.ActiveCfg = Release|Any CPU\r
+               {EC0A0231-66EA-4593-A792-C6CA3BB8668E}.Release|Any CPU.Build.0 = Release|Any CPU\r
+       EndGlobalSection\r
+       GlobalSection(MonoDevelopProperties) = preSolution\r
+               StartupItem = Thrift.csproj\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
index c6e72f1..b2e67db 100644 (file)
@@ -23,7 +23,6 @@ using Thrift.Protocol;
 
 namespace Thrift.Transport {
        public class TMemoryBuffer : TTransport {
-
                private readonly MemoryStream byteStream;
 
                public TMemoryBuffer() {
@@ -60,8 +59,12 @@ namespace Thrift.Transport {
                }
 
                public static byte[] Serialize(TBase s) {
+                       return Serialize(s, new TBinaryProtocol.Factory());
+               }
+
+               public static byte[] Serialize(TBase s, TProtocolFactory factory) {
                        var t = new TMemoryBuffer();
-                       var p = new TBinaryProtocol(t);
+                       var p = factory.GetProtocol(t);
 
                        s.Write(p);
 
@@ -69,9 +72,13 @@ namespace Thrift.Transport {
                }
 
                public static T DeSerialize<T>(byte[] buf) where T : TBase, new() {
+                       return DeSerialize<T>(buf, new TBinaryProtocol.Factory());
+               }
+
+               public static T DeSerialize<T>(byte[] buf, TProtocolFactory factory) where T : TBase, new() {
                       var t = new T();
                       var trans = new TMemoryBuffer(buf);
-                      var p = new TBinaryProtocol(trans);
+                      var p = factory.GetProtocol(trans);
                       t.Read(p);
                       return t;
                }
index 8717876..0187eed 100644 (file)
@@ -1,4 +1,4 @@
-\feff<?xml version="1.0" encoding="utf-8"?>\r
+<?xml version="1.0" encoding="utf-8"?>\r
 <!--\r
   Licensed to the Apache Software Foundation (ASF) under one\r
   or more contributor license agreements. See the NOTICE file\r
   </PropertyGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
-    <Reference Include="ThriftImpl, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">\r
-      <SpecificVersion>False</SpecificVersion>\r
-      <HintPath>.\ThriftImpl.dll</HintPath>\r
+    <Reference Include="ThriftImpl">\r
+      <HintPath>ThriftImpl.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">\r
+      <Private>False</Private>\r
     </Reference>\r
   </ItemGroup>\r
   <ItemGroup>\r
+    <Compile Include="gen-csharp\Thrift\Test\*.cs" />\r
     <Compile Include="Program.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
     <Compile Include="TestClient.cs" />\r
     <Compile Include="TestServer.cs" />\r
+    <Compile Include="RoundTripTest.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <BootstrapperPackage Include="Microsoft.Net.Client.3.5">\r
@@ -138,4 +142,4 @@ for %25%25I in ("%25THRIFT_FILE%25") do set THRIFT_SHORT=%25%25~fsI
 "$(ProjectDir)\..\..\..\..\compiler\cpp\thrift.exe" --gen csharp -o %25SHORT_DIR%25 %25THRIFT_SHORT%25\r
 $(MSBuildToolsPath)\Csc.exe /t:library /out:"$(ProjectDir)ThriftImpl.dll" /recurse:"$(ProjectDir)gen-csharp"\* /reference:"$(ProjectDir)..\..\src\bin\Debug\Thrift.dll"</PreBuildEvent>\r
   </PropertyGroup>\r
-</Project>
\ No newline at end of file
+</Project>\r
diff --git a/lib/csharp/test/ThriftTest/maketest.sh b/lib/csharp/test/ThriftTest/maketest.sh
deleted file mode 100755 (executable)
index 86c1a11..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/sh
-
-#
-# 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.
-#
-
-../../../../compiler/cpp/thrift --gen csharp -o . ../../../../test/ThriftTest.thrift
-gmcs /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll
-gmcs  /out:TestClientServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll TestClient.cs TestServer.cs Program.cs
-
-export MONO_PATH=../../
-
-timeout 120 ./TestClientServer.exe server &
-./TestClientServer.exe client
index be000b6..d191afd 100644 (file)
@@ -375,3 +375,11 @@ struct StructB {
   1: optional StructA aa;
   2: required StructA ab;
 }
+
+struct Primitives {
+  1: optional byte byte_thing;
+  2: optional i16 i16_thing;
+  3: optional i32 i32_thing;
+  4: optional i64 i64_thing;
+  5: optional bool bool_thing;
+}