THRIFT-1973 TCompactProtocol in C# lib does not serialize and deserialize negative int32 and int64 number correctly Patch: Eric Ding
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/5a61438a Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/5a61438a Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/5a61438a Branch: refs/heads/master Commit: 5a61438a5e61505d226d9aef1d131659109e5781 Parents: f57ec91 Author: Henrique Mendonça <[email protected]> Authored: Sat Jun 1 11:33:25 2013 +0200 Committer: Henrique Mendonça <[email protected]> Committed: Sat Jun 1 11:33:25 2013 +0200 ---------------------------------------------------------------------- lib/csharp/Makefile.am | 18 ----- lib/csharp/src/Thrift.sln | 73 +++++++++++---------- lib/csharp/src/Transport/TMemoryBuffer.cs | 13 +--- lib/csharp/test/ThriftTest/ThriftTest.csproj | 14 ++--- test/ThriftTest.thrift | 8 -- 5 files changed, 46 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/5a61438a/lib/csharp/Makefile.am ---------------------------------------------------------------------- diff --git a/lib/csharp/Makefile.am b/lib/csharp/Makefile.am index ee71bc9..7bc161d 100644 --- a/lib/csharp/Makefile.am +++ b/lib/csharp/Makefile.am @@ -61,16 +61,7 @@ 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 @@ -81,15 +72,6 @@ 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 http://git-wip-us.apache.org/repos/asf/thrift/blob/5a61438a/lib/csharp/src/Thrift.sln ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Thrift.sln b/lib/csharp/src/Thrift.sln index 5c210a5..ee0a3e7 100644 --- a/lib/csharp/src/Thrift.sln +++ b/lib/csharp/src/Thrift.sln @@ -1,35 +1,38 @@ - -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}") = "ThriftMSBuildTask", "..\ThriftMSBuildTask\ThriftMSBuildTask.csproj", "{EC0A0231-66EA-4593-A792-C6CA3BB8668E}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThriftTest", "..\test\ThriftTest\ThriftTest.csproj", "{48DD757F-CA95-4DD7-BDA4-58DB6F108C2C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {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 - {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 - {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 + +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 http://git-wip-us.apache.org/repos/asf/thrift/blob/5a61438a/lib/csharp/src/Transport/TMemoryBuffer.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Transport/TMemoryBuffer.cs b/lib/csharp/src/Transport/TMemoryBuffer.cs index b2e67db..c6e72f1 100644 --- a/lib/csharp/src/Transport/TMemoryBuffer.cs +++ b/lib/csharp/src/Transport/TMemoryBuffer.cs @@ -23,6 +23,7 @@ using Thrift.Protocol; namespace Thrift.Transport { public class TMemoryBuffer : TTransport { + private readonly MemoryStream byteStream; public TMemoryBuffer() { @@ -59,12 +60,8 @@ 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 = factory.GetProtocol(t); + var p = new TBinaryProtocol(t); s.Write(p); @@ -72,13 +69,9 @@ 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 = factory.GetProtocol(trans); + var p = new TBinaryProtocol(trans); t.Read(p); return t; } http://git-wip-us.apache.org/repos/asf/thrift/blob/5a61438a/lib/csharp/test/ThriftTest/ThriftTest.csproj ---------------------------------------------------------------------- diff --git a/lib/csharp/test/ThriftTest/ThriftTest.csproj b/lib/csharp/test/ThriftTest/ThriftTest.csproj index 0187eed..8717876 100644 --- a/lib/csharp/test/ThriftTest/ThriftTest.csproj +++ b/lib/csharp/test/ThriftTest/ThriftTest.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -71,20 +71,16 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> - <Reference Include="ThriftImpl"> - <HintPath>ThriftImpl.dll</HintPath> - </Reference> - <Reference Include="nunit.framework, Version=2.6.0.12051, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> - <Private>False</Private> + <Reference Include="ThriftImpl, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>.\ThriftImpl.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="gen-csharp\Thrift\Test\*.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="TestClient.cs" /> <Compile Include="TestServer.cs" /> - <Compile Include="RoundTripTest.cs" /> </ItemGroup> <ItemGroup> <BootstrapperPackage Include="Microsoft.Net.Client.3.5"> @@ -142,4 +138,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 $(MSBuildToolsPath)\Csc.exe /t:library /out:"$(ProjectDir)ThriftImpl.dll" /recurse:"$(ProjectDir)gen-csharp"\* /reference:"$(ProjectDir)..\..\src\bin\Debug\Thrift.dll"</PreBuildEvent> </PropertyGroup> -</Project> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/thrift/blob/5a61438a/test/ThriftTest.thrift ---------------------------------------------------------------------- diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift index d191afd..be000b6 100644 --- a/test/ThriftTest.thrift +++ b/test/ThriftTest.thrift @@ -375,11 +375,3 @@ 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; -}
