THRIFT-2768: Whitespace Fixup Client: C#, Delphi Patch: Jens Geyer
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d5436f5c Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d5436f5c Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d5436f5c Branch: refs/heads/master Commit: d5436f5cf7a100d89abb3d125d8f241ca7dc925e Parents: 23b60b5 Author: Jens Geyer <[email protected]> Authored: Fri Oct 3 19:50:38 2014 +0200 Committer: Jens Geyer <[email protected]> Committed: Fri Oct 3 20:12:40 2014 +0200 ---------------------------------------------------------------------- lib/csharp/Makefile.am | 8 +- lib/csharp/ThriftMSBuildTask/ThriftBuild.cs | 420 +-- lib/csharp/src/Collections/TCollections.cs | 132 +- lib/csharp/src/Collections/THashSet.cs | 216 +- lib/csharp/src/Protocol/TAbstractBase.cs | 14 +- lib/csharp/src/Protocol/TBase.cs | 14 +- lib/csharp/src/Protocol/TBase64Utils.cs | 142 +- lib/csharp/src/Protocol/TBinaryProtocol.cs | 668 ++-- lib/csharp/src/Protocol/TCompactProtocol.cs | 74 +- lib/csharp/src/Protocol/TField.cs | 56 +- lib/csharp/src/Protocol/TJSONProtocol.cs | 2100 ++++++------ lib/csharp/src/Protocol/TList.cs | 42 +- lib/csharp/src/Protocol/TMap.cs | 56 +- lib/csharp/src/Protocol/TMessage.cs | 56 +- lib/csharp/src/Protocol/TMessageType.cs | 14 +- .../src/Protocol/TMultiplexedProcessor.cs | 36 +- lib/csharp/src/Protocol/TMultiplexedProtocol.cs | 16 +- lib/csharp/src/Protocol/TProtocol.cs | 110 +- lib/csharp/src/Protocol/TProtocolDecorator.cs | 24 +- lib/csharp/src/Protocol/TProtocolException.cs | 66 +- lib/csharp/src/Protocol/TProtocolFactory.cs | 8 +- lib/csharp/src/Protocol/TProtocolUtil.cs | 140 +- lib/csharp/src/Protocol/TSet.cs | 50 +- lib/csharp/src/Protocol/TStruct.cs | 28 +- lib/csharp/src/Protocol/TType.cs | 32 +- lib/csharp/src/Server/TSimpleServer.cs | 2 +- lib/csharp/src/Server/TThreadPoolServer.cs | 2 +- lib/csharp/src/Server/TThreadedServer.cs | 2 +- lib/csharp/src/TApplicationException.cs | 224 +- lib/csharp/src/TException.cs | 20 +- lib/csharp/src/TProcessor.cs | 8 +- lib/csharp/src/Thrift.WP7.csproj | 2 +- lib/csharp/src/Thrift.sln | 54 +- lib/csharp/src/Transport/TBufferedTransport.cs | 158 +- lib/csharp/src/Transport/TFramedTransport.cs | 284 +- lib/csharp/src/Transport/THttpClient.cs | 374 +-- lib/csharp/src/Transport/THttpHandler.cs | 30 +- lib/csharp/src/Transport/TMemoryBuffer.cs | 146 +- .../src/Transport/TNamedPipeClientTransport.cs | 114 +- .../src/Transport/TNamedPipeServerTransport.cs | 188 +- lib/csharp/src/Transport/TServerSocket.cs | 190 +- lib/csharp/src/Transport/TServerTransport.cs | 28 +- lib/csharp/src/Transport/TSocket.cs | 270 +- lib/csharp/src/Transport/TStreamTransport.cs | 154 +- lib/csharp/src/Transport/TTLSServerSocket.cs | 320 +- lib/csharp/src/Transport/TTLSSocket.cs | 544 +-- lib/csharp/src/Transport/TTransport.cs | 76 +- lib/csharp/src/Transport/TTransportException.cs | 68 +- lib/csharp/src/Transport/TTransportFactory.cs | 28 +- lib/csharp/test/JSON/JSONTest.csproj | 2 +- lib/csharp/test/JSON/Program.cs | 86 +- lib/csharp/test/JSON/Properties/AssemblyInfo.cs | 10 +- lib/csharp/test/JSON/app.config | 42 +- .../Multiplex/Client/Multiplex.Test.Client.cs | 6 +- .../test/Multiplex/Multiplex.Test.Common.cs | 4 +- .../Multiplex/Server/Multiplex.Test.Server.cs | 12 +- lib/csharp/test/Multiplex/maketest.sh | 6 +- lib/csharp/test/ThriftTest/Program.cs | 56 +- lib/csharp/test/ThriftTest/TestClient.cs | 898 ++--- lib/csharp/test/ThriftTest/TestServer.cs | 776 ++--- lib/delphi/src/Thrift.Collections.pas | 1238 +++---- lib/delphi/src/Thrift.Console.pas | 266 +- lib/delphi/src/Thrift.Processor.Multiplex.pas | 52 +- lib/delphi/src/Thrift.Protocol.Multiplex.pas | 36 +- lib/delphi/src/Thrift.Protocol.pas | 3102 +++++++++--------- lib/delphi/src/Thrift.Serializer.pas | 6 +- lib/delphi/src/Thrift.Server.pas | 24 +- lib/delphi/src/Thrift.Stream.pas | 600 ++-- lib/delphi/src/Thrift.Transport.Pipes.pas | 2 +- lib/delphi/src/Thrift.Transport.pas | 2778 ++++++++-------- lib/delphi/src/Thrift.TypeRegistry.pas | 190 +- lib/delphi/src/Thrift.Utils.pas | 236 +- lib/delphi/test/TestClient.pas | 8 +- lib/delphi/test/TestServer.pas | 8 +- lib/delphi/test/TestServerEvents.pas | 188 +- lib/delphi/test/codegen/README.md | 8 +- lib/delphi/test/codegen/ReservedKeywords.thrift | 2 +- .../codegen/run-Pascal-Codegen-Tests.bat.tmpl | 36 +- .../test/multiplexed/Multiplex.Client.Main.pas | 14 +- .../test/multiplexed/Multiplex.Server.Main.pas | 44 +- .../test/multiplexed/Multiplex.Test.Client.dpr | 26 +- .../test/multiplexed/Multiplex.Test.Common.pas | 70 +- .../test/multiplexed/Multiplex.Test.Server.dpr | 28 +- lib/delphi/test/skip/README.md | 10 +- .../test/typeregistry/TestTypeRegistry.dpr | 66 +- .../csharp/CsharpClient/CsharpClient.csproj | 174 +- .../CsharpClient/Properties/AssemblyInfo.cs | 110 +- tutorial/csharp/CsharpServer/CsharpServer.cs | 224 +- .../csharp/CsharpServer/CsharpServer.csproj | 174 +- .../CsharpServer/Properties/AssemblyInfo.cs | 110 +- tutorial/csharp/tutorial.sln | 78 +- tutorial/delphi/DelphiClient/DelphiClient.dproj | 238 +- tutorial/delphi/DelphiServer/DelphiServer.dproj | 236 +- tutorial/delphi/Tutorial.groupproj | 96 +- 94 files changed, 10098 insertions(+), 10086 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/Makefile.am ---------------------------------------------------------------------- diff --git a/lib/csharp/Makefile.am b/lib/csharp/Makefile.am index 1c75aa1..7b2b618 100644 --- a/lib/csharp/Makefile.am +++ b/lib/csharp/Makefile.am @@ -76,15 +76,15 @@ endif all-local: Thrift.dll Thrift.dll: $(THRIFTCODE) - $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library /reference:System.Web $(MONO_DEFINES) + $(CSC) $(THRIFTCODE) /out:Thrift.dll /target:library /reference:System.Web $(MONO_DEFINES) clean-local: - $(RM) Thrift.dll + $(RM) Thrift.dll # run csharp tests? # check: -# cd test/ThriftTest && ./maketest.sh -# cd test/Multiplex && ./maketest.sh +# cd test/ThriftTest && ./maketest.sh +# cd test/Multiplex && ./maketest.sh EXTRA_DIST = \ $(THRIFTCODE) \ http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs b/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs index 75bb339..4e6d301 100644 --- a/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs +++ b/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs @@ -33,214 +33,214 @@ using System.Diagnostics; namespace ThriftMSBuildTask { - /// <summary> - /// MSBuild Task to generate csharp from .thrift files, and compile the code into a library: ThriftImpl.dll - /// </summary> - public class ThriftBuild : Task - { - /// <summary> - /// The full path to the thrift.exe compiler - /// </summary> - [Required] - public ITaskItem ThriftExecutable - { - get; - set; - } - - /// <summary> - /// The full path to a thrift.dll C# library - /// </summary> - [Required] - public ITaskItem ThriftLibrary - { - get; - set; - } - - /// <summary> - /// A direcotry containing .thrift files - /// </summary> - [Required] - public ITaskItem ThriftDefinitionDir - { - get; - set; - } - - /// <summary> - /// The name of the auto-gen and compiled thrift library. It will placed in - /// the same directory as ThriftLibrary - /// </summary> - [Required] - public ITaskItem OutputName - { - get; - set; - } - - /// <summary> - /// The full path to the compiled ThriftLibrary. This allows msbuild tasks to use this - /// output as a variable for use elsewhere. - /// </summary> - [Output] - public ITaskItem ThriftImplementation - { - get { return thriftImpl; } - } - - private ITaskItem thriftImpl; - private const string lastCompilationName = "LAST_COMP_TIMESTAMP"; - - //use the Message Build Task to write something to build log - private void LogMessage(string text, MessageImportance importance) - { - Message m = new Message(); - m.Text = text; - m.Importance = importance.ToString(); - m.BuildEngine = this.BuildEngine; - m.Execute(); - } - - //recursively find .cs files in srcDir, paths should initially be non-null and empty - private void FindSourcesHelper(string srcDir, List<string> paths) - { - string[] files = Directory.GetFiles(srcDir, "*.cs"); - foreach (string f in files) - { - paths.Add(f); - } - string[] dirs = Directory.GetDirectories(srcDir); - foreach (string dir in dirs) - { - FindSourcesHelper(dir, paths); - } - } - - /// <summary> - /// Quote paths with spaces - /// </summary> - private string SafePath(string path) - { - if (path.Contains(' ') && !path.StartsWith("\"")) - { - return "\"" + path + "\""; - } - return path; - } - - private ITaskItem[] FindSources(string srcDir) - { - List<string> files = new List<string>(); - FindSourcesHelper(srcDir, files); - ITaskItem[] items = new ITaskItem[files.Count]; - for (int i = 0; i < items.Length; i++) - { - items[i] = new TaskItem(files[i]); - } - return items; - } - - private string LastWriteTime(string defDir) - { - string[] files = Directory.GetFiles(defDir, "*.thrift"); - DateTime d = (new DirectoryInfo(defDir)).LastWriteTime; - foreach(string file in files) - { - FileInfo f = new FileInfo(file); - DateTime curr = f.LastWriteTime; - if (DateTime.Compare(curr, d) > 0) - { - d = curr; - } - } - return d.ToFileTimeUtc().ToString(); - } - - public override bool Execute() - { - string defDir = SafePath(ThriftDefinitionDir.ItemSpec); - //look for last compilation timestamp - string lastBuildPath = Path.Combine(defDir, lastCompilationName); - DirectoryInfo defDirInfo = new DirectoryInfo(defDir); - string lastWrite = LastWriteTime(defDir); - if (File.Exists(lastBuildPath)) - { - string lastComp = File.ReadAllText(lastBuildPath); - //don't recompile if the thrift library has been updated since lastComp - FileInfo f = new FileInfo(ThriftLibrary.ItemSpec); - string thriftLibTime = f.LastWriteTimeUtc.ToFileTimeUtc().ToString(); - if (lastComp.CompareTo(thriftLibTime) < 0) - { - //new thrift library, do a compile - lastWrite = thriftLibTime; - } - else if (lastComp == lastWrite || (lastComp == thriftLibTime && lastComp.CompareTo(lastWrite) > 0)) - { - //the .thrift dir hasn't been written to since last compilation, don't need to do anything - LogMessage("ThriftImpl up-to-date", MessageImportance.High); - return true; - } - } - - //find the directory of the thriftlibrary (that's where output will go) - FileInfo thriftLibInfo = new FileInfo(SafePath(ThriftLibrary.ItemSpec)); - string thriftDir = thriftLibInfo.Directory.FullName; - - string genDir = Path.Combine(thriftDir, "gen-csharp"); - if (Directory.Exists(genDir)) - { - try - { - Directory.Delete(genDir, true); - } - catch { /*eh i tried, just over-write now*/} - } - - //run the thrift executable to generate C# - foreach (string thriftFile in Directory.GetFiles(defDir, "*.thrift")) - { - LogMessage("Generating code for: " + thriftFile, MessageImportance.Normal); - Process p = new Process(); - p.StartInfo.FileName = SafePath(ThriftExecutable.ItemSpec); - p.StartInfo.Arguments = "--gen csharp -o " + SafePath(thriftDir) + " -r " + thriftFile; - p.StartInfo.UseShellExecute = false; - p.StartInfo.CreateNoWindow = true; - p.StartInfo.RedirectStandardOutput = false; - p.Start(); - p.WaitForExit(); - if (p.ExitCode != 0) - { - LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); - return false; - } - if (p.ExitCode != 0) - { - LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); - return false; - } - } - - Csc csc = new Csc(); - csc.TargetType = "library"; - csc.References = new ITaskItem[] { new TaskItem(ThriftLibrary.ItemSpec) }; - csc.EmitDebugInformation = true; - string outputPath = Path.Combine(thriftDir, OutputName.ItemSpec); - csc.OutputAssembly = new TaskItem(outputPath); - csc.Sources = FindSources(Path.Combine(thriftDir, "gen-csharp")); - csc.BuildEngine = this.BuildEngine; - LogMessage("Compiling generated cs...", MessageImportance.Normal); - if (!csc.Execute()) - { - return false; - } - - //write file to defDir to indicate a build was successfully completed - File.WriteAllText(lastBuildPath, lastWrite); - - thriftImpl = new TaskItem(outputPath); - - return true; - } - } + /// <summary> + /// MSBuild Task to generate csharp from .thrift files, and compile the code into a library: ThriftImpl.dll + /// </summary> + public class ThriftBuild : Task + { + /// <summary> + /// The full path to the thrift.exe compiler + /// </summary> + [Required] + public ITaskItem ThriftExecutable + { + get; + set; + } + + /// <summary> + /// The full path to a thrift.dll C# library + /// </summary> + [Required] + public ITaskItem ThriftLibrary + { + get; + set; + } + + /// <summary> + /// A direcotry containing .thrift files + /// </summary> + [Required] + public ITaskItem ThriftDefinitionDir + { + get; + set; + } + + /// <summary> + /// The name of the auto-gen and compiled thrift library. It will placed in + /// the same directory as ThriftLibrary + /// </summary> + [Required] + public ITaskItem OutputName + { + get; + set; + } + + /// <summary> + /// The full path to the compiled ThriftLibrary. This allows msbuild tasks to use this + /// output as a variable for use elsewhere. + /// </summary> + [Output] + public ITaskItem ThriftImplementation + { + get { return thriftImpl; } + } + + private ITaskItem thriftImpl; + private const string lastCompilationName = "LAST_COMP_TIMESTAMP"; + + //use the Message Build Task to write something to build log + private void LogMessage(string text, MessageImportance importance) + { + Message m = new Message(); + m.Text = text; + m.Importance = importance.ToString(); + m.BuildEngine = this.BuildEngine; + m.Execute(); + } + + //recursively find .cs files in srcDir, paths should initially be non-null and empty + private void FindSourcesHelper(string srcDir, List<string> paths) + { + string[] files = Directory.GetFiles(srcDir, "*.cs"); + foreach (string f in files) + { + paths.Add(f); + } + string[] dirs = Directory.GetDirectories(srcDir); + foreach (string dir in dirs) + { + FindSourcesHelper(dir, paths); + } + } + + /// <summary> + /// Quote paths with spaces + /// </summary> + private string SafePath(string path) + { + if (path.Contains(' ') && !path.StartsWith("\"")) + { + return "\"" + path + "\""; + } + return path; + } + + private ITaskItem[] FindSources(string srcDir) + { + List<string> files = new List<string>(); + FindSourcesHelper(srcDir, files); + ITaskItem[] items = new ITaskItem[files.Count]; + for (int i = 0; i < items.Length; i++) + { + items[i] = new TaskItem(files[i]); + } + return items; + } + + private string LastWriteTime(string defDir) + { + string[] files = Directory.GetFiles(defDir, "*.thrift"); + DateTime d = (new DirectoryInfo(defDir)).LastWriteTime; + foreach(string file in files) + { + FileInfo f = new FileInfo(file); + DateTime curr = f.LastWriteTime; + if (DateTime.Compare(curr, d) > 0) + { + d = curr; + } + } + return d.ToFileTimeUtc().ToString(); + } + + public override bool Execute() + { + string defDir = SafePath(ThriftDefinitionDir.ItemSpec); + //look for last compilation timestamp + string lastBuildPath = Path.Combine(defDir, lastCompilationName); + DirectoryInfo defDirInfo = new DirectoryInfo(defDir); + string lastWrite = LastWriteTime(defDir); + if (File.Exists(lastBuildPath)) + { + string lastComp = File.ReadAllText(lastBuildPath); + //don't recompile if the thrift library has been updated since lastComp + FileInfo f = new FileInfo(ThriftLibrary.ItemSpec); + string thriftLibTime = f.LastWriteTimeUtc.ToFileTimeUtc().ToString(); + if (lastComp.CompareTo(thriftLibTime) < 0) + { + //new thrift library, do a compile + lastWrite = thriftLibTime; + } + else if (lastComp == lastWrite || (lastComp == thriftLibTime && lastComp.CompareTo(lastWrite) > 0)) + { + //the .thrift dir hasn't been written to since last compilation, don't need to do anything + LogMessage("ThriftImpl up-to-date", MessageImportance.High); + return true; + } + } + + //find the directory of the thriftlibrary (that's where output will go) + FileInfo thriftLibInfo = new FileInfo(SafePath(ThriftLibrary.ItemSpec)); + string thriftDir = thriftLibInfo.Directory.FullName; + + string genDir = Path.Combine(thriftDir, "gen-csharp"); + if (Directory.Exists(genDir)) + { + try + { + Directory.Delete(genDir, true); + } + catch { /*eh i tried, just over-write now*/} + } + + //run the thrift executable to generate C# + foreach (string thriftFile in Directory.GetFiles(defDir, "*.thrift")) + { + LogMessage("Generating code for: " + thriftFile, MessageImportance.Normal); + Process p = new Process(); + p.StartInfo.FileName = SafePath(ThriftExecutable.ItemSpec); + p.StartInfo.Arguments = "--gen csharp -o " + SafePath(thriftDir) + " -r " + thriftFile; + p.StartInfo.UseShellExecute = false; + p.StartInfo.CreateNoWindow = true; + p.StartInfo.RedirectStandardOutput = false; + p.Start(); + p.WaitForExit(); + if (p.ExitCode != 0) + { + LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); + return false; + } + if (p.ExitCode != 0) + { + LogMessage("thrift.exe failed to compile " + thriftFile, MessageImportance.High); + return false; + } + } + + Csc csc = new Csc(); + csc.TargetType = "library"; + csc.References = new ITaskItem[] { new TaskItem(ThriftLibrary.ItemSpec) }; + csc.EmitDebugInformation = true; + string outputPath = Path.Combine(thriftDir, OutputName.ItemSpec); + csc.OutputAssembly = new TaskItem(outputPath); + csc.Sources = FindSources(Path.Combine(thriftDir, "gen-csharp")); + csc.BuildEngine = this.BuildEngine; + LogMessage("Compiling generated cs...", MessageImportance.Normal); + if (!csc.Execute()) + { + return false; + } + + //write file to defDir to indicate a build was successfully completed + File.WriteAllText(lastBuildPath, lastWrite); + + thriftImpl = new TaskItem(outputPath); + + return true; + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Collections/TCollections.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Collections/TCollections.cs b/lib/csharp/src/Collections/TCollections.cs index 23fd8da..f0bb1de 100644 --- a/lib/csharp/src/Collections/TCollections.cs +++ b/lib/csharp/src/Collections/TCollections.cs @@ -21,74 +21,74 @@ using System.Collections; namespace Thrift.Collections { - public class TCollections - { - /// <summary> - /// This will return true if the two collections are value-wise the same. - /// If the collection contains a collection, the collections will be compared using this method. - /// </summary> - public static bool Equals (IEnumerable first, IEnumerable second) - { - if (first == null && second == null) - { - return true; - } - if (first == null || second == null) - { - return false; - } - IEnumerator fiter = first.GetEnumerator (); - IEnumerator siter = second.GetEnumerator (); + public class TCollections + { + /// <summary> + /// This will return true if the two collections are value-wise the same. + /// If the collection contains a collection, the collections will be compared using this method. + /// </summary> + public static bool Equals (IEnumerable first, IEnumerable second) + { + if (first == null && second == null) + { + return true; + } + if (first == null || second == null) + { + return false; + } + IEnumerator fiter = first.GetEnumerator (); + IEnumerator siter = second.GetEnumerator (); - bool fnext = fiter.MoveNext (); - bool snext = siter.MoveNext (); - while (fnext && snext) - { - IEnumerable fenum = fiter.Current as IEnumerable; - IEnumerable senum = siter.Current as IEnumerable; - if (fenum != null && senum != null) - { - if (!Equals(fenum, senum)) - { - return false; - } - } - else if (fenum == null ^ senum == null) - { - return false; - } - else if (!Equals(fiter.Current, siter.Current)) - { - return false; - } - fnext = fiter.MoveNext(); - snext = siter.MoveNext(); - } + bool fnext = fiter.MoveNext (); + bool snext = siter.MoveNext (); + while (fnext && snext) + { + IEnumerable fenum = fiter.Current as IEnumerable; + IEnumerable senum = siter.Current as IEnumerable; + if (fenum != null && senum != null) + { + if (!Equals(fenum, senum)) + { + return false; + } + } + else if (fenum == null ^ senum == null) + { + return false; + } + else if (!Equals(fiter.Current, siter.Current)) + { + return false; + } + fnext = fiter.MoveNext(); + snext = siter.MoveNext(); + } - return fnext == snext; - } + return fnext == snext; + } - /// <summary> - /// This returns a hashcode based on the value of the enumerable. - /// </summary> - public static int GetHashCode (IEnumerable enumerable) - { - if (enumerable == null) - { - return 0; - } + /// <summary> + /// This returns a hashcode based on the value of the enumerable. + /// </summary> + public static int GetHashCode (IEnumerable enumerable) + { + if (enumerable == null) + { + return 0; + } - int hashcode = 0; - foreach (Object obj in enumerable) - { - IEnumerable enum2 = obj as IEnumerable; - int objHash = enum2 == null ? obj.GetHashCode () : GetHashCode (enum2); - unchecked - { - hashcode = (hashcode * 397) ^ (objHash); - } - } - return hashcode; - } - } + int hashcode = 0; + foreach (Object obj in enumerable) + { + IEnumerable enum2 = obj as IEnumerable; + int objHash = enum2 == null ? obj.GetHashCode () : GetHashCode (enum2); + unchecked + { + hashcode = (hashcode * 397) ^ (objHash); + } + } + return hashcode; + } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Collections/THashSet.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Collections/THashSet.cs b/lib/csharp/src/Collections/THashSet.cs index b71a8d2..e29271a 100644 --- a/lib/csharp/src/Collections/THashSet.cs +++ b/lib/csharp/src/Collections/THashSet.cs @@ -30,131 +30,131 @@ namespace Thrift.Collections #if SILVERLIGHT [DataContract] #else - [Serializable] + [Serializable] #endif - public class THashSet<T> : ICollection<T> - { + public class THashSet<T> : ICollection<T> + { #if NET_2_0 || SILVERLIGHT #if SILVERLIGHT [DataMember] #endif TDictSet<T> set = new TDictSet<T>(); #else - HashSet<T> set = new HashSet<T>(); + HashSet<T> set = new HashSet<T>(); #endif - public int Count - { - get { return set.Count; } - } - - public bool IsReadOnly - { - get { return false; } - } - - public void Add(T item) - { - set.Add(item); - } - - public void Clear() - { - set.Clear(); - } - - public bool Contains(T item) - { - return set.Contains(item); - } - - public void CopyTo(T[] array, int arrayIndex) - { - set.CopyTo(array, arrayIndex); - } - - public IEnumerator GetEnumerator() - { - return set.GetEnumerator(); - } - - IEnumerator<T> IEnumerable<T>.GetEnumerator() - { - return ((IEnumerable<T>)set).GetEnumerator(); - } - - public bool Remove(T item) - { - return set.Remove(item); - } + public int Count + { + get { return set.Count; } + } + + public bool IsReadOnly + { + get { return false; } + } + + public void Add(T item) + { + set.Add(item); + } + + public void Clear() + { + set.Clear(); + } + + public bool Contains(T item) + { + return set.Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + set.CopyTo(array, arrayIndex); + } + + public IEnumerator GetEnumerator() + { + return set.GetEnumerator(); + } + + IEnumerator<T> IEnumerable<T>.GetEnumerator() + { + return ((IEnumerable<T>)set).GetEnumerator(); + } + + public bool Remove(T item) + { + return set.Remove(item); + } #if NET_2_0 || SILVERLIGHT #if SILVERLIGHT [DataContract] #endif private class TDictSet<V> : ICollection<V> - { + { #if SILVERLIGHT [DataMember] #endif - Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>(); - - public int Count - { - get { return dict.Count; } - } - - public bool IsReadOnly - { - get { return false; } - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)dict.Keys).GetEnumerator(); - } - - IEnumerator<V> IEnumerable<V>.GetEnumerator() - { - return dict.Keys.GetEnumerator(); - } - - public bool Add(V item) - { - if (!dict.ContainsKey(item)) - { - dict[item] = this; - return true; - } - - return false; - } - - void ICollection<V>.Add(V item) - { - Add(item); - } - - public void Clear() - { - dict.Clear(); - } - - public bool Contains(V item) - { - return dict.ContainsKey(item); - } - - public void CopyTo(V[] array, int arrayIndex) - { - dict.Keys.CopyTo(array, arrayIndex); - } - - public bool Remove(V item) - { - return dict.Remove(item); - } - } + Dictionary<V, TDictSet<V>> dict = new Dictionary<V, TDictSet<V>>(); + + public int Count + { + get { return dict.Count; } + } + + public bool IsReadOnly + { + get { return false; } + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)dict.Keys).GetEnumerator(); + } + + IEnumerator<V> IEnumerable<V>.GetEnumerator() + { + return dict.Keys.GetEnumerator(); + } + + public bool Add(V item) + { + if (!dict.ContainsKey(item)) + { + dict[item] = this; + return true; + } + + return false; + } + + void ICollection<V>.Add(V item) + { + Add(item); + } + + public void Clear() + { + dict.Clear(); + } + + public bool Contains(V item) + { + return dict.ContainsKey(item); + } + + public void CopyTo(V[] array, int arrayIndex) + { + dict.Keys.CopyTo(array, arrayIndex); + } + + public bool Remove(V item) + { + return dict.Remove(item); + } + } #endif - } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TAbstractBase.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TAbstractBase.cs b/lib/csharp/src/Protocol/TAbstractBase.cs index de2e3db..c0d5abe 100644 --- a/lib/csharp/src/Protocol/TAbstractBase.cs +++ b/lib/csharp/src/Protocol/TAbstractBase.cs @@ -19,11 +19,11 @@ namespace Thrift.Protocol { - public interface TAbstractBase - { - /// - /// Writes the objects out to the protocol - /// - void Write(TProtocol tProtocol); - } + public interface TAbstractBase + { + /// + /// Writes the objects out to the protocol + /// + void Write(TProtocol tProtocol); + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TBase.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TBase.cs b/lib/csharp/src/Protocol/TBase.cs index b8b36fb..350ff49 100644 --- a/lib/csharp/src/Protocol/TBase.cs +++ b/lib/csharp/src/Protocol/TBase.cs @@ -19,11 +19,11 @@ namespace Thrift.Protocol { - public interface TBase : TAbstractBase - { - /// - /// Reads the TObject from the given input protocol. - /// - void Read(TProtocol tProtocol); - } + public interface TBase : TAbstractBase + { + /// + /// Reads the TObject from the given input protocol. + /// + void Read(TProtocol tProtocol); + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TBase64Utils.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TBase64Utils.cs b/lib/csharp/src/Protocol/TBase64Utils.cs index 78c3767..9eaaebd 100644 --- a/lib/csharp/src/Protocol/TBase64Utils.cs +++ b/lib/csharp/src/Protocol/TBase64Utils.cs @@ -21,80 +21,80 @@ using System; namespace Thrift.Protocol { - internal static class TBase64Utils - { - internal const string ENCODE_TABLE = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + internal static class TBase64Utils + { + internal const string ENCODE_TABLE = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - internal static void encode(byte[] src, int srcOff, int len, byte[] dst, - int dstOff) - { - dst[dstOff] = (byte)ENCODE_TABLE[(src[srcOff] >> 2) & 0x3F]; - if (len == 3) - { - dst[dstOff + 1] = - (byte)ENCODE_TABLE[ - ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)]; - dst[dstOff + 2] = - (byte)ENCODE_TABLE[ - ((src[srcOff + 1] << 2) & 0x3C) | ((src[srcOff + 2] >> 6) & 0x03)]; - dst[dstOff + 3] = - (byte)ENCODE_TABLE[src[srcOff + 2] & 0x3F]; - } - else if (len == 2) - { - dst[dstOff + 1] = - (byte)ENCODE_TABLE[ - ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)]; - dst[dstOff + 2] = - (byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3C]; + internal static void encode(byte[] src, int srcOff, int len, byte[] dst, + int dstOff) + { + dst[dstOff] = (byte)ENCODE_TABLE[(src[srcOff] >> 2) & 0x3F]; + if (len == 3) + { + dst[dstOff + 1] = + (byte)ENCODE_TABLE[ + ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)]; + dst[dstOff + 2] = + (byte)ENCODE_TABLE[ + ((src[srcOff + 1] << 2) & 0x3C) | ((src[srcOff + 2] >> 6) & 0x03)]; + dst[dstOff + 3] = + (byte)ENCODE_TABLE[src[srcOff + 2] & 0x3F]; + } + else if (len == 2) + { + dst[dstOff + 1] = + (byte)ENCODE_TABLE[ + ((src[srcOff] << 4) & 0x30) | ((src[srcOff + 1] >> 4) & 0x0F)]; + dst[dstOff + 2] = + (byte)ENCODE_TABLE[(src[srcOff + 1] << 2) & 0x3C]; - } - else - { // len == 1) { - dst[dstOff + 1] = - (byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x30]; - } - } + } + else + { // len == 1) { + dst[dstOff + 1] = + (byte)ENCODE_TABLE[(src[srcOff] << 4) & 0x30]; + } + } - private static int[] DECODE_TABLE = { - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, - 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, - 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, - -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, - 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - }; + private static int[] DECODE_TABLE = { + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, + 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, + 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, + -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, + 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + }; - internal static void decode(byte[] src, int srcOff, int len, byte[] dst, - int dstOff) - { - dst[dstOff] = (byte) - ((DECODE_TABLE[src[srcOff] & 0x0FF] << 2) | - (DECODE_TABLE[src[srcOff + 1] & 0x0FF] >> 4)); - if (len > 2) - { - dst[dstOff + 1] = (byte) - (((DECODE_TABLE[src[srcOff + 1] & 0x0FF] << 4) & 0xF0) | - (DECODE_TABLE[src[srcOff + 2] & 0x0FF] >> 2)); - if (len > 3) - { - dst[dstOff + 2] = (byte) - (((DECODE_TABLE[src[srcOff + 2] & 0x0FF] << 6) & 0xC0) | - DECODE_TABLE[src[srcOff + 3] & 0x0FF]); - } - } - } + internal static void decode(byte[] src, int srcOff, int len, byte[] dst, + int dstOff) + { + dst[dstOff] = (byte) + ((DECODE_TABLE[src[srcOff] & 0x0FF] << 2) | + (DECODE_TABLE[src[srcOff + 1] & 0x0FF] >> 4)); + if (len > 2) + { + dst[dstOff + 1] = (byte) + (((DECODE_TABLE[src[srcOff + 1] & 0x0FF] << 4) & 0xF0) | + (DECODE_TABLE[src[srcOff + 2] & 0x0FF] >> 2)); + if (len > 3) + { + dst[dstOff + 2] = (byte) + (((DECODE_TABLE[src[srcOff + 2] & 0x0FF] << 6) & 0xC0) | + DECODE_TABLE[src[srcOff + 3] & 0x0FF]); + } + } + } - } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TBinaryProtocol.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs index 2e86a70..4eceb86 100644 --- a/lib/csharp/src/Protocol/TBinaryProtocol.cs +++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs @@ -27,324 +27,324 @@ using Thrift.Transport; namespace Thrift.Protocol { - public class TBinaryProtocol : TProtocol - { - protected const uint VERSION_MASK = 0xffff0000; - protected const uint VERSION_1 = 0x80010000; - - protected bool strictRead_ = false; - protected bool strictWrite_ = true; - - #region BinaryProtocol Factory - /** - * Factory - */ - public class Factory : TProtocolFactory { - - protected bool strictRead_ = false; - protected bool strictWrite_ = true; - - public Factory() - :this(false, true) - { - } - - public Factory(bool strictRead, bool strictWrite) - { - strictRead_ = strictRead; - strictWrite_ = strictWrite; - } - - public TProtocol GetProtocol(TTransport trans) { - return new TBinaryProtocol(trans, strictRead_, strictWrite_); - } - } - - #endregion - - public TBinaryProtocol(TTransport trans) - : this(trans, false, true) - { - } - - public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite) - :base(trans) - { - strictRead_ = strictRead; - strictWrite_ = strictWrite; - } - - #region Write Methods - - public override void WriteMessageBegin(TMessage message) - { - if (strictWrite_) - { - uint version = VERSION_1 | (uint)(message.Type); - WriteI32((int)version); - WriteString(message.Name); - WriteI32(message.SeqID); - } - else - { - WriteString(message.Name); - WriteByte((sbyte)message.Type); - WriteI32(message.SeqID); - } - } - - public override void WriteMessageEnd() - { - } - - public override void WriteStructBegin(TStruct struc) - { - } - - public override void WriteStructEnd() - { - } - - public override void WriteFieldBegin(TField field) - { - WriteByte((sbyte)field.Type); - WriteI16(field.ID); - } - - public override void WriteFieldEnd() - { - } - - public override void WriteFieldStop() - { - WriteByte((sbyte)TType.Stop); - } - - public override void WriteMapBegin(TMap map) - { - WriteByte((sbyte)map.KeyType); - WriteByte((sbyte)map.ValueType); - WriteI32(map.Count); - } - - public override void WriteMapEnd() - { - } - - public override void WriteListBegin(TList list) - { - WriteByte((sbyte)list.ElementType); - WriteI32(list.Count); - } - - public override void WriteListEnd() - { - } - - public override void WriteSetBegin(TSet set) - { - WriteByte((sbyte)set.ElementType); - WriteI32(set.Count); - } - - public override void WriteSetEnd() - { - } - - public override void WriteBool(bool b) - { - WriteByte(b ? (sbyte)1 : (sbyte)0); - } - - private byte[] bout = new byte[1]; - public override void WriteByte(sbyte b) - { - bout[0] = (byte)b; - trans.Write(bout, 0, 1); - } - - private byte[] i16out = new byte[2]; - public override void WriteI16(short s) - { - i16out[0] = (byte)(0xff & (s >> 8)); - i16out[1] = (byte)(0xff & s); - trans.Write(i16out, 0, 2); - } - - private byte[] i32out = new byte[4]; - public override void WriteI32(int i32) - { - i32out[0] = (byte)(0xff & (i32 >> 24)); - i32out[1] = (byte)(0xff & (i32 >> 16)); - i32out[2] = (byte)(0xff & (i32 >> 8)); - i32out[3] = (byte)(0xff & i32); - trans.Write(i32out, 0, 4); - } - - private byte[] i64out = new byte[8]; - public override void WriteI64(long i64) - { - i64out[0] = (byte)(0xff & (i64 >> 56)); - i64out[1] = (byte)(0xff & (i64 >> 48)); - i64out[2] = (byte)(0xff & (i64 >> 40)); - i64out[3] = (byte)(0xff & (i64 >> 32)); - i64out[4] = (byte)(0xff & (i64 >> 24)); - i64out[5] = (byte)(0xff & (i64 >> 16)); - i64out[6] = (byte)(0xff & (i64 >> 8)); - i64out[7] = (byte)(0xff & i64); - trans.Write(i64out, 0, 8); - } - - public override void WriteDouble(double d) - { + public class TBinaryProtocol : TProtocol + { + protected const uint VERSION_MASK = 0xffff0000; + protected const uint VERSION_1 = 0x80010000; + + protected bool strictRead_ = false; + protected bool strictWrite_ = true; + + #region BinaryProtocol Factory + /** + * Factory + */ + public class Factory : TProtocolFactory { + + protected bool strictRead_ = false; + protected bool strictWrite_ = true; + + public Factory() + :this(false, true) + { + } + + public Factory(bool strictRead, bool strictWrite) + { + strictRead_ = strictRead; + strictWrite_ = strictWrite; + } + + public TProtocol GetProtocol(TTransport trans) { + return new TBinaryProtocol(trans, strictRead_, strictWrite_); + } + } + + #endregion + + public TBinaryProtocol(TTransport trans) + : this(trans, false, true) + { + } + + public TBinaryProtocol(TTransport trans, bool strictRead, bool strictWrite) + :base(trans) + { + strictRead_ = strictRead; + strictWrite_ = strictWrite; + } + + #region Write Methods + + public override void WriteMessageBegin(TMessage message) + { + if (strictWrite_) + { + uint version = VERSION_1 | (uint)(message.Type); + WriteI32((int)version); + WriteString(message.Name); + WriteI32(message.SeqID); + } + else + { + WriteString(message.Name); + WriteByte((sbyte)message.Type); + WriteI32(message.SeqID); + } + } + + public override void WriteMessageEnd() + { + } + + public override void WriteStructBegin(TStruct struc) + { + } + + public override void WriteStructEnd() + { + } + + public override void WriteFieldBegin(TField field) + { + WriteByte((sbyte)field.Type); + WriteI16(field.ID); + } + + public override void WriteFieldEnd() + { + } + + public override void WriteFieldStop() + { + WriteByte((sbyte)TType.Stop); + } + + public override void WriteMapBegin(TMap map) + { + WriteByte((sbyte)map.KeyType); + WriteByte((sbyte)map.ValueType); + WriteI32(map.Count); + } + + public override void WriteMapEnd() + { + } + + public override void WriteListBegin(TList list) + { + WriteByte((sbyte)list.ElementType); + WriteI32(list.Count); + } + + public override void WriteListEnd() + { + } + + public override void WriteSetBegin(TSet set) + { + WriteByte((sbyte)set.ElementType); + WriteI32(set.Count); + } + + public override void WriteSetEnd() + { + } + + public override void WriteBool(bool b) + { + WriteByte(b ? (sbyte)1 : (sbyte)0); + } + + private byte[] bout = new byte[1]; + public override void WriteByte(sbyte b) + { + bout[0] = (byte)b; + trans.Write(bout, 0, 1); + } + + private byte[] i16out = new byte[2]; + public override void WriteI16(short s) + { + i16out[0] = (byte)(0xff & (s >> 8)); + i16out[1] = (byte)(0xff & s); + trans.Write(i16out, 0, 2); + } + + private byte[] i32out = new byte[4]; + public override void WriteI32(int i32) + { + i32out[0] = (byte)(0xff & (i32 >> 24)); + i32out[1] = (byte)(0xff & (i32 >> 16)); + i32out[2] = (byte)(0xff & (i32 >> 8)); + i32out[3] = (byte)(0xff & i32); + trans.Write(i32out, 0, 4); + } + + private byte[] i64out = new byte[8]; + public override void WriteI64(long i64) + { + i64out[0] = (byte)(0xff & (i64 >> 56)); + i64out[1] = (byte)(0xff & (i64 >> 48)); + i64out[2] = (byte)(0xff & (i64 >> 40)); + i64out[3] = (byte)(0xff & (i64 >> 32)); + i64out[4] = (byte)(0xff & (i64 >> 24)); + i64out[5] = (byte)(0xff & (i64 >> 16)); + i64out[6] = (byte)(0xff & (i64 >> 8)); + i64out[7] = (byte)(0xff & i64); + trans.Write(i64out, 0, 8); + } + + public override void WriteDouble(double d) + { #if !SILVERLIGHT - WriteI64(BitConverter.DoubleToInt64Bits(d)); + WriteI64(BitConverter.DoubleToInt64Bits(d)); #else var bytes = BitConverter.GetBytes(d); WriteI64(BitConverter.ToInt64(bytes, 0)); #endif - } - - public override void WriteBinary(byte[] b) - { - WriteI32(b.Length); - trans.Write(b, 0, b.Length); - } - - #endregion - - #region ReadMethods - - public override TMessage ReadMessageBegin() - { - TMessage message = new TMessage(); - int size = ReadI32(); - if (size < 0) - { - uint version = (uint)size & VERSION_MASK; - if (version != VERSION_1) - { - throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version); - } - message.Type = (TMessageType)(size & 0x000000ff); - message.Name = ReadString(); - message.SeqID = ReadI32(); - } - else - { - if (strictRead_) - { - throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?"); - } - message.Name = ReadStringBody(size); - message.Type = (TMessageType)ReadByte(); - message.SeqID = ReadI32(); - } - return message; - } - - public override void ReadMessageEnd() - { - } - - public override TStruct ReadStructBegin() - { - return new TStruct(); - } - - public override void ReadStructEnd() - { - } - - public override TField ReadFieldBegin() - { - TField field = new TField(); - field.Type = (TType)ReadByte(); - - if (field.Type != TType.Stop) - { - field.ID = ReadI16(); - } - - return field; - } - - public override void ReadFieldEnd() - { - } - - public override TMap ReadMapBegin() - { - TMap map = new TMap(); - map.KeyType = (TType)ReadByte(); - map.ValueType = (TType)ReadByte(); - map.Count = ReadI32(); - - return map; - } - - public override void ReadMapEnd() - { - } - - public override TList ReadListBegin() - { - TList list = new TList(); - list.ElementType = (TType)ReadByte(); - list.Count = ReadI32(); - - return list; - } - - public override void ReadListEnd() - { - } - - public override TSet ReadSetBegin() - { - TSet set = new TSet(); - set.ElementType = (TType)ReadByte(); - set.Count = ReadI32(); - - return set; - } - - public override void ReadSetEnd() - { - } - - public override bool ReadBool() - { - return ReadByte() == 1; - } - - private byte[] bin = new byte[1]; - public override sbyte ReadByte() - { - ReadAll(bin, 0, 1); - return (sbyte)bin[0]; - } - - private byte[] i16in = new byte[2]; - public override short ReadI16() - { - ReadAll(i16in, 0, 2); - return (short)(((i16in[0] & 0xff) << 8) | ((i16in[1] & 0xff))); - } - - private byte[] i32in = new byte[4]; - public override int ReadI32() - { - ReadAll(i32in, 0, 4); - return (int)(((i32in[0] & 0xff) << 24) | ((i32in[1] & 0xff) << 16) | ((i32in[2] & 0xff) << 8) | ((i32in[3] & 0xff))); - } + } + + public override void WriteBinary(byte[] b) + { + WriteI32(b.Length); + trans.Write(b, 0, b.Length); + } + + #endregion + + #region ReadMethods + + public override TMessage ReadMessageBegin() + { + TMessage message = new TMessage(); + int size = ReadI32(); + if (size < 0) + { + uint version = (uint)size & VERSION_MASK; + if (version != VERSION_1) + { + throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version); + } + message.Type = (TMessageType)(size & 0x000000ff); + message.Name = ReadString(); + message.SeqID = ReadI32(); + } + else + { + if (strictRead_) + { + throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?"); + } + message.Name = ReadStringBody(size); + message.Type = (TMessageType)ReadByte(); + message.SeqID = ReadI32(); + } + return message; + } + + public override void ReadMessageEnd() + { + } + + public override TStruct ReadStructBegin() + { + return new TStruct(); + } + + public override void ReadStructEnd() + { + } + + public override TField ReadFieldBegin() + { + TField field = new TField(); + field.Type = (TType)ReadByte(); + + if (field.Type != TType.Stop) + { + field.ID = ReadI16(); + } + + return field; + } + + public override void ReadFieldEnd() + { + } + + public override TMap ReadMapBegin() + { + TMap map = new TMap(); + map.KeyType = (TType)ReadByte(); + map.ValueType = (TType)ReadByte(); + map.Count = ReadI32(); + + return map; + } + + public override void ReadMapEnd() + { + } + + public override TList ReadListBegin() + { + TList list = new TList(); + list.ElementType = (TType)ReadByte(); + list.Count = ReadI32(); + + return list; + } + + public override void ReadListEnd() + { + } + + public override TSet ReadSetBegin() + { + TSet set = new TSet(); + set.ElementType = (TType)ReadByte(); + set.Count = ReadI32(); + + return set; + } + + public override void ReadSetEnd() + { + } + + public override bool ReadBool() + { + return ReadByte() == 1; + } + + private byte[] bin = new byte[1]; + public override sbyte ReadByte() + { + ReadAll(bin, 0, 1); + return (sbyte)bin[0]; + } + + private byte[] i16in = new byte[2]; + public override short ReadI16() + { + ReadAll(i16in, 0, 2); + return (short)(((i16in[0] & 0xff) << 8) | ((i16in[1] & 0xff))); + } + + private byte[] i32in = new byte[4]; + public override int ReadI32() + { + ReadAll(i32in, 0, 4); + return (int)(((i32in[0] & 0xff) << 24) | ((i32in[1] & 0xff) << 16) | ((i32in[2] & 0xff) << 8) | ((i32in[3] & 0xff))); + } #pragma warning disable 675 private byte[] i64in = new byte[8]; - public override long ReadI64() - { - ReadAll(i64in, 0, 8); + public override long ReadI64() + { + ReadAll(i64in, 0, 8); unchecked { return (long)( ((long)(i64in[0] & 0xff) << 56) | @@ -361,35 +361,35 @@ namespace Thrift.Protocol #pragma warning restore 675 public override double ReadDouble() - { + { #if !SILVERLIGHT - return BitConverter.Int64BitsToDouble(ReadI64()); + return BitConverter.Int64BitsToDouble(ReadI64()); #else var value = ReadI64(); var bytes = BitConverter.GetBytes(value); return BitConverter.ToDouble(bytes, 0); #endif - } - - public override byte[] ReadBinary() - { - int size = ReadI32(); - byte[] buf = new byte[size]; - trans.ReadAll(buf, 0, size); - return buf; - } - private string ReadStringBody(int size) - { - byte[] buf = new byte[size]; - trans.ReadAll(buf, 0, size); - return Encoding.UTF8.GetString(buf, 0, buf.Length); - } - - private int ReadAll(byte[] buf, int off, int len) - { - return trans.ReadAll(buf, off, len); - } - - #endregion - } + } + + public override byte[] ReadBinary() + { + int size = ReadI32(); + byte[] buf = new byte[size]; + trans.ReadAll(buf, 0, size); + return buf; + } + private string ReadStringBody(int size) + { + byte[] buf = new byte[size]; + trans.ReadAll(buf, 0, size); + return Encoding.UTF8.GetString(buf, 0, buf.Length); + } + + private int ReadAll(byte[] buf, int off, int len) + { + return trans.ReadAll(buf, off, len); + } + + #endregion + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TCompactProtocol.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TCompactProtocol.cs b/lib/csharp/src/Protocol/TCompactProtocol.cs index c992e9b..2b4f6f1 100644 --- a/lib/csharp/src/Protocol/TCompactProtocol.cs +++ b/lib/csharp/src/Protocol/TCompactProtocol.cs @@ -64,7 +64,7 @@ namespace Thrift.Protocol public const byte STRUCT = 0x0C; } - /** + /** * Used to keep track of the last field for the current and previous structs, * so we can do the delta stuff. */ @@ -73,13 +73,13 @@ namespace Thrift.Protocol private short lastFieldId_ = 0; /** - * If we encounter a boolean field begin, save the TField here so it can + * If we encounter a boolean field begin, save the TField here so it can * have the value incorporated. */ private Nullable<TField> booleanField_; /** - * If we Read a field header, and it's a boolean field, save the boolean + * If we Read a field header, and it's a boolean field, save the boolean * value here so that ReadBool can use it. */ private Nullable<Boolean> boolValue_; @@ -88,8 +88,8 @@ namespace Thrift.Protocol #region CompactProtocol Factory /** - * Factory - */ + * Factory + */ public class Factory : TProtocolFactory { public Factory() { } @@ -128,8 +128,8 @@ namespace Thrift.Protocol #region Write Methods - /** - * Writes a byte without any possibility of all that field header nonsense. + /** + * Writes a byte without any possibility of all that field header nonsense. * Used internally by other writing methods that know they need to Write a byte. */ private byte[] byteDirectBuffer = new byte[1]; @@ -139,7 +139,7 @@ namespace Thrift.Protocol trans.Write(byteDirectBuffer); } - /** + /** * Writes a byte without any possibility of all that field header nonsense. */ private void WriteByteDirect(int n) @@ -187,7 +187,7 @@ namespace Thrift.Protocol } /** - * Write a struct begin. This doesn't actually put anything on the wire. We + * Write a struct begin. This doesn't actually put anything on the wire. We * use it as an opportunity to put special placeholder markers on the field * stack so we can get the field id deltas correct. */ @@ -227,8 +227,8 @@ namespace Thrift.Protocol } /** - * The workhorse of WriteFieldBegin. It has the option of doing a - * 'type override' of the type header. This is used specifically in the + * The workhorse of WriteFieldBegin. It has the option of doing a + * 'type override' of the type header. This is used specifically in the * boolean field case. */ private void WriteFieldBeginInternal(TField field, byte typeOverride) @@ -264,7 +264,7 @@ namespace Thrift.Protocol } /** - * Write a map header. If the map is empty, omit the key and value type + * Write a map header. If the map is empty, omit the key and value type * headers, as we don't need any additional information to skip it. */ public override void WriteMapBegin(TMap map) @@ -280,7 +280,7 @@ namespace Thrift.Protocol } } - /** + /** * Write a list header. */ public override void WriteListBegin(TList list) @@ -297,9 +297,9 @@ namespace Thrift.Protocol } /** - * Write a boolean value. Potentially, this could be a boolean field, in + * Write a boolean value. Potentially, this could be a boolean field, in * which case the field header info isn't written yet. If so, decide what the - * right type header is for the value and then Write the field header. + * right type header is for the value and then Write the field header. * Otherwise, Write a single byte. */ public override void WriteBool(Boolean b) @@ -317,7 +317,7 @@ namespace Thrift.Protocol } } - /** + /** * Write a byte. Nothing to see here! */ public override void WriteByte(sbyte b) @@ -369,7 +369,7 @@ namespace Thrift.Protocol } /** - * Write a byte array, using a varint for the size. + * Write a byte array, using a varint for the size. */ public override void WriteBinary(byte[] bin) { @@ -383,9 +383,9 @@ namespace Thrift.Protocol } // - // These methods are called by structs, but don't actually have any wire + // These methods are called by structs, but don't actually have any wire // output or purpose. - // + // public override void WriteMessageEnd() { } public override void WriteMapEnd() { } @@ -398,7 +398,7 @@ namespace Thrift.Protocol // /** - * Abstract method for writing the start of lists and sets. List and sets on + * Abstract method for writing the start of lists and sets. List and sets on * the wire differ only by the type indicator. */ protected void WriteCollectionBegin(TType elemType, int size) @@ -438,7 +438,7 @@ namespace Thrift.Protocol } /** - * Convert l into a zigzag long. This allows negative numbers to be + * Convert l into a zigzag long. This allows negative numbers to be * represented compactly as a varint. */ private ulong longToZigzag(long n) @@ -447,7 +447,7 @@ namespace Thrift.Protocol } /** - * Convert n into a zigzag int. This allows negative numbers to be + * Convert n into a zigzag int. This allows negative numbers to be * represented compactly as a varint. */ private uint intToZigZag(int n) @@ -456,7 +456,7 @@ namespace Thrift.Protocol } /** - * Convert a long into little-endian bytes in buf starting at off and going + * Convert a long into little-endian bytes in buf starting at off and going * until off+7. */ private void fixedLongToBytes(long n, byte[] buf, int off) @@ -476,7 +476,7 @@ namespace Thrift.Protocol #region ReadMethods /** - * Read a message header. + * Read a message header. */ public override TMessage ReadMessageBegin() { @@ -509,7 +509,7 @@ namespace Thrift.Protocol } /** - * Doesn't actually consume any wire data, just removes the last field for + * Doesn't actually consume any wire data, just removes the last field for * this struct from the field stack. */ public override void ReadStructEnd() @@ -519,7 +519,7 @@ namespace Thrift.Protocol } /** - * Read a field header off the wire. + * Read a field header off the wire. */ public override TField ReadFieldBegin() { @@ -560,7 +560,7 @@ namespace Thrift.Protocol return field; } - /** + /** * Read a map header off the wire. If the size is zero, skip Reading the key * and value type. This means that 0-length maps will yield TMaps without the * "correct" types. @@ -573,7 +573,7 @@ namespace Thrift.Protocol } /** - * Read a list header off the wire. If the list size is 0-14, the size will + * Read a list header off the wire. If the list size is 0-14, the size will * be packed into the element type header. If it's a longer list, the 4 MSB * of the element type header will be 0xF, and a varint will follow with the * true size. @@ -591,7 +591,7 @@ namespace Thrift.Protocol } /** - * Read a set header off the wire. If the set size is 0-14, the size will + * Read a set header off the wire. If the set size is 0-14, the size will * be packed into the element type header. If it's a longer set, the 4 MSB * of the element type header will be 0xF, and a varint will follow with the * true size. @@ -677,7 +677,7 @@ namespace Thrift.Protocol } /** - * Read a byte[] from the wire. + * Read a byte[] from the wire. */ public override byte[] ReadBinary() { @@ -690,7 +690,7 @@ namespace Thrift.Protocol } /** - * Read a byte[] of a known length from the wire. + * Read a byte[] of a known length from the wire. */ private byte[] ReadBinary(int length) { @@ -702,7 +702,7 @@ namespace Thrift.Protocol } // - // These methods are here for the struct to call, but don't have any wire + // These methods are here for the struct to call, but don't have any wire // encoding. // public override void ReadMessageEnd() { } @@ -734,7 +734,7 @@ namespace Thrift.Protocol } /** - * Read an i64 from the wire as a proper varint. The MSB of each byte is set + * Read an i64 from the wire as a proper varint. The MSB of each byte is set * if there is another byte to follow. This can Read up to 10 bytes. */ private ulong ReadVarint64() @@ -748,7 +748,7 @@ namespace Thrift.Protocol if ((b & 0x80) != 0x80) break; shift += 7; } - + return result; } @@ -766,7 +766,7 @@ namespace Thrift.Protocol return (int)(n >> 1) ^ (-(int)(n & 1)); } - /** + /** * Convert from zigzag long to long. */ private long zigzagToLong(ulong n) @@ -775,7 +775,7 @@ namespace Thrift.Protocol } /** - * Note that it's important that the mask bytes are long literals, + * Note that it's important that the mask bytes are long literals, * otherwise they'll default to ints, and when you shift an int left 56 bits, * you just get a messed up int. */ @@ -803,7 +803,7 @@ namespace Thrift.Protocol } /** - * Given a TCompactProtocol.Types constant, convert it to its corresponding + * Given a TCompactProtocol.Types constant, convert it to its corresponding * TType value. */ private TType getTType(byte type) http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Protocol/TField.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Protocol/TField.cs b/lib/csharp/src/Protocol/TField.cs index fa10584..8179557 100644 --- a/lib/csharp/src/Protocol/TField.cs +++ b/lib/csharp/src/Protocol/TField.cs @@ -27,36 +27,36 @@ using System.Text; namespace Thrift.Protocol { - public struct TField - { - private string name; - private TType type; - private short id; + public struct TField + { + private string name; + private TType type; + private short id; - public TField(string name, TType type, short id) - :this() - { - this.name = name; - this.type = type; - this.id = id; - } + public TField(string name, TType type, short id) + :this() + { + this.name = name; + this.type = type; + this.id = id; + } - public string Name - { - get { return name; } - set { name = value; } - } + public string Name + { + get { return name; } + set { name = value; } + } - public TType Type - { - get { return type; } - set { type = value; } - } + public TType Type + { + get { return type; } + set { type = value; } + } - public short ID - { - get { return id; } - set { id = value; } - } - } + public short ID + { + get { return id; } + set { id = value; } + } + } }
