THRIFT-2768: Whitespace Fixup
Client: C#, Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Collections.pas b/lib/delphi/src/Thrift.Collections.pas
index 3a0274c..b2206cb 100644
--- a/lib/delphi/src/Thrift.Collections.pas
+++ b/lib/delphi/src/Thrift.Collections.pas
@@ -1,619 +1,619 @@
-(*
- * 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.
- *)
-
-unit Thrift.Collections;
-
-interface
-
-uses
- Generics.Collections, Generics.Defaults, Thrift.Utils;
-
-type
-
-{$IF CompilerVersion < 21.0}
- TArray<T> = array of T;
-{$IFEND}
-
- IThriftContainer = interface
- ['{93DEF5A0-D162-461A-AB22-5B4EE0734050}']
- function ToString: string;
- end;
-
- IThriftDictionary<TKey,TValue> = interface(IThriftContainer)
- ['{25EDD506-F9D1-4008-A40F-5940364B7E46}']
- function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
-
- function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
- function GetValues: TDictionary<TKey,TValue>.TValueCollection;
- function GetItem(const Key: TKey): TValue;
- procedure SetItem(const Key: TKey; const Value: TValue);
- function GetCount: Integer;
-
- procedure Add(const Key: TKey; const Value: TValue);
- procedure Remove(const Key: TKey);
-{$IF CompilerVersion >= 21.0}
- function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
-{$IFEND}
- procedure Clear;
- procedure TrimExcess;
- function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
- procedure AddOrSetValue(const Key: TKey; const Value: TValue);
- function ContainsKey(const Key: TKey): Boolean;
- function ContainsValue(const Value: TValue): Boolean;
- function ToArray: TArray<TPair<TKey,TValue>>;
-
- property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
- property Count: Integer read GetCount;
- property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
- property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
- end;
-
- TThriftDictionaryImpl<TKey,TValue> = class( TInterfacedObject, IThriftDictionary<TKey,TValue>)
- private
- FDictionaly : TDictionary<TKey,TValue>;
- protected
- function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
-
- function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
- function GetValues: TDictionary<TKey,TValue>.TValueCollection;
- function GetItem(const Key: TKey): TValue;
- procedure SetItem(const Key: TKey; const Value: TValue);
- function GetCount: Integer;
-
- procedure Add(const Key: TKey; const Value: TValue);
- procedure Remove(const Key: TKey);
-{$IF CompilerVersion >= 21.0}
- function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
-{$IFEND}
- procedure Clear;
- procedure TrimExcess;
- function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
- procedure AddOrSetValue(const Key: TKey; const Value: TValue);
- function ContainsKey(const Key: TKey): Boolean;
- function ContainsValue(const Value: TValue): Boolean;
- function ToArray: TArray<TPair<TKey,TValue>>;
- property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
- property Count: Integer read GetCount;
- property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
- property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
- public
- constructor Create(ACapacity: Integer = 0);
- destructor Destroy; override;
- end;
-
- IThriftList<T> = interface(IThriftContainer)
- ['{29BEEE31-9CB4-401B-AA04-5148A75F473B}']
- function GetEnumerator: TEnumerator<T>;
- function GetCapacity: Integer;
- procedure SetCapacity(Value: Integer);
- function GetCount: Integer;
- procedure SetCount(Value: Integer);
- function GetItem(Index: Integer): T;
- procedure SetItem(Index: Integer; const Value: T);
- function Add(const Value: T): Integer;
- procedure AddRange(const Values: array of T); overload;
- procedure AddRange(const Collection: IEnumerable<T>); overload;
- procedure AddRange(Collection: TEnumerable<T>); overload;
- procedure Insert(Index: Integer; const Value: T);
- procedure InsertRange(Index: Integer; const Values: array of T); overload;
- procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
- procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
- function Remove(const Value: T): Integer;
- procedure Delete(Index: Integer);
- procedure DeleteRange(AIndex, ACount: Integer);
- function Extract(const Value: T): T;
-{$IF CompilerVersion >= 21.0}
- procedure Exchange(Index1, Index2: Integer);
- procedure Move(CurIndex, NewIndex: Integer);
- function First: T;
- function Last: T;
-{$IFEND}
- procedure Clear;
- function Contains(const Value: T): Boolean;
- function IndexOf(const Value: T): Integer;
- function LastIndexOf(const Value: T): Integer;
- procedure Reverse;
- procedure Sort; overload;
- procedure Sort(const AComparer: IComparer<T>); overload;
- function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
- function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
- procedure TrimExcess;
- function ToArray: TArray<T>;
- property Capacity: Integer read GetCapacity write SetCapacity;
- property Count: Integer read GetCount write SetCount;
- property Items[Index: Integer]: T read GetItem write SetItem; default;
- end;
-
- TThriftListImpl<T> = class( TInterfacedObject, IThriftList<T>)
- private
- FList : TList<T>;
- protected
- function GetEnumerator: TEnumerator<T>;
- function GetCapacity: Integer;
- procedure SetCapacity(Value: Integer);
- function GetCount: Integer;
- procedure SetCount(Value: Integer);
- function GetItem(Index: Integer): T;
- procedure SetItem(Index: Integer; const Value: T);
- function Add(const Value: T): Integer;
- procedure AddRange(const Values: array of T); overload;
- procedure AddRange(const Collection: IEnumerable<T>); overload;
- procedure AddRange(Collection: TEnumerable<T>); overload;
- procedure Insert(Index: Integer; const Value: T);
- procedure InsertRange(Index: Integer; const Values: array of T); overload;
- procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
- procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
- function Remove(const Value: T): Integer;
- procedure Delete(Index: Integer);
- procedure DeleteRange(AIndex, ACount: Integer);
- function Extract(const Value: T): T;
-{$IF CompilerVersion >= 21.0}
- procedure Exchange(Index1, Index2: Integer);
- procedure Move(CurIndex, NewIndex: Integer);
- function First: T;
- function Last: T;
-{$IFEND}
- procedure Clear;
- function Contains(const Value: T): Boolean;
- function IndexOf(const Value: T): Integer;
- function LastIndexOf(const Value: T): Integer;
- procedure Reverse;
- procedure Sort; overload;
- procedure Sort(const AComparer: IComparer<T>); overload;
- function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
- function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
- procedure TrimExcess;
- function ToArray: TArray<T>;
- property Capacity: Integer read GetCapacity write SetCapacity;
- property Count: Integer read GetCount write SetCount;
- property Items[Index: Integer]: T read GetItem write SetItem; default;
- public
- constructor Create;
- destructor Destroy; override;
- end;
-
- IHashSet<TValue> = interface(IThriftContainer)
- ['{0923A3B5-D4D4-48A8-91AD-40238E2EAD66}']
- function GetEnumerator: TEnumerator<TValue>;
- function GetIsReadOnly: Boolean;
- function GetCount: Integer;
- property Count: Integer read GetCount;
- property IsReadOnly: Boolean read GetIsReadOnly;
- procedure Add( const item: TValue);
- procedure Clear;
- function Contains( const item: TValue): Boolean;
- procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
- function Remove( const item: TValue ): Boolean;
- end;
-
- THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>)
- private
- FDictionary : IThriftDictionary<TValue,Integer>;
- FIsReadOnly: Boolean;
- protected
- function GetEnumerator: TEnumerator<TValue>;
- function GetIsReadOnly: Boolean;
- function GetCount: Integer;
- property Count: Integer read GetCount;
- property IsReadOnly: Boolean read FIsReadOnly;
- procedure Add( const item: TValue);
- procedure Clear;
- function Contains( const item: TValue): Boolean;
- procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
- function Remove( const item: TValue ): Boolean;
- public
- constructor Create;
- end;
-
-implementation
-
-{ THashSetImpl<TValue> }
-
-procedure THashSetImpl<TValue>.Add( const item: TValue);
-begin
- if not FDictionary.ContainsKey(item) then
- begin
- FDictionary.Add( item, 0);
- end;
-end;
-
-procedure THashSetImpl<TValue>.Clear;
-begin
- FDictionary.Clear;
-end;
-
-function THashSetImpl<TValue>.Contains( const item: TValue): Boolean;
-begin
- Result := FDictionary.ContainsKey(item);
-end;
-
-procedure THashSetImpl<TValue>.CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
-var
- i : Integer;
- Enumlator : TEnumerator<TValue>;
-begin
- Enumlator := GetEnumerator;
- while Enumlator.MoveNext do
- begin
- A[arrayIndex] := Enumlator.Current;
- Inc(arrayIndex);
- end;
-end;
-
-constructor THashSetImpl<TValue>.Create;
-begin
- inherited;
- FDictionary := TThriftDictionaryImpl<TValue,Integer>.Create;
-end;
-
-function THashSetImpl<TValue>.GetCount: Integer;
-begin
- Result := FDictionary.Count;
-end;
-
-function THashSetImpl<TValue>.GetEnumerator: TEnumerator<TValue>;
-begin
- Result := FDictionary.Keys.GetEnumerator;
-end;
-
-function THashSetImpl<TValue>.GetIsReadOnly: Boolean;
-begin
- Result := FIsReadOnly;
-end;
-
-function THashSetImpl<TValue>.Remove( const item: TValue): Boolean;
-begin
- Result := False;
- if FDictionary.ContainsKey( item ) then
- begin
- FDictionary.Remove( item );
- Result := not FDictionary.ContainsKey( item );
- end;
-end;
-
-{ TThriftDictionaryImpl<TKey, TValue> }
-
-procedure TThriftDictionaryImpl<TKey, TValue>.Add(const Key: TKey;
- const Value: TValue);
-begin
- FDictionaly.Add( Key, Value);
-end;
-
-procedure TThriftDictionaryImpl<TKey, TValue>.AddOrSetValue(const Key: TKey;
- const Value: TValue);
-begin
- FDictionaly.AddOrSetValue( Key, Value);
-end;
-
-procedure TThriftDictionaryImpl<TKey, TValue>.Clear;
-begin
- FDictionaly.Clear;
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.ContainsKey(
- const Key: TKey): Boolean;
-begin
- Result := FDictionaly.ContainsKey( Key );
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.ContainsValue(
- const Value: TValue): Boolean;
-begin
- Result := FDictionaly.ContainsValue( Value );
-end;
-
-constructor TThriftDictionaryImpl<TKey, TValue>.Create(ACapacity: Integer);
-begin
- inherited Create;
- FDictionaly := TDictionary<TKey,TValue>.Create( ACapacity );
-end;
-
-destructor TThriftDictionaryImpl<TKey, TValue>.Destroy;
-begin
- FDictionaly.Free;
- inherited;
-end;
-
-{$IF CompilerVersion >= 21.0}
-function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
-begin
- Result := FDictionaly.ExtractPair( Key);
-end;
-{$IFEND}
-
-function TThriftDictionaryImpl<TKey, TValue>.GetCount: Integer;
-begin
- Result := FDictionaly.Count;
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.GetEnumerator: TEnumerator<TPair<TKey, TValue>>;
-begin
- Result := FDictionaly.GetEnumerator;
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.GetItem(const Key: TKey): TValue;
-begin
- Result := FDictionaly.Items[Key];
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.GetKeys: TDictionary<TKey, TValue>.TKeyCollection;
-begin
- Result := FDictionaly.Keys;
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.GetValues: TDictionary<TKey, TValue>.TValueCollection;
-begin
- Result := FDictionaly.Values;
-end;
-
-procedure TThriftDictionaryImpl<TKey, TValue>.Remove(const Key: TKey);
-begin
- FDictionaly.Remove( Key );
-end;
-
-procedure TThriftDictionaryImpl<TKey, TValue>.SetItem(const Key: TKey;
- const Value: TValue);
-begin
- FDictionaly.AddOrSetValue( Key, Value);
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.ToArray: TArray<TPair<TKey, TValue>>;
-{$IF CompilerVersion < 22.0}
-var
- x : TPair<TKey, TValue>;
- i : Integer;
-{$IFEND}
-begin
-{$IF CompilerVersion < 22.0}
- SetLength(Result, Count);
- i := 0;
- for x in FDictionaly do
- begin
- Result[i] := x;
- Inc( i );
- end;
-{$ELSE}
- Result := FDictionaly.ToArray;
-{$IFEND}
-end;
-
-procedure TThriftDictionaryImpl<TKey, TValue>.TrimExcess;
-begin
- FDictionaly.TrimExcess;
-end;
-
-function TThriftDictionaryImpl<TKey, TValue>.TryGetValue(const Key: TKey;
- out Value: TValue): Boolean;
-begin
- Result := FDictionaly.TryGetValue( Key, Value);
-end;
-
-{ TThriftListImpl<T> }
-
-function TThriftListImpl<T>.Add(const Value: T): Integer;
-begin
- Result := FList.Add( Value );
-end;
-
-procedure TThriftListImpl<T>.AddRange(Collection: TEnumerable<T>);
-begin
- FList.AddRange( Collection );
-end;
-
-procedure TThriftListImpl<T>.AddRange(const Collection: IEnumerable<T>);
-begin
- FList.AddRange( Collection );
-end;
-
-procedure TThriftListImpl<T>.AddRange(const Values: array of T);
-begin
- FList.AddRange( Values );
-end;
-
-function TThriftListImpl<T>.BinarySearch(const Item: T;
- out Index: Integer): Boolean;
-begin
- Result := FList.BinarySearch( Item, Index);
-end;
-
-function TThriftListImpl<T>.BinarySearch(const Item: T; out Index: Integer;
- const AComparer: IComparer<T>): Boolean;
-begin
- Result := FList.BinarySearch( Item, Index, AComparer);
-end;
-
-procedure TThriftListImpl<T>.Clear;
-begin
- FList.Clear;
-end;
-
-function TThriftListImpl<T>.Contains(const Value: T): Boolean;
-begin
- Result := FList.Contains( Value );
-end;
-
-constructor TThriftListImpl<T>.Create;
-begin
- inherited;
- FList := TList<T>.Create;
-end;
-
-procedure TThriftListImpl<T>.Delete(Index: Integer);
-begin
- FList.Delete( Index )
-end;
-
-procedure TThriftListImpl<T>.DeleteRange(AIndex, ACount: Integer);
-begin
- FList.DeleteRange( AIndex, ACount)
-end;
-
-destructor TThriftListImpl<T>.Destroy;
-begin
- FList.Free;
- inherited;
-end;
-
-{$IF CompilerVersion >= 21.0}
-procedure TThriftListImpl<T>.Exchange(Index1, Index2: Integer);
-begin
- FList.Exchange( Index1, Index2 )
-end;
-{$IFEND}
-
-function TThriftListImpl<T>.Extract(const Value: T): T;
-begin
- Result := FList.Extract( Value )
-end;
-
-{$IF CompilerVersion >= 21.0}
-function TThriftListImpl<T>.First: T;
-begin
- Result := FList.First;
-end;
-{$IFEND}
-
-function TThriftListImpl<T>.GetCapacity: Integer;
-begin
- Result := FList.Capacity;
-end;
-
-function TThriftListImpl<T>.GetCount: Integer;
-begin
- Result := FList.Count;
-end;
-
-function TThriftListImpl<T>.GetEnumerator: TEnumerator<T>;
-begin
- Result := FList.GetEnumerator;
-end;
-
-function TThriftListImpl<T>.GetItem(Index: Integer): T;
-begin
- Result := FList[Index];
-end;
-
-function TThriftListImpl<T>.IndexOf(const Value: T): Integer;
-begin
- Result := FList.IndexOf( Value );
-end;
-
-procedure TThriftListImpl<T>.Insert(Index: Integer; const Value: T);
-begin
- FList.Insert( Index, Value);
-end;
-
-procedure TThriftListImpl<T>.InsertRange(Index: Integer;
- const Collection: TEnumerable<T>);
-begin
- FList.InsertRange( Index, Collection );
-end;
-
-procedure TThriftListImpl<T>.InsertRange(Index: Integer;
- const Values: array of T);
-begin
- FList.InsertRange( Index, Values);
-end;
-
-procedure TThriftListImpl<T>.InsertRange(Index: Integer;
- const Collection: IEnumerable<T>);
-begin
- FList.InsertRange( Index, Collection );
-end;
-
-{$IF CompilerVersion >= 21.0}
-function TThriftListImpl<T>.Last: T;
-begin
- Result := FList.Last;
-end;
-{$IFEND}
-
-function TThriftListImpl<T>.LastIndexOf(const Value: T): Integer;
-begin
- Result := FList.LastIndexOf( Value );
-end;
-
-{$IF CompilerVersion >= 21.0}
-procedure TThriftListImpl<T>.Move(CurIndex, NewIndex: Integer);
-begin
- FList.Move( CurIndex, NewIndex);
-end;
-{$IFEND}
-
-function TThriftListImpl<T>.Remove(const Value: T): Integer;
-begin
- Result := FList.Remove( Value );
-end;
-
-procedure TThriftListImpl<T>.Reverse;
-begin
- FList.Reverse;
-end;
-
-procedure TThriftListImpl<T>.SetCapacity(Value: Integer);
-begin
- FList.Capacity := Value;
-end;
-
-procedure TThriftListImpl<T>.SetCount(Value: Integer);
-begin
- FList.Count := Value;
-end;
-
-procedure TThriftListImpl<T>.SetItem(Index: Integer; const Value: T);
-begin
- FList[Index] := Value;
-end;
-
-procedure TThriftListImpl<T>.Sort;
-begin
- FList.Sort;
-end;
-
-procedure TThriftListImpl<T>.Sort(const AComparer: IComparer<T>);
-begin
- FList.Sort;
-end;
-
-function TThriftListImpl<T>.ToArray: TArray<T>;
-{$IF CompilerVersion < 22.0}
-var
- x : T;
- i : Integer;
-{$IFEND}
-begin
-{$IF CompilerVersion < 22.0}
- SetLength(Result, Count);
- i := 0;
- for x in FList do
- begin
- Result[i] := x;
- Inc( i );
- end;
-{$ELSE}
- Result := FList.ToArray;
-{$IFEND}
-end;
-
-procedure TThriftListImpl<T>.TrimExcess;
-begin
- FList.TrimExcess;
-end;
-
-end.
+(*
+ * 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.
+ *)
+
+unit Thrift.Collections;
+
+interface
+
+uses
+ Generics.Collections, Generics.Defaults, Thrift.Utils;
+
+type
+
+{$IF CompilerVersion < 21.0}
+ TArray<T> = array of T;
+{$IFEND}
+
+ IThriftContainer = interface
+ ['{93DEF5A0-D162-461A-AB22-5B4EE0734050}']
+ function ToString: string;
+ end;
+
+ IThriftDictionary<TKey,TValue> = interface(IThriftContainer)
+ ['{25EDD506-F9D1-4008-A40F-5940364B7E46}']
+ function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
+
+ function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
+ function GetValues: TDictionary<TKey,TValue>.TValueCollection;
+ function GetItem(const Key: TKey): TValue;
+ procedure SetItem(const Key: TKey; const Value: TValue);
+ function GetCount: Integer;
+
+ procedure Add(const Key: TKey; const Value: TValue);
+ procedure Remove(const Key: TKey);
+{$IF CompilerVersion >= 21.0}
+ function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
+{$IFEND}
+ procedure Clear;
+ procedure TrimExcess;
+ function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
+ procedure AddOrSetValue(const Key: TKey; const Value: TValue);
+ function ContainsKey(const Key: TKey): Boolean;
+ function ContainsValue(const Value: TValue): Boolean;
+ function ToArray: TArray<TPair<TKey,TValue>>;
+
+ property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
+ property Count: Integer read GetCount;
+ property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
+ property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
+ end;
+
+ TThriftDictionaryImpl<TKey,TValue> = class( TInterfacedObject, IThriftDictionary<TKey,TValue>)
+ private
+ FDictionaly : TDictionary<TKey,TValue>;
+ protected
+ function GetEnumerator: TEnumerator<TPair<TKey,TValue>>;
+
+ function GetKeys: TDictionary<TKey,TValue>.TKeyCollection;
+ function GetValues: TDictionary<TKey,TValue>.TValueCollection;
+ function GetItem(const Key: TKey): TValue;
+ procedure SetItem(const Key: TKey; const Value: TValue);
+ function GetCount: Integer;
+
+ procedure Add(const Key: TKey; const Value: TValue);
+ procedure Remove(const Key: TKey);
+{$IF CompilerVersion >= 21.0}
+ function ExtractPair(const Key: TKey): TPair<TKey,TValue>;
+{$IFEND}
+ procedure Clear;
+ procedure TrimExcess;
+ function TryGetValue(const Key: TKey; out Value: TValue): Boolean;
+ procedure AddOrSetValue(const Key: TKey; const Value: TValue);
+ function ContainsKey(const Key: TKey): Boolean;
+ function ContainsValue(const Value: TValue): Boolean;
+ function ToArray: TArray<TPair<TKey,TValue>>;
+ property Items[const Key: TKey]: TValue read GetItem write SetItem; default;
+ property Count: Integer read GetCount;
+ property Keys: TDictionary<TKey,TValue>.TKeyCollection read GetKeys;
+ property Values: TDictionary<TKey,TValue>.TValueCollection read GetValues;
+ public
+ constructor Create(ACapacity: Integer = 0);
+ destructor Destroy; override;
+ end;
+
+ IThriftList<T> = interface(IThriftContainer)
+ ['{29BEEE31-9CB4-401B-AA04-5148A75F473B}']
+ function GetEnumerator: TEnumerator<T>;
+ function GetCapacity: Integer;
+ procedure SetCapacity(Value: Integer);
+ function GetCount: Integer;
+ procedure SetCount(Value: Integer);
+ function GetItem(Index: Integer): T;
+ procedure SetItem(Index: Integer; const Value: T);
+ function Add(const Value: T): Integer;
+ procedure AddRange(const Values: array of T); overload;
+ procedure AddRange(const Collection: IEnumerable<T>); overload;
+ procedure AddRange(Collection: TEnumerable<T>); overload;
+ procedure Insert(Index: Integer; const Value: T);
+ procedure InsertRange(Index: Integer; const Values: array of T); overload;
+ procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
+ procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
+ function Remove(const Value: T): Integer;
+ procedure Delete(Index: Integer);
+ procedure DeleteRange(AIndex, ACount: Integer);
+ function Extract(const Value: T): T;
+{$IF CompilerVersion >= 21.0}
+ procedure Exchange(Index1, Index2: Integer);
+ procedure Move(CurIndex, NewIndex: Integer);
+ function First: T;
+ function Last: T;
+{$IFEND}
+ procedure Clear;
+ function Contains(const Value: T): Boolean;
+ function IndexOf(const Value: T): Integer;
+ function LastIndexOf(const Value: T): Integer;
+ procedure Reverse;
+ procedure Sort; overload;
+ procedure Sort(const AComparer: IComparer<T>); overload;
+ function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
+ function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
+ procedure TrimExcess;
+ function ToArray: TArray<T>;
+ property Capacity: Integer read GetCapacity write SetCapacity;
+ property Count: Integer read GetCount write SetCount;
+ property Items[Index: Integer]: T read GetItem write SetItem; default;
+ end;
+
+ TThriftListImpl<T> = class( TInterfacedObject, IThriftList<T>)
+ private
+ FList : TList<T>;
+ protected
+ function GetEnumerator: TEnumerator<T>;
+ function GetCapacity: Integer;
+ procedure SetCapacity(Value: Integer);
+ function GetCount: Integer;
+ procedure SetCount(Value: Integer);
+ function GetItem(Index: Integer): T;
+ procedure SetItem(Index: Integer; const Value: T);
+ function Add(const Value: T): Integer;
+ procedure AddRange(const Values: array of T); overload;
+ procedure AddRange(const Collection: IEnumerable<T>); overload;
+ procedure AddRange(Collection: TEnumerable<T>); overload;
+ procedure Insert(Index: Integer; const Value: T);
+ procedure InsertRange(Index: Integer; const Values: array of T); overload;
+ procedure InsertRange(Index: Integer; const Collection: IEnumerable<T>); overload;
+ procedure InsertRange(Index: Integer; const Collection: TEnumerable<T>); overload;
+ function Remove(const Value: T): Integer;
+ procedure Delete(Index: Integer);
+ procedure DeleteRange(AIndex, ACount: Integer);
+ function Extract(const Value: T): T;
+{$IF CompilerVersion >= 21.0}
+ procedure Exchange(Index1, Index2: Integer);
+ procedure Move(CurIndex, NewIndex: Integer);
+ function First: T;
+ function Last: T;
+{$IFEND}
+ procedure Clear;
+ function Contains(const Value: T): Boolean;
+ function IndexOf(const Value: T): Integer;
+ function LastIndexOf(const Value: T): Integer;
+ procedure Reverse;
+ procedure Sort; overload;
+ procedure Sort(const AComparer: IComparer<T>); overload;
+ function BinarySearch(const Item: T; out Index: Integer): Boolean; overload;
+ function BinarySearch(const Item: T; out Index: Integer; const AComparer: IComparer<T>): Boolean; overload;
+ procedure TrimExcess;
+ function ToArray: TArray<T>;
+ property Capacity: Integer read GetCapacity write SetCapacity;
+ property Count: Integer read GetCount write SetCount;
+ property Items[Index: Integer]: T read GetItem write SetItem; default;
+ public
+ constructor Create;
+ destructor Destroy; override;
+ end;
+
+ IHashSet<TValue> = interface(IThriftContainer)
+ ['{0923A3B5-D4D4-48A8-91AD-40238E2EAD66}']
+ function GetEnumerator: TEnumerator<TValue>;
+ function GetIsReadOnly: Boolean;
+ function GetCount: Integer;
+ property Count: Integer read GetCount;
+ property IsReadOnly: Boolean read GetIsReadOnly;
+ procedure Add( const item: TValue);
+ procedure Clear;
+ function Contains( const item: TValue): Boolean;
+ procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
+ function Remove( const item: TValue ): Boolean;
+ end;
+
+ THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>)
+ private
+ FDictionary : IThriftDictionary<TValue,Integer>;
+ FIsReadOnly: Boolean;
+ protected
+ function GetEnumerator: TEnumerator<TValue>;
+ function GetIsReadOnly: Boolean;
+ function GetCount: Integer;
+ property Count: Integer read GetCount;
+ property IsReadOnly: Boolean read FIsReadOnly;
+ procedure Add( const item: TValue);
+ procedure Clear;
+ function Contains( const item: TValue): Boolean;
+ procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
+ function Remove( const item: TValue ): Boolean;
+ public
+ constructor Create;
+ end;
+
+implementation
+
+{ THashSetImpl<TValue> }
+
+procedure THashSetImpl<TValue>.Add( const item: TValue);
+begin
+ if not FDictionary.ContainsKey(item) then
+ begin
+ FDictionary.Add( item, 0);
+ end;
+end;
+
+procedure THashSetImpl<TValue>.Clear;
+begin
+ FDictionary.Clear;
+end;
+
+function THashSetImpl<TValue>.Contains( const item: TValue): Boolean;
+begin
+ Result := FDictionary.ContainsKey(item);
+end;
+
+procedure THashSetImpl<TValue>.CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
+var
+ i : Integer;
+ Enumlator : TEnumerator<TValue>;
+begin
+ Enumlator := GetEnumerator;
+ while Enumlator.MoveNext do
+ begin
+ A[arrayIndex] := Enumlator.Current;
+ Inc(arrayIndex);
+ end;
+end;
+
+constructor THashSetImpl<TValue>.Create;
+begin
+ inherited;
+ FDictionary := TThriftDictionaryImpl<TValue,Integer>.Create;
+end;
+
+function THashSetImpl<TValue>.GetCount: Integer;
+begin
+ Result := FDictionary.Count;
+end;
+
+function THashSetImpl<TValue>.GetEnumerator: TEnumerator<TValue>;
+begin
+ Result := FDictionary.Keys.GetEnumerator;
+end;
+
+function THashSetImpl<TValue>.GetIsReadOnly: Boolean;
+begin
+ Result := FIsReadOnly;
+end;
+
+function THashSetImpl<TValue>.Remove( const item: TValue): Boolean;
+begin
+ Result := False;
+ if FDictionary.ContainsKey( item ) then
+ begin
+ FDictionary.Remove( item );
+ Result := not FDictionary.ContainsKey( item );
+ end;
+end;
+
+{ TThriftDictionaryImpl<TKey, TValue> }
+
+procedure TThriftDictionaryImpl<TKey, TValue>.Add(const Key: TKey;
+ const Value: TValue);
+begin
+ FDictionaly.Add( Key, Value);
+end;
+
+procedure TThriftDictionaryImpl<TKey, TValue>.AddOrSetValue(const Key: TKey;
+ const Value: TValue);
+begin
+ FDictionaly.AddOrSetValue( Key, Value);
+end;
+
+procedure TThriftDictionaryImpl<TKey, TValue>.Clear;
+begin
+ FDictionaly.Clear;
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.ContainsKey(
+ const Key: TKey): Boolean;
+begin
+ Result := FDictionaly.ContainsKey( Key );
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.ContainsValue(
+ const Value: TValue): Boolean;
+begin
+ Result := FDictionaly.ContainsValue( Value );
+end;
+
+constructor TThriftDictionaryImpl<TKey, TValue>.Create(ACapacity: Integer);
+begin
+ inherited Create;
+ FDictionaly := TDictionary<TKey,TValue>.Create( ACapacity );
+end;
+
+destructor TThriftDictionaryImpl<TKey, TValue>.Destroy;
+begin
+ FDictionaly.Free;
+ inherited;
+end;
+
+{$IF CompilerVersion >= 21.0}
+function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
+begin
+ Result := FDictionaly.ExtractPair( Key);
+end;
+{$IFEND}
+
+function TThriftDictionaryImpl<TKey, TValue>.GetCount: Integer;
+begin
+ Result := FDictionaly.Count;
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.GetEnumerator: TEnumerator<TPair<TKey, TValue>>;
+begin
+ Result := FDictionaly.GetEnumerator;
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.GetItem(const Key: TKey): TValue;
+begin
+ Result := FDictionaly.Items[Key];
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.GetKeys: TDictionary<TKey, TValue>.TKeyCollection;
+begin
+ Result := FDictionaly.Keys;
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.GetValues: TDictionary<TKey, TValue>.TValueCollection;
+begin
+ Result := FDictionaly.Values;
+end;
+
+procedure TThriftDictionaryImpl<TKey, TValue>.Remove(const Key: TKey);
+begin
+ FDictionaly.Remove( Key );
+end;
+
+procedure TThriftDictionaryImpl<TKey, TValue>.SetItem(const Key: TKey;
+ const Value: TValue);
+begin
+ FDictionaly.AddOrSetValue( Key, Value);
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.ToArray: TArray<TPair<TKey, TValue>>;
+{$IF CompilerVersion < 22.0}
+var
+ x : TPair<TKey, TValue>;
+ i : Integer;
+{$IFEND}
+begin
+{$IF CompilerVersion < 22.0}
+ SetLength(Result, Count);
+ i := 0;
+ for x in FDictionaly do
+ begin
+ Result[i] := x;
+ Inc( i );
+ end;
+{$ELSE}
+ Result := FDictionaly.ToArray;
+{$IFEND}
+end;
+
+procedure TThriftDictionaryImpl<TKey, TValue>.TrimExcess;
+begin
+ FDictionaly.TrimExcess;
+end;
+
+function TThriftDictionaryImpl<TKey, TValue>.TryGetValue(const Key: TKey;
+ out Value: TValue): Boolean;
+begin
+ Result := FDictionaly.TryGetValue( Key, Value);
+end;
+
+{ TThriftListImpl<T> }
+
+function TThriftListImpl<T>.Add(const Value: T): Integer;
+begin
+ Result := FList.Add( Value );
+end;
+
+procedure TThriftListImpl<T>.AddRange(Collection: TEnumerable<T>);
+begin
+ FList.AddRange( Collection );
+end;
+
+procedure TThriftListImpl<T>.AddRange(const Collection: IEnumerable<T>);
+begin
+ FList.AddRange( Collection );
+end;
+
+procedure TThriftListImpl<T>.AddRange(const Values: array of T);
+begin
+ FList.AddRange( Values );
+end;
+
+function TThriftListImpl<T>.BinarySearch(const Item: T;
+ out Index: Integer): Boolean;
+begin
+ Result := FList.BinarySearch( Item, Index);
+end;
+
+function TThriftListImpl<T>.BinarySearch(const Item: T; out Index: Integer;
+ const AComparer: IComparer<T>): Boolean;
+begin
+ Result := FList.BinarySearch( Item, Index, AComparer);
+end;
+
+procedure TThriftListImpl<T>.Clear;
+begin
+ FList.Clear;
+end;
+
+function TThriftListImpl<T>.Contains(const Value: T): Boolean;
+begin
+ Result := FList.Contains( Value );
+end;
+
+constructor TThriftListImpl<T>.Create;
+begin
+ inherited;
+ FList := TList<T>.Create;
+end;
+
+procedure TThriftListImpl<T>.Delete(Index: Integer);
+begin
+ FList.Delete( Index )
+end;
+
+procedure TThriftListImpl<T>.DeleteRange(AIndex, ACount: Integer);
+begin
+ FList.DeleteRange( AIndex, ACount)
+end;
+
+destructor TThriftListImpl<T>.Destroy;
+begin
+ FList.Free;
+ inherited;
+end;
+
+{$IF CompilerVersion >= 21.0}
+procedure TThriftListImpl<T>.Exchange(Index1, Index2: Integer);
+begin
+ FList.Exchange( Index1, Index2 )
+end;
+{$IFEND}
+
+function TThriftListImpl<T>.Extract(const Value: T): T;
+begin
+ Result := FList.Extract( Value )
+end;
+
+{$IF CompilerVersion >= 21.0}
+function TThriftListImpl<T>.First: T;
+begin
+ Result := FList.First;
+end;
+{$IFEND}
+
+function TThriftListImpl<T>.GetCapacity: Integer;
+begin
+ Result := FList.Capacity;
+end;
+
+function TThriftListImpl<T>.GetCount: Integer;
+begin
+ Result := FList.Count;
+end;
+
+function TThriftListImpl<T>.GetEnumerator: TEnumerator<T>;
+begin
+ Result := FList.GetEnumerator;
+end;
+
+function TThriftListImpl<T>.GetItem(Index: Integer): T;
+begin
+ Result := FList[Index];
+end;
+
+function TThriftListImpl<T>.IndexOf(const Value: T): Integer;
+begin
+ Result := FList.IndexOf( Value );
+end;
+
+procedure TThriftListImpl<T>.Insert(Index: Integer; const Value: T);
+begin
+ FList.Insert( Index, Value);
+end;
+
+procedure TThriftListImpl<T>.InsertRange(Index: Integer;
+ const Collection: TEnumerable<T>);
+begin
+ FList.InsertRange( Index, Collection );
+end;
+
+procedure TThriftListImpl<T>.InsertRange(Index: Integer;
+ const Values: array of T);
+begin
+ FList.InsertRange( Index, Values);
+end;
+
+procedure TThriftListImpl<T>.InsertRange(Index: Integer;
+ const Collection: IEnumerable<T>);
+begin
+ FList.InsertRange( Index, Collection );
+end;
+
+{$IF CompilerVersion >= 21.0}
+function TThriftListImpl<T>.Last: T;
+begin
+ Result := FList.Last;
+end;
+{$IFEND}
+
+function TThriftListImpl<T>.LastIndexOf(const Value: T): Integer;
+begin
+ Result := FList.LastIndexOf( Value );
+end;
+
+{$IF CompilerVersion >= 21.0}
+procedure TThriftListImpl<T>.Move(CurIndex, NewIndex: Integer);
+begin
+ FList.Move( CurIndex, NewIndex);
+end;
+{$IFEND}
+
+function TThriftListImpl<T>.Remove(const Value: T): Integer;
+begin
+ Result := FList.Remove( Value );
+end;
+
+procedure TThriftListImpl<T>.Reverse;
+begin
+ FList.Reverse;
+end;
+
+procedure TThriftListImpl<T>.SetCapacity(Value: Integer);
+begin
+ FList.Capacity := Value;
+end;
+
+procedure TThriftListImpl<T>.SetCount(Value: Integer);
+begin
+ FList.Count := Value;
+end;
+
+procedure TThriftListImpl<T>.SetItem(Index: Integer; const Value: T);
+begin
+ FList[Index] := Value;
+end;
+
+procedure TThriftListImpl<T>.Sort;
+begin
+ FList.Sort;
+end;
+
+procedure TThriftListImpl<T>.Sort(const AComparer: IComparer<T>);
+begin
+ FList.Sort;
+end;
+
+function TThriftListImpl<T>.ToArray: TArray<T>;
+{$IF CompilerVersion < 22.0}
+var
+ x : T;
+ i : Integer;
+{$IFEND}
+begin
+{$IF CompilerVersion < 22.0}
+ SetLength(Result, Count);
+ i := 0;
+ for x in FList do
+ begin
+ Result[i] := x;
+ Inc( i );
+ end;
+{$ELSE}
+ Result := FList.ToArray;
+{$IFEND}
+end;
+
+procedure TThriftListImpl<T>.TrimExcess;
+begin
+ FList.TrimExcess;
+end;
+
+end.
diff --git a/lib/delphi/src/Thrift.Console.pas b/lib/delphi/src/Thrift.Console.pas
index 5d1345b..a52eeb9 100644
--- a/lib/delphi/src/Thrift.Console.pas
+++ b/lib/delphi/src/Thrift.Console.pas
@@ -1,133 +1,133 @@
-(*
- * 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.
- *)
-
-unit Thrift.Console;
-
-interface
-
-uses
- StdCtrls;
-
-type
- TThriftConsole = class
- public
- procedure Write( const S: string); virtual;
- procedure WriteLine( const S: string); virtual;
- end;
-
- TGUIConsole = class( TThriftConsole )
- private
- FLineBreak : Boolean;
- FMemo : TMemo;
-
- procedure InternalWrite( const S: string; bWriteLine: Boolean);
- public
- procedure Write( const S: string); override;
- procedure WriteLine( const S: string); override;
- constructor Create( AMemo: TMemo);
- end;
-
-function Console: TThriftConsole;
-procedure ChangeConsole( AConsole: TThriftConsole );
-procedure RestoreConsoleToDefault;
-
-implementation
-
-var
- FDefaultConsole : TThriftConsole;
- FConsole : TThriftConsole;
-
-function Console: TThriftConsole;
-begin
- Result := FConsole;
-end;
-
-{ TThriftConsole }
-
-procedure TThriftConsole.Write(const S: string);
-begin
- System.Write( S );
-end;
-
-procedure TThriftConsole.WriteLine(const S: string);
-begin
- System.Writeln( S );
-end;
-
-procedure ChangeConsole( AConsole: TThriftConsole );
-begin
- FConsole := AConsole;
-end;
-
-procedure RestoreConsoleToDefault;
-begin
- FConsole := FDefaultConsole;
-end;
-
-{ TGUIConsole }
-
-constructor TGUIConsole.Create( AMemo: TMemo);
-begin
- inherited Create;
- FMemo := AMemo;
- FLineBreak := True;
-end;
-
-procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
-var
- idx : Integer;
-begin
- if FLineBreak then
- begin
- FMemo.Lines.Add( S );
- end else
- begin
- idx := FMemo.Lines.Count - 1;
- if idx < 0 then
- begin
- FMemo.Lines.Add( S );
- end;
- FMemo.Lines[idx] := FMemo.Lines[idx] + S;
- end;
- FLineBreak := bWriteLine;
-end;
-
-procedure TGUIConsole.Write(const S: string);
-begin
- InternalWrite( S, False);
-end;
-
-procedure TGUIConsole.WriteLine(const S: string);
-begin
- InternalWrite( S, True);
-end;
-
-initialization
-begin
- FDefaultConsole := TThriftConsole.Create;
- FConsole := FDefaultConsole;
-end;
-
-finalization
-begin
- FDefaultConsole.Free;
-end;
-
-end.
-
+(*
+ * 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.
+ *)
+
+unit Thrift.Console;
+
+interface
+
+uses
+ StdCtrls;
+
+type
+ TThriftConsole = class
+ public
+ procedure Write( const S: string); virtual;
+ procedure WriteLine( const S: string); virtual;
+ end;
+
+ TGUIConsole = class( TThriftConsole )
+ private
+ FLineBreak : Boolean;
+ FMemo : TMemo;
+
+ procedure InternalWrite( const S: string; bWriteLine: Boolean);
+ public
+ procedure Write( const S: string); override;
+ procedure WriteLine( const S: string); override;
+ constructor Create( AMemo: TMemo);
+ end;
+
+function Console: TThriftConsole;
+procedure ChangeConsole( AConsole: TThriftConsole );
+procedure RestoreConsoleToDefault;
+
+implementation
+
+var
+ FDefaultConsole : TThriftConsole;
+ FConsole : TThriftConsole;
+
+function Console: TThriftConsole;
+begin
+ Result := FConsole;
+end;
+
+{ TThriftConsole }
+
+procedure TThriftConsole.Write(const S: string);
+begin
+ System.Write( S );
+end;
+
+procedure TThriftConsole.WriteLine(const S: string);
+begin
+ System.Writeln( S );
+end;
+
+procedure ChangeConsole( AConsole: TThriftConsole );
+begin
+ FConsole := AConsole;
+end;
+
+procedure RestoreConsoleToDefault;
+begin
+ FConsole := FDefaultConsole;
+end;
+
+{ TGUIConsole }
+
+constructor TGUIConsole.Create( AMemo: TMemo);
+begin
+ inherited Create;
+ FMemo := AMemo;
+ FLineBreak := True;
+end;
+
+procedure TGUIConsole.InternalWrite(const S: string; bWriteLine: Boolean);
+var
+ idx : Integer;
+begin
+ if FLineBreak then
+ begin
+ FMemo.Lines.Add( S );
+ end else
+ begin
+ idx := FMemo.Lines.Count - 1;
+ if idx < 0 then
+ begin
+ FMemo.Lines.Add( S );
+ end;
+ FMemo.Lines[idx] := FMemo.Lines[idx] + S;
+ end;
+ FLineBreak := bWriteLine;
+end;
+
+procedure TGUIConsole.Write(const S: string);
+begin
+ InternalWrite( S, False);
+end;
+
+procedure TGUIConsole.WriteLine(const S: string);
+begin
+ InternalWrite( S, True);
+end;
+
+initialization
+begin
+ FDefaultConsole := TThriftConsole.Create;
+ FConsole := FDefaultConsole;
+end;
+
+finalization
+begin
+ FDefaultConsole.Free;
+end;
+
+end.
+
diff --git a/lib/delphi/src/Thrift.Processor.Multiplex.pas b/lib/delphi/src/Thrift.Processor.Multiplex.pas
index 198bed8..f6d9446 100644
--- a/lib/delphi/src/Thrift.Processor.Multiplex.pas
+++ b/lib/delphi/src/Thrift.Processor.Multiplex.pas
@@ -1,22 +1,22 @@
(*
- * 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.
- *)
-
+ * 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.
+ *)
+
unit Thrift.Processor.Multiplex;
@@ -53,7 +53,7 @@
type
IMultiplexedProcessor = interface( IProcessor)
- ['{810FF32D-22A2-4D58-B129-B0590703ECEC}']
+ ['{810FF32D-22A2-4D58-B129-B0590703ECEC}']
// Register a service with this TMultiplexedProcessor. This allows us
// to broker requests to individual services by using the service name
// to select them at request time.
@@ -150,14 +150,14 @@
appex := TApplicationException.Create( extype, etxt);
try
newMsg := TMessageImpl.Create( msg.Name, TMessageType.Exception, msg.SeqID);
-
+
oprot.WriteMessageBegin(newMsg);
appex.Write(oprot);
oprot.WriteMessageEnd();
oprot.Transport.Flush();
finally
- appex.Free;
+ appex.Free;
end;
end;
@@ -180,9 +180,9 @@
Error( oprot, msg,
TApplicationException.TExceptionType.InvalidMessageType,
ERROR_INVALID_MSGTYPE);
- Exit( FALSE);
- end;
-
+ Exit( FALSE);
+ end;
+
// Extract the service name
idx := Pos( TMultiplexedProtocol.SEPARATOR, msg.Name);
if idx < 1 then begin
@@ -190,7 +190,7 @@
TApplicationException.TExceptionType.InvalidProtocol,
Format(ERROR_INCOMPATIBLE_PROT,[msg.Name]));
Exit( FALSE);
- end;
+ end;
// Create a new TMessage, something that can be consumed by any TProtocol
sService := Copy( msg.Name, 1, idx-1);
@@ -200,7 +200,7 @@
TApplicationException.TExceptionType.InternalError,
Format(ERROR_UNKNOWN_SERVICE,[sService]));
Exit( FALSE);
- end;
+ end;
// Create a new TMessage, removing the service name
Inc( idx, Length(TMultiplexedProtocol.SEPARATOR));
diff --git a/lib/delphi/src/Thrift.Protocol.Multiplex.pas b/lib/delphi/src/Thrift.Protocol.Multiplex.pas
index 2cd2401..18b39b5 100644
--- a/lib/delphi/src/Thrift.Protocol.Multiplex.pas
+++ b/lib/delphi/src/Thrift.Protocol.Multiplex.pas
@@ -1,22 +1,22 @@
(*
- * 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.
- *)
-
+ * 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.
+ *)
+
unit Thrift.Protocol.Multiplex;
interface
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index 4d92cb1..6cff09c 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -1,505 +1,505 @@
-(*
- * 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.
- *)
-
-{$SCOPEDENUMS ON}
-
-unit Thrift.Protocol;
-
-interface
-
-uses
- Classes,
- SysUtils,
- Contnrs,
- Thrift.Stream,
- Thrift.Collections,
- Thrift.Transport;
-
-type
-
- TType = (
- Stop = 0,
- Void = 1,
- Bool_ = 2,
- Byte_ = 3,
- Double_ = 4,
- I16 = 6,
- I32 = 8,
- I64 = 10,
- String_ = 11,
- Struct = 12,
- Map = 13,
- Set_ = 14,
- List = 15
- );
-
- TMessageType = (
- Call = 1,
- Reply = 2,
- Exception = 3,
- Oneway = 4
- );
-
- IProtocol = interface;
- IStruct = interface;
-
- IProtocolFactory = interface
- ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}']
- function GetProtocol( const trans: ITransport): IProtocol;
- end;
-
- TThriftStringBuilder = class( TStringBuilder)
- public
- function Append(const Value: TBytes): TStringBuilder; overload;
- function Append(const Value: IThriftContainer): TStringBuilder; overload;
- end;
-
- TProtocolException = class( Exception )
- public
- const // TODO(jensg): change into enum
- UNKNOWN : Integer = 0;
- INVALID_DATA : Integer = 1;
- NEGATIVE_SIZE : Integer = 2;
- SIZE_LIMIT : Integer = 3;
- BAD_VERSION : Integer = 4;
- NOT_IMPLEMENTED : Integer = 5;
- DEPTH_LIMIT : Integer = 6;
- protected
- FType : Integer;
- public
- constructor Create; overload;
- constructor Create( type_: Integer ); overload;
- constructor Create( type_: Integer; const msg: string); overload;
- end;
-
- IMap = interface
- ['{30531D97-7E06-4233-B800-C3F53CCD23E7}']
- function GetKeyType: TType;
- procedure SetKeyType( Value: TType);
- function GetValueType: TType;
- procedure SetValueType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- property KeyType: TType read GetKeyType write SetKeyType;
- property ValueType: TType read GetValueType write SetValueType;
- property Count: Integer read GetCount write SetCount;
- end;
-
- TMapImpl = class( TInterfacedObject, IMap)
- private
- FValueType: TType;
- FKeyType: TType;
- FCount: Integer;
- protected
- function GetKeyType: TType;
- procedure SetKeyType( Value: TType);
- function GetValueType: TType;
- procedure SetValueType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- public
- constructor Create( AValueType: TType; AKeyType: TType; ACount: Integer); overload;
- constructor Create; overload;
- end;
-
- IList = interface
- ['{6763E1EA-A934-4472-904F-0083980B9B87}']
- function GetElementType: TType;
- procedure SetElementType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- property ElementType: TType read GetElementType write SetElementType;
- property Count: Integer read GetCount write SetCount;
- end;
-
- TListImpl = class( TInterfacedObject, IList)
- private
- FElementType: TType;
- FCount : Integer;
- protected
- function GetElementType: TType;
- procedure SetElementType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- public
- constructor Create( AElementType: TType; ACount: Integer); overload;
- constructor Create; overload;
- end;
-
- ISet = interface
- ['{A8671700-7514-4C1E-8A05-62786872005F}']
- function GetElementType: TType;
- procedure SetElementType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- property ElementType: TType read GetElementType write SetElementType;
- property Count: Integer read GetCount write SetCount;
- end;
-
- TSetImpl = class( TInterfacedObject, ISet)
- private
- FCount: Integer;
- FElementType: TType;
- protected
- function GetElementType: TType;
- procedure SetElementType( Value: TType);
- function GetCount: Integer;
- procedure SetCount( Value: Integer);
- public
- constructor Create( AElementType: TType; ACount: Integer); overload;
- constructor Create; overload;
- end;
-
- IMessage = interface
- ['{9E368B4A-B1FA-43E7-8CF5-56C66D256CA7}']
- function GetName: string;
- procedure SetName( const Value: string);
- function GetType: TMessageType;
- procedure SetType( Value: TMessageType);
- function GetSeqID: Integer;
- procedure SetSeqID( Value: Integer);
- property Name: string read GetName write SetName;
- property Type_: TMessageType read GetType write SetType;
- property SeqID: Integer read GetSeqID write SetSeqID;
- end;
-
- TMessageImpl = class( TInterfacedObject, IMessage )
- private
- FName: string;
- FMessageType: TMessageType;
- FSeqID: Integer;
- protected
- function GetName: string;
- procedure SetName( const Value: string);
- function GetType: TMessageType;
- procedure SetType( Value: TMessageType);
- function GetSeqID: Integer;
- procedure SetSeqID( Value: Integer);
- public
- property Name: string read FName write FName;
- property Type_: TMessageType read FMessageType write FMessageType;
- property SeqID: Integer read FSeqID write FSeqID;
- constructor Create( AName: string; AMessageType: TMessageType; ASeqID: Integer); overload;
- constructor Create; overload;
- end;
-
- IField = interface
- ['{F0D43BE5-7883-442E-83FF-0580CC632B72}']
- function GetName: string;
- procedure SetName( const Value: string);
- function GetType: TType;
- procedure SetType( Value: TType);
- function GetId: SmallInt;
- procedure SetId( Value: SmallInt);
- property Name: string read GetName write SetName;
- property Type_: TType read GetType write SetType;
- property Id: SmallInt read GetId write SetId;
- end;
-
- TFieldImpl = class( TInterfacedObject, IField)
- private
- FName : string;
- FType : TType;
- FId : SmallInt;
- protected
- function GetName: string;
- procedure SetName( const Value: string);
- function GetType: TType;
- procedure SetType( Value: TType);
- function GetId: SmallInt;
- procedure SetId( Value: SmallInt);
- public
- constructor Create( const AName: string; const AType: TType; AId: SmallInt); overload;
- constructor Create; overload;
- end;
-
- TProtocolUtil = class
- public
- class procedure Skip( prot: IProtocol; type_: TType);
- end;
-
- IProtocol = interface
- ['{FD95C151-1527-4C96-8134-B902BFC4B4FC}']
- function GetTransport: ITransport;
- procedure WriteMessageBegin( const msg: IMessage);
- procedure WriteMessageEnd;
- procedure WriteStructBegin( const struc: IStruct);
- procedure WriteStructEnd;
- procedure WriteFieldBegin( const field: IField);
- procedure WriteFieldEnd;
- procedure WriteFieldStop;
- procedure WriteMapBegin( const map: IMap);
- procedure WriteMapEnd;
- procedure WriteListBegin( const list: IList);
- procedure WriteListEnd();
- procedure WriteSetBegin( const set_: ISet );
- procedure WriteSetEnd();
- procedure WriteBool( b: Boolean);
- procedure WriteByte( b: ShortInt);
- procedure WriteI16( i16: SmallInt);
- procedure WriteI32( i32: Integer);
- procedure WriteI64( const i64: Int64);
- procedure WriteDouble( const d: Double);
- procedure WriteString( const s: string );
- procedure WriteAnsiString( const s: AnsiString);
- procedure WriteBinary( const b: TBytes);
-
- function ReadMessageBegin: IMessage;
- procedure ReadMessageEnd();
- function ReadStructBegin: IStruct;
- procedure ReadStructEnd;
- function ReadFieldBegin: IField;
- procedure ReadFieldEnd();
- function ReadMapBegin: IMap;
- procedure ReadMapEnd();
- function ReadListBegin: IList;
- procedure ReadListEnd();
- function ReadSetBegin: ISet;
- procedure ReadSetEnd();
- function ReadBool: Boolean;
- function ReadByte: ShortInt;
- function ReadI16: SmallInt;
- function ReadI32: Integer;
- function ReadI64: Int64;
- function ReadDouble:Double;
- function ReadBinary: TBytes;
- function ReadString: string;
- function ReadAnsiString: AnsiString;
- property Transport: ITransport read GetTransport;
- end;
-
- TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
- protected
- FTrans : ITransport;
- function GetTransport: ITransport;
- public
- procedure WriteMessageBegin( const msg: IMessage); virtual; abstract;
- procedure WriteMessageEnd; virtual; abstract;
- procedure WriteStructBegin( const struc: IStruct); virtual; abstract;
- procedure WriteStructEnd; virtual; abstract;
- procedure WriteFieldBegin( const field: IField); virtual; abstract;
- procedure WriteFieldEnd; virtual; abstract;
- procedure WriteFieldStop; virtual; abstract;
- procedure WriteMapBegin( const map: IMap); virtual; abstract;
- procedure WriteMapEnd; virtual; abstract;
- procedure WriteListBegin( const list: IList); virtual; abstract;
- procedure WriteListEnd(); virtual; abstract;
- procedure WriteSetBegin( const set_: ISet ); virtual; abstract;
- procedure WriteSetEnd(); virtual; abstract;
- procedure WriteBool( b: Boolean); virtual; abstract;
- procedure WriteByte( b: ShortInt); virtual; abstract;
- procedure WriteI16( i16: SmallInt); virtual; abstract;
- procedure WriteI32( i32: Integer); virtual; abstract;
- procedure WriteI64( const i64: Int64); virtual; abstract;
- procedure WriteDouble( const d: Double); virtual; abstract;
- procedure WriteString( const s: string ); virtual;
- procedure WriteAnsiString( const s: AnsiString); virtual;
- procedure WriteBinary( const b: TBytes); virtual; abstract;
-
- function ReadMessageBegin: IMessage; virtual; abstract;
- procedure ReadMessageEnd(); virtual; abstract;
- function ReadStructBegin: IStruct; virtual; abstract;
- procedure ReadStructEnd; virtual; abstract;
- function ReadFieldBegin: IField; virtual; abstract;
- procedure ReadFieldEnd(); virtual; abstract;
- function ReadMapBegin: IMap; virtual; abstract;
- procedure ReadMapEnd(); virtual; abstract;
- function ReadListBegin: IList; virtual; abstract;
- procedure ReadListEnd(); virtual; abstract;
- function ReadSetBegin: ISet; virtual; abstract;
- procedure ReadSetEnd(); virtual; abstract;
- function ReadBool: Boolean; virtual; abstract;
- function ReadByte: ShortInt; virtual; abstract;
- function ReadI16: SmallInt; virtual; abstract;
- function ReadI32: Integer; virtual; abstract;
- function ReadI64: Int64; virtual; abstract;
- function ReadDouble:Double; virtual; abstract;
- function ReadBinary: TBytes; virtual; abstract;
- function ReadString: string; virtual;
- function ReadAnsiString: AnsiString; virtual;
-
- property Transport: ITransport read GetTransport;
-
- constructor Create( trans: ITransport );
- end;
-
- IBase = interface
- ['{08D9BAA8-5EAA-410F-B50B-AC2E6E5E4155}']
- function ToString: string;
- procedure Read( const iprot: IProtocol);
- procedure Write( const iprot: IProtocol);
- end;
-
- IStruct = interface
- ['{5DCE39AA-C916-4BC7-A79B-96A0C36B2220}']
- procedure SetName(const Value: string);
- function GetName: string;
- property Name: string read GetName write SetName;
- end;
-
- TStructImpl = class( TInterfacedObject, IStruct )
- private
- FName: string;
- protected
- function GetName: string;
- procedure SetName(const Value: string);
- public
- constructor Create( const AName: string);
- end;
-
- TBinaryProtocolImpl = class( TProtocolImpl )
- protected
- const
- VERSION_MASK : Cardinal = $ffff0000;
- VERSION_1 : Cardinal = $80010000;
- protected
- FStrictRead : Boolean;
- FStrictWrite : Boolean;
-
- private
- function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;
- function ReadStringBody( size: Integer): string;
-
- public
-
- type
- TFactory = class( TInterfacedObject, IProtocolFactory)
- protected
- FStrictRead : Boolean;
- FStrictWrite : Boolean;
- public
- function GetProtocol( const trans: ITransport): IProtocol;
- constructor Create( AStrictRead, AStrictWrite: Boolean ); overload;
- constructor Create; overload;
- end;
-
- constructor Create( const trans: ITransport); overload;
- constructor Create( const trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload;
-
- procedure WriteMessageBegin( const msg: IMessage); override;
- procedure WriteMessageEnd; override;
- procedure WriteStructBegin( const struc: IStruct); override;
- procedure WriteStructEnd; override;
- procedure WriteFieldBegin( const field: IField); override;
- procedure WriteFieldEnd; override;
- procedure WriteFieldStop; override;
- procedure WriteMapBegin( const map: IMap); override;
- procedure WriteMapEnd; override;
- procedure WriteListBegin( const list: IList); override;
- procedure WriteListEnd(); override;
- procedure WriteSetBegin( const set_: ISet ); override;
- procedure WriteSetEnd(); override;
- procedure WriteBool( b: Boolean); override;
- procedure WriteByte( b: ShortInt); override;
- procedure WriteI16( i16: SmallInt); override;
- procedure WriteI32( i32: Integer); override;
- procedure WriteI64( const i64: Int64); override;
- procedure WriteDouble( const d: Double); override;
- procedure WriteBinary( const b: TBytes); override;
-
- function ReadMessageBegin: IMessage; override;
- procedure ReadMessageEnd(); override;
- function ReadStructBegin: IStruct; override;
- procedure ReadStructEnd; override;
- function ReadFieldBegin: IField; override;
- procedure ReadFieldEnd(); override;
- function ReadMapBegin: IMap; override;
- procedure ReadMapEnd(); override;
- function ReadListBegin: IList; override;
- procedure ReadListEnd(); override;
- function ReadSetBegin: ISet; override;
- procedure ReadSetEnd(); override;
- function ReadBool: Boolean; override;
- function ReadByte: ShortInt; override;
- function ReadI16: SmallInt; override;
- function ReadI32: Integer; override;
- function ReadI64: Int64; override;
- function ReadDouble:Double; override;
- function ReadBinary: TBytes; override;
-
- end;
-
-
- { TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
- providing a way to author concise concrete decorator subclasses. The decorator
- does not (and should not) modify the behaviour of the enclosed TProtocol
-
- See p.175 of Design Patterns (by Gamma et al.)
- }
- TProtocolDecorator = class( TProtocolImpl)
- private
- FWrappedProtocol : IProtocol;
-
- public
- // Encloses the specified protocol.
- // All operations will be forward to the given protocol. Must be non-null.
- constructor Create( const aProtocol : IProtocol);
-
- procedure WriteMessageBegin( const msg: IMessage); override;
- procedure WriteMessageEnd; override;
- procedure WriteStructBegin( const struc: IStruct); override;
- procedure WriteStructEnd; override;
- procedure WriteFieldBegin( const field: IField); override;
- procedure WriteFieldEnd; override;
- procedure WriteFieldStop; override;
- procedure WriteMapBegin( const map: IMap); override;
- procedure WriteMapEnd; override;
- procedure WriteListBegin( const list: IList); override;
- procedure WriteListEnd(); override;
- procedure WriteSetBegin( const set_: ISet ); override;
- procedure WriteSetEnd(); override;
- procedure WriteBool( b: Boolean); override;
- procedure WriteByte( b: ShortInt); override;
- procedure WriteI16( i16: SmallInt); override;
- procedure WriteI32( i32: Integer); override;
- procedure WriteI64( const i64: Int64); override;
- procedure WriteDouble( const d: Double); override;
- procedure WriteString( const s: string ); override;
- procedure WriteAnsiString( const s: AnsiString); override;
- procedure WriteBinary( const b: TBytes); override;
-
- function ReadMessageBegin: IMessage; override;
- procedure ReadMessageEnd(); override;
- function ReadStructBegin: IStruct; override;
- procedure ReadStructEnd; override;
- function ReadFieldBegin: IField; override;
- procedure ReadFieldEnd(); override;
- function ReadMapBegin: IMap; override;
- procedure ReadMapEnd(); override;
- function ReadListBegin: IList; override;
- procedure ReadListEnd(); override;
- function ReadSetBegin: ISet; override;
- procedure ReadSetEnd(); override;
- function ReadBool: Boolean; override;
- function ReadByte: ShortInt; override;
- function ReadI16: SmallInt; override;
- function ReadI32: Integer; override;
- function ReadI64: Int64; override;
- function ReadDouble:Double; override;
- function ReadBinary: TBytes; override;
- function ReadString: string; override;
- function ReadAnsiString: AnsiString; override;
- end;
-
-
-type
- IRequestEvents = interface
+(*
+ * 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.
+ *)
+
+{$SCOPEDENUMS ON}
+
+unit Thrift.Protocol;
+
+interface
+
+uses
+ Classes,
+ SysUtils,
+ Contnrs,
+ Thrift.Stream,
+ Thrift.Collections,
+ Thrift.Transport;
+
+type
+
+ TType = (
+ Stop = 0,
+ Void = 1,
+ Bool_ = 2,
+ Byte_ = 3,
+ Double_ = 4,
+ I16 = 6,
+ I32 = 8,
+ I64 = 10,
+ String_ = 11,
+ Struct = 12,
+ Map = 13,
+ Set_ = 14,
+ List = 15
+ );
+
+ TMessageType = (
+ Call = 1,
+ Reply = 2,
+ Exception = 3,
+ Oneway = 4
+ );
+
+ IProtocol = interface;
+ IStruct = interface;
+
+ IProtocolFactory = interface
+ ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}']
+ function GetProtocol( const trans: ITransport): IProtocol;
+ end;
+
+ TThriftStringBuilder = class( TStringBuilder)
+ public
+ function Append(const Value: TBytes): TStringBuilder; overload;
+ function Append(const Value: IThriftContainer): TStringBuilder; overload;
+ end;
+
+ TProtocolException = class( Exception )
+ public
+ const // TODO(jensg): change into enum
+ UNKNOWN : Integer = 0;
+ INVALID_DATA : Integer = 1;
+ NEGATIVE_SIZE : Integer = 2;
+ SIZE_LIMIT : Integer = 3;
+ BAD_VERSION : Integer = 4;
+ NOT_IMPLEMENTED : Integer = 5;
+ DEPTH_LIMIT : Integer = 6;
+ protected
+ FType : Integer;
+ public
+ constructor Create; overload;
+ constructor Create( type_: Integer ); overload;
+ constructor Create( type_: Integer; const msg: string); overload;
+ end;
+
+ IMap = interface
+ ['{30531D97-7E06-4233-B800-C3F53CCD23E7}']
+ function GetKeyType: TType;
+ procedure SetKeyType( Value: TType);
+ function GetValueType: TType;
+ procedure SetValueType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ property KeyType: TType read GetKeyType write SetKeyType;
+ property ValueType: TType read GetValueType write SetValueType;
+ property Count: Integer read GetCount write SetCount;
+ end;
+
+ TMapImpl = class( TInterfacedObject, IMap)
+ private
+ FValueType: TType;
+ FKeyType: TType;
+ FCount: Integer;
+ protected
+ function GetKeyType: TType;
+ procedure SetKeyType( Value: TType);
+ function GetValueType: TType;
+ procedure SetValueType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ public
+ constructor Create( AValueType: TType; AKeyType: TType; ACount: Integer); overload;
+ constructor Create; overload;
+ end;
+
+ IList = interface
+ ['{6763E1EA-A934-4472-904F-0083980B9B87}']
+ function GetElementType: TType;
+ procedure SetElementType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ property ElementType: TType read GetElementType write SetElementType;
+ property Count: Integer read GetCount write SetCount;
+ end;
+
+ TListImpl = class( TInterfacedObject, IList)
+ private
+ FElementType: TType;
+ FCount : Integer;
+ protected
+ function GetElementType: TType;
+ procedure SetElementType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ public
+ constructor Create( AElementType: TType; ACount: Integer); overload;
+ constructor Create; overload;
+ end;
+
+ ISet = interface
+ ['{A8671700-7514-4C1E-8A05-62786872005F}']
+ function GetElementType: TType;
+ procedure SetElementType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ property ElementType: TType read GetElementType write SetElementType;
+ property Count: Integer read GetCount write SetCount;
+ end;
+
+ TSetImpl = class( TInterfacedObject, ISet)
+ private
+ FCount: Integer;
+ FElementType: TType;
+ protected
+ function GetElementType: TType;
+ procedure SetElementType( Value: TType);
+ function GetCount: Integer;
+ procedure SetCount( Value: Integer);
+ public
+ constructor Create( AElementType: TType; ACount: Integer); overload;
+ constructor Create; overload;
+ end;
+
+ IMessage = interface
+ ['{9E368B4A-B1FA-43E7-8CF5-56C66D256CA7}']
+ function GetName: string;
+ procedure SetName( const Value: string);
+ function GetType: TMessageType;
+ procedure SetType( Value: TMessageType);
+ function GetSeqID: Integer;
+ procedure SetSeqID( Value: Integer);
+ property Name: string read GetName write SetName;
+ property Type_: TMessageType read GetType write SetType;
+ property SeqID: Integer read GetSeqID write SetSeqID;
+ end;
+
+ TMessageImpl = class( TInterfacedObject, IMessage )
+ private
+ FName: string;
+ FMessageType: TMessageType;
+ FSeqID: Integer;
+ protected
+ function GetName: string;
+ procedure SetName( const Value: string);
+ function GetType: TMessageType;
+ procedure SetType( Value: TMessageType);
+ function GetSeqID: Integer;
+ procedure SetSeqID( Value: Integer);
+ public
+ property Name: string read FName write FName;
+ property Type_: TMessageType read FMessageType write FMessageType;
+ property SeqID: Integer read FSeqID write FSeqID;
+ constructor Create( AName: string; AMessageType: TMessageType; ASeqID: Integer); overload;
+ constructor Create; overload;
+ end;
+
+ IField = interface
+ ['{F0D43BE5-7883-442E-83FF-0580CC632B72}']
+ function GetName: string;
+ procedure SetName( const Value: string);
+ function GetType: TType;
+ procedure SetType( Value: TType);
+ function GetId: SmallInt;
+ procedure SetId( Value: SmallInt);
+ property Name: string read GetName write SetName;
+ property Type_: TType read GetType write SetType;
+ property Id: SmallInt read GetId write SetId;
+ end;
+
+ TFieldImpl = class( TInterfacedObject, IField)
+ private
+ FName : string;
+ FType : TType;
+ FId : SmallInt;
+ protected
+ function GetName: string;
+ procedure SetName( const Value: string);
+ function GetType: TType;
+ procedure SetType( Value: TType);
+ function GetId: SmallInt;
+ procedure SetId( Value: SmallInt);
+ public
+ constructor Create( const AName: string; const AType: TType; AId: SmallInt); overload;
+ constructor Create; overload;
+ end;
+
+ TProtocolUtil = class
+ public
+ class procedure Skip( prot: IProtocol; type_: TType);
+ end;
+
+ IProtocol = interface
+ ['{FD95C151-1527-4C96-8134-B902BFC4B4FC}']
+ function GetTransport: ITransport;
+ procedure WriteMessageBegin( const msg: IMessage);
+ procedure WriteMessageEnd;
+ procedure WriteStructBegin( const struc: IStruct);
+ procedure WriteStructEnd;
+ procedure WriteFieldBegin( const field: IField);
+ procedure WriteFieldEnd;
+ procedure WriteFieldStop;
+ procedure WriteMapBegin( const map: IMap);
+ procedure WriteMapEnd;
+ procedure WriteListBegin( const list: IList);
+ procedure WriteListEnd();
+ procedure WriteSetBegin( const set_: ISet );
+ procedure WriteSetEnd();
+ procedure WriteBool( b: Boolean);
+ procedure WriteByte( b: ShortInt);
+ procedure WriteI16( i16: SmallInt);
+ procedure WriteI32( i32: Integer);
+ procedure WriteI64( const i64: Int64);
+ procedure WriteDouble( const d: Double);
+ procedure WriteString( const s: string );
+ procedure WriteAnsiString( const s: AnsiString);
+ procedure WriteBinary( const b: TBytes);
+
+ function ReadMessageBegin: IMessage;
+ procedure ReadMessageEnd();
+ function ReadStructBegin: IStruct;
+ procedure ReadStructEnd;
+ function ReadFieldBegin: IField;
+ procedure ReadFieldEnd();
+ function ReadMapBegin: IMap;
+ procedure ReadMapEnd();
+ function ReadListBegin: IList;
+ procedure ReadListEnd();
+ function ReadSetBegin: ISet;
+ procedure ReadSetEnd();
+ function ReadBool: Boolean;
+ function ReadByte: ShortInt;
+ function ReadI16: SmallInt;
+ function ReadI32: Integer;
+ function ReadI64: Int64;
+ function ReadDouble:Double;
+ function ReadBinary: TBytes;
+ function ReadString: string;
+ function ReadAnsiString: AnsiString;
+ property Transport: ITransport read GetTransport;
+ end;
+
+ TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
+ protected
+ FTrans : ITransport;
+ function GetTransport: ITransport;
+ public
+ procedure WriteMessageBegin( const msg: IMessage); virtual; abstract;
+ procedure WriteMessageEnd; virtual; abstract;
+ procedure WriteStructBegin( const struc: IStruct); virtual; abstract;
+ procedure WriteStructEnd; virtual; abstract;
+ procedure WriteFieldBegin( const field: IField); virtual; abstract;
+ procedure WriteFieldEnd; virtual; abstract;
+ procedure WriteFieldStop; virtual; abstract;
+ procedure WriteMapBegin( const map: IMap); virtual; abstract;
+ procedure WriteMapEnd; virtual; abstract;
+ procedure WriteListBegin( const list: IList); virtual; abstract;
+ procedure WriteListEnd(); virtual; abstract;
+ procedure WriteSetBegin( const set_: ISet ); virtual; abstract;
+ procedure WriteSetEnd(); virtual; abstract;
+ procedure WriteBool( b: Boolean); virtual; abstract;
+ procedure WriteByte( b: ShortInt); virtual; abstract;
+ procedure WriteI16( i16: SmallInt); virtual; abstract;
+ procedure WriteI32( i32: Integer); virtual; abstract;
+ procedure WriteI64( const i64: Int64); virtual; abstract;
+ procedure WriteDouble( const d: Double); virtual; abstract;
+ procedure WriteString( const s: string ); virtual;
+ procedure WriteAnsiString( const s: AnsiString); virtual;
+ procedure WriteBinary( const b: TBytes); virtual; abstract;
+
+ function ReadMessageBegin: IMessage; virtual; abstract;
+ procedure ReadMessageEnd(); virtual; abstract;
+ function ReadStructBegin: IStruct; virtual; abstract;
+ procedure ReadStructEnd; virtual; abstract;
+ function ReadFieldBegin: IField; virtual; abstract;
+ procedure ReadFieldEnd(); virtual; abstract;
+ function ReadMapBegin: IMap; virtual; abstract;
+ procedure ReadMapEnd(); virtual; abstract;
+ function ReadListBegin: IList; virtual; abstract;
+ procedure ReadListEnd(); virtual; abstract;
+ function ReadSetBegin: ISet; virtual; abstract;
+ procedure ReadSetEnd(); virtual; abstract;
+ function ReadBool: Boolean; virtual; abstract;
+ function ReadByte: ShortInt; virtual; abstract;
+ function ReadI16: SmallInt; virtual; abstract;
+ function ReadI32: Integer; virtual; abstract;
+ function ReadI64: Int64; virtual; abstract;
+ function ReadDouble:Double; virtual; abstract;
+ function ReadBinary: TBytes; virtual; abstract;
+ function ReadString: string; virtual;
+ function ReadAnsiString: AnsiString; virtual;
+
+ property Transport: ITransport read GetTransport;
+
+ constructor Create( trans: ITransport );
+ end;
+
+ IBase = interface
+ ['{08D9BAA8-5EAA-410F-B50B-AC2E6E5E4155}']
+ function ToString: string;
+ procedure Read( const iprot: IProtocol);
+ procedure Write( const iprot: IProtocol);
+ end;
+
+ IStruct = interface
+ ['{5DCE39AA-C916-4BC7-A79B-96A0C36B2220}']
+ procedure SetName(const Value: string);
+ function GetName: string;
+ property Name: string read GetName write SetName;
+ end;
+
+ TStructImpl = class( TInterfacedObject, IStruct )
+ private
+ FName: string;
+ protected
+ function GetName: string;
+ procedure SetName(const Value: string);
+ public
+ constructor Create( const AName: string);
+ end;
+
+ TBinaryProtocolImpl = class( TProtocolImpl )
+ protected
+ const
+ VERSION_MASK : Cardinal = $ffff0000;
+ VERSION_1 : Cardinal = $80010000;
+ protected
+ FStrictRead : Boolean;
+ FStrictWrite : Boolean;
+
+ private
+ function ReadAll( var buf: TBytes; off: Integer; len: Integer ): Integer;
+ function ReadStringBody( size: Integer): string;
+
+ public
+
+ type
+ TFactory = class( TInterfacedObject, IProtocolFactory)
+ protected
+ FStrictRead : Boolean;
+ FStrictWrite : Boolean;
+ public
+ function GetProtocol( const trans: ITransport): IProtocol;
+ constructor Create( AStrictRead, AStrictWrite: Boolean ); overload;
+ constructor Create; overload;
+ end;
+
+ constructor Create( const trans: ITransport); overload;
+ constructor Create( const trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload;
+
+ procedure WriteMessageBegin( const msg: IMessage); override;
+ procedure WriteMessageEnd; override;
+ procedure WriteStructBegin( const struc: IStruct); override;
+ procedure WriteStructEnd; override;
+ procedure WriteFieldBegin( const field: IField); override;
+ procedure WriteFieldEnd; override;
+ procedure WriteFieldStop; override;
+ procedure WriteMapBegin( const map: IMap); override;
+ procedure WriteMapEnd; override;
+ procedure WriteListBegin( const list: IList); override;
+ procedure WriteListEnd(); override;
+ procedure WriteSetBegin( const set_: ISet ); override;
+ procedure WriteSetEnd(); override;
+ procedure WriteBool( b: Boolean); override;
+ procedure WriteByte( b: ShortInt); override;
+ procedure WriteI16( i16: SmallInt); override;
+ procedure WriteI32( i32: Integer); override;
+ procedure WriteI64( const i64: Int64); override;
+ procedure WriteDouble( const d: Double); override;
+ procedure WriteBinary( const b: TBytes); override;
+
+ function ReadMessageBegin: IMessage; override;
+ procedure ReadMessageEnd(); override;
+ function ReadStructBegin: IStruct; override;
+ procedure ReadStructEnd; override;
+ function ReadFieldBegin: IField; override;
+ procedure ReadFieldEnd(); override;
+ function ReadMapBegin: IMap; override;
+ procedure ReadMapEnd(); override;
+ function ReadListBegin: IList; override;
+ procedure ReadListEnd(); override;
+ function ReadSetBegin: ISet; override;
+ procedure ReadSetEnd(); override;
+ function ReadBool: Boolean; override;
+ function ReadByte: ShortInt; override;
+ function ReadI16: SmallInt; override;
+ function ReadI32: Integer; override;
+ function ReadI64: Int64; override;
+ function ReadDouble:Double; override;
+ function ReadBinary: TBytes; override;
+
+ end;
+
+
+ { TProtocolDecorator forwards all requests to an enclosed TProtocol instance,
+ providing a way to author concise concrete decorator subclasses. The decorator
+ does not (and should not) modify the behaviour of the enclosed TProtocol
+
+ See p.175 of Design Patterns (by Gamma et al.)
+ }
+ TProtocolDecorator = class( TProtocolImpl)
+ private
+ FWrappedProtocol : IProtocol;
+
+ public
+ // Encloses the specified protocol.
+ // All operations will be forward to the given protocol. Must be non-null.
+ constructor Create( const aProtocol : IProtocol);
+
+ procedure WriteMessageBegin( const msg: IMessage); override;
+ procedure WriteMessageEnd; override;
+ procedure WriteStructBegin( const struc: IStruct); override;
+ procedure WriteStructEnd; override;
+ procedure WriteFieldBegin( const field: IField); override;
+ procedure WriteFieldEnd; override;
+ procedure WriteFieldStop; override;
+ procedure WriteMapBegin( const map: IMap); override;
+ procedure WriteMapEnd; override;
+ procedure WriteListBegin( const list: IList); override;
+ procedure WriteListEnd(); override;
+ procedure WriteSetBegin( const set_: ISet ); override;
+ procedure WriteSetEnd(); override;
+ procedure WriteBool( b: Boolean); override;
+ procedure WriteByte( b: ShortInt); override;
+ procedure WriteI16( i16: SmallInt); override;
+ procedure WriteI32( i32: Integer); override;
+ procedure WriteI64( const i64: Int64); override;
+ procedure WriteDouble( const d: Double); override;
+ procedure WriteString( const s: string ); override;
+ procedure WriteAnsiString( const s: AnsiString); override;
+ procedure WriteBinary( const b: TBytes); override;
+
+ function ReadMessageBegin: IMessage; override;
+ procedure ReadMessageEnd(); override;
+ function ReadStructBegin: IStruct; override;
+ procedure ReadStructEnd; override;
+ function ReadFieldBegin: IField; override;
+ procedure ReadFieldEnd(); override;
+ function ReadMapBegin: IMap; override;
+ procedure ReadMapEnd(); override;
+ function ReadListBegin: IList; override;
+ procedure ReadListEnd(); override;
+ function ReadSetBegin: ISet; override;
+ procedure ReadSetEnd(); override;
+ function ReadBool: Boolean; override;
+ function ReadByte: ShortInt; override;
+ function ReadI16: SmallInt; override;
+ function ReadI32: Integer; override;
+ function ReadI64: Int64; override;
+ function ReadDouble:Double; override;
+ function ReadBinary: TBytes; override;
+ function ReadString: string; override;
+ function ReadAnsiString: AnsiString; override;
+ end;
+
+
+type
+ IRequestEvents = interface
['{F926A26A-5B00-4560-86FA-2CAE3BA73DAF}']
// Called before reading arguments.
procedure PreRead;
@@ -534,1052 +534,1052 @@
function Process( const iprot :IProtocol; const oprot: IProtocol; const events : IProcessorEvents = nil): Boolean;
end;
-
-
-implementation
-
-function ConvertInt64ToDouble( const n: Int64): Double;
-begin
- ASSERT( SizeOf(n) = SizeOf(Result));
- System.Move( n, Result, SizeOf(Result));
-end;
-
-function ConvertDoubleToInt64( const d: Double): Int64;
-begin
- ASSERT( SizeOf(d) = SizeOf(Result));
- System.Move( d, Result, SizeOf(Result));
-end;
-
-{ TFieldImpl }
-
-constructor TFieldImpl.Create(const AName: string; const AType: TType;
- AId: SmallInt);
-begin
- inherited Create;
- FName := AName;
- FType := AType;
- FId := AId;
-end;
-
-constructor TFieldImpl.Create;
-begin
- inherited Create;
- FName := '';
- FType := Low(TType);
- FId := 0;
-end;
-
-function TFieldImpl.GetId: SmallInt;
-begin
- Result := FId;
-end;
-
-function TFieldImpl.GetName: string;
-begin
- Result := FName;
-end;
-
-function TFieldImpl.GetType: TType;
-begin
- Result := FType;
-end;
-
-procedure TFieldImpl.SetId(Value: SmallInt);
-begin
- FId := Value;
-end;
-
-procedure TFieldImpl.SetName(const Value: string);
-begin
- FName := Value;
-end;
-
-procedure TFieldImpl.SetType(Value: TType);
-begin
- FType := Value;
-end;
-
-{ TProtocolImpl }
-
-constructor TProtocolImpl.Create(trans: ITransport);
-begin
- inherited Create;
- FTrans := trans;
-end;
-
-function TProtocolImpl.GetTransport: ITransport;
-begin
- Result := FTrans;
-end;
-
-function TProtocolImpl.ReadAnsiString: AnsiString;
-var
- b : TBytes;
- len : Integer;
-begin
- Result := '';
- b := ReadBinary;
- len := Length( b );
- if len > 0 then
- begin
- SetLength( Result, len);
- System.Move( b[0], Pointer(Result)^, len );
- end;
-end;
-
-function TProtocolImpl.ReadString: string;
-begin
- Result := TEncoding.UTF8.GetString( ReadBinary );
-end;
-
-procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
-var
- b : TBytes;
- len : Integer;
-begin
- len := Length(s);
- SetLength( b, len);
- if len > 0 then
- begin
- System.Move( Pointer(s)^, b[0], len );
- end;
- WriteBinary( b );
-end;
-
-procedure TProtocolImpl.WriteString(const s: string);
-var
- b : TBytes;
-begin
- b := TEncoding.UTF8.GetBytes(s);
- WriteBinary( b );
-end;
-
-{ TProtocolUtil }
-
-class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
-var field : IField;
- map : IMap;
- set_ : ISet;
- list : IList;
- i : Integer;
-begin
- case type_ of
- // simple types
- TType.Bool_ : prot.ReadBool();
- TType.Byte_ : prot.ReadByte();
- TType.I16 : prot.ReadI16();
- TType.I32 : prot.ReadI32();
- TType.I64 : prot.ReadI64();
- TType.Double_ : prot.ReadDouble();
- TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it.
-
- // structured types
- TType.Struct : begin
- prot.ReadStructBegin();
- while TRUE do begin
- field := prot.ReadFieldBegin();
- if (field.Type_ = TType.Stop) then Break;
- Skip(prot, field.Type_);
- prot.ReadFieldEnd();
- end;
- prot.ReadStructEnd();
- end;
-
- TType.Map : begin
- map := prot.ReadMapBegin();
- for i := 0 to map.Count-1 do begin
- Skip(prot, map.KeyType);
- Skip(prot, map.ValueType);
- end;
- prot.ReadMapEnd();
- end;
-
- TType.Set_ : begin
- set_ := prot.ReadSetBegin();
- for i := 0 to set_.Count-1
- do Skip( prot, set_.ElementType);
- prot.ReadSetEnd();
- end;
-
- TType.List : begin
- list := prot.ReadListBegin();
- for i := 0 to list.Count-1
- do Skip( prot, list.ElementType);
- prot.ReadListEnd();
- end;
-
- else
- ASSERT( FALSE); // any new types?
- end;
-end;
-
-{ TStructImpl }
-
-constructor TStructImpl.Create(const AName: string);
-begin
- inherited Create;
- FName := AName;
-end;
-
-function TStructImpl.GetName: string;
-begin
- Result := FName;
-end;
-
-procedure TStructImpl.SetName(const Value: string);
-begin
- FName := Value;
-end;
-
-{ TMapImpl }
-
-constructor TMapImpl.Create(AValueType, AKeyType: TType; ACount: Integer);
-begin
- inherited Create;
- FValueType := AValueType;
- FKeyType := AKeyType;
- FCount := ACount;
-end;
-
-constructor TMapImpl.Create;
-begin
- inherited Create;
-end;
-
-function TMapImpl.GetCount: Integer;
-begin
- Result := FCount;
-end;
-
-function TMapImpl.GetKeyType: TType;
-begin
- Result := FKeyType;
-end;
-
-function TMapImpl.GetValueType: TType;
-begin
- Result := FValueType;
-end;
-
-procedure TMapImpl.SetCount(Value: Integer);
-begin
- FCount := Value;
-end;
-
-procedure TMapImpl.SetKeyType(Value: TType);
-begin
- FKeyType := Value;
-end;
-
-procedure TMapImpl.SetValueType(Value: TType);
-begin
- FValueType := Value;
-end;
-
-{ IMessage }
-
-constructor TMessageImpl.Create(AName: string; AMessageType: TMessageType;
- ASeqID: Integer);
-begin
- inherited Create;
- FName := AName;
- FMessageType := AMessageType;
- FSeqID := ASeqID;
-end;
-
-constructor TMessageImpl.Create;
-begin
- inherited;
-end;
-
-function TMessageImpl.GetName: string;
-begin
- Result := FName;
-end;
-
-function TMessageImpl.GetSeqID: Integer;
-begin
- Result := FSeqID;
-end;
-
-function TMessageImpl.GetType: TMessageType;
-begin
- Result := FMessageType;
-end;
-
-procedure TMessageImpl.SetName(const Value: string);
-begin
- FName := Value;
-end;
-
-procedure TMessageImpl.SetSeqID(Value: Integer);
-begin
- FSeqID := Value;
-end;
-
-procedure TMessageImpl.SetType(Value: TMessageType);
-begin
- FMessageType := Value;
-end;
-
-{ ISet }
-
-constructor TSetImpl.Create( AElementType: TType; ACount: Integer);
-begin
- inherited Create;
- FCount := ACount;
- FElementType := AElementType;
-end;
-
-constructor TSetImpl.Create;
-begin
- inherited Create;
-end;
-
-function TSetImpl.GetCount: Integer;
-begin
- Result := FCount;
-end;
-
-function TSetImpl.GetElementType: TType;
-begin
- Result := FElementType;
-end;
-
-procedure TSetImpl.SetCount(Value: Integer);
-begin
- FCount := Value;
-end;
-
-procedure TSetImpl.SetElementType(Value: TType);
-begin
- FElementType := Value;
-end;
-
-{ IList }
-
-constructor TListImpl.Create( AElementType: TType; ACount: Integer);
-begin
- inherited Create;
- FCount := ACount;
- FElementType := AElementType;
-end;
-
-constructor TListImpl.Create;
-begin
- inherited Create;
-end;
-
-function TListImpl.GetCount: Integer;
-begin
- Result := FCount;
-end;
-
-function TListImpl.GetElementType: TType;
-begin
- Result := FElementType;
-end;
-
-procedure TListImpl.SetCount(Value: Integer);
-begin
- FCount := Value;
-end;
-
-procedure TListImpl.SetElementType(Value: TType);
-begin
- FElementType := Value;
-end;
-
-{ TBinaryProtocolImpl }
-
-constructor TBinaryProtocolImpl.Create( const trans: ITransport);
-begin
- //no inherited
- Create( trans, False, True);
-end;
-
-constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
- strictWrite: Boolean);
-begin
- inherited Create( trans );
- FStrictRead := strictRead;
- FStrictWrite := strictWrite;
-end;
-
-function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
- len: Integer): Integer;
-begin
- Result := FTrans.ReadAll( buf, off, len );
-end;
-
-function TBinaryProtocolImpl.ReadBinary: TBytes;
-var
- size : Integer;
- buf : TBytes;
-begin
- size := ReadI32;
- SetLength( buf, size );
- FTrans.ReadAll( buf, 0, size);
- Result := buf;
-end;
-
-function TBinaryProtocolImpl.ReadBool: Boolean;
-begin
- Result := ReadByte = 1;
-end;
-
-function TBinaryProtocolImpl.ReadByte: ShortInt;
-var
- bin : TBytes;
-begin
- SetLength( bin, 1);
- ReadAll( bin, 0, 1 );
- Result := ShortInt( bin[0]);
-end;
-
-function TBinaryProtocolImpl.ReadDouble: Double;
-begin
- Result := ConvertInt64ToDouble( ReadI64 )
-end;
-
-function TBinaryProtocolImpl.ReadFieldBegin: IField;
-var
- field : IField;
-begin
- field := TFieldImpl.Create;
- field.Type_ := TType( ReadByte);
- if ( field.Type_ <> TType.Stop ) then
- begin
- field.Id := ReadI16;
- end;
- Result := field;
-end;
-
-procedure TBinaryProtocolImpl.ReadFieldEnd;
-begin
-
-end;
-
-function TBinaryProtocolImpl.ReadI16: SmallInt;
-var
- i16in : TBytes;
-begin
- SetLength( i16in, 2 );
- ReadAll( i16in, 0, 2);
- Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
-end;
-
-function TBinaryProtocolImpl.ReadI32: Integer;
-var
- i32in : TBytes;
-begin
- SetLength( i32in, 4 );
- ReadAll( i32in, 0, 4);
-
- Result := Integer(
- ((i32in[0] and $FF) shl 24) or
- ((i32in[1] and $FF) shl 16) or
- ((i32in[2] and $FF) shl 8) or
- (i32in[3] and $FF));
-
-end;
-
-function TBinaryProtocolImpl.ReadI64: Int64;
-var
- i64in : TBytes;
-begin
- SetLength( i64in, 8);
- ReadAll( i64in, 0, 8);
- Result :=
- (Int64( i64in[0] and $FF) shl 56) or
- (Int64( i64in[1] and $FF) shl 48) or
- (Int64( i64in[2] and $FF) shl 40) or
- (Int64( i64in[3] and $FF) shl 32) or
- (Int64( i64in[4] and $FF) shl 24) or
- (Int64( i64in[5] and $FF) shl 16) or
- (Int64( i64in[6] and $FF) shl 8) or
- (Int64( i64in[7] and $FF));
-end;
-
-function TBinaryProtocolImpl.ReadListBegin: IList;
-var
- list : IList;
-begin
- list := TListImpl.Create;
- list.ElementType := TType( ReadByte );
- list.Count := ReadI32;
- Result := list;
-end;
-
-procedure TBinaryProtocolImpl.ReadListEnd;
-begin
-
-end;
-
-function TBinaryProtocolImpl.ReadMapBegin: IMap;
-var
- map : IMap;
-begin
- map := TMapImpl.Create;
- map.KeyType := TType( ReadByte );
- map.ValueType := TType( ReadByte );
- map.Count := ReadI32;
- Result := map;
-end;
-
-procedure TBinaryProtocolImpl.ReadMapEnd;
-begin
-
-end;
-
-function TBinaryProtocolImpl.ReadMessageBegin: IMessage;
-var
- size : Integer;
- version : Integer;
- message : IMessage;
-begin
- message := TMessageImpl.Create;
- size := ReadI32;
- if (size < 0) then
- begin
- version := size and Integer( VERSION_MASK);
- if ( version <> Integer( VERSION_1)) then
- begin
- raise TProtocolException.Create(TProtocolException.BAD_VERSION, 'Bad version in ReadMessageBegin: ' + IntToStr(version) );
- end;
- message.Type_ := TMessageType( size and $000000ff);
- message.Name := ReadString;
- message.SeqID := ReadI32;
- end else
- begin
- if FStrictRead then
- begin
- raise TProtocolException.Create( TProtocolException.BAD_VERSION, 'Missing version in readMessageBegin, old client?' );
- end;
- message.Name := ReadStringBody( size );
- message.Type_ := TMessageType( ReadByte );
- message.SeqID := ReadI32;
- end;
- Result := message;
-end;
-
-procedure TBinaryProtocolImpl.ReadMessageEnd;
-begin
- inherited;
-
-end;
-
-function TBinaryProtocolImpl.ReadSetBegin: ISet;
-var
- set_ : ISet;
-begin
- set_ := TSetImpl.Create;
- set_.ElementType := TType( ReadByte );
- set_.Count := ReadI32;
- Result := set_;
-end;
-
-procedure TBinaryProtocolImpl.ReadSetEnd;
-begin
-
-end;
-
-function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
-var
- buf : TBytes;
-begin
- SetLength( buf, size );
- FTrans.ReadAll( buf, 0, size );
- Result := TEncoding.UTF8.GetString( buf);
-end;
-
-function TBinaryProtocolImpl.ReadStructBegin: IStruct;
-begin
- Result := TStructImpl.Create('');
-end;
-
-procedure TBinaryProtocolImpl.ReadStructEnd;
-begin
- inherited;
-
-end;
-
-procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
-var iLen : Integer;
-begin
- iLen := Length(b);
- WriteI32( iLen);
- if iLen > 0 then FTrans.Write(b, 0, iLen);
-end;
-
-procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
-begin
- if b then
- begin
- WriteByte( 1 );
- end else
- begin
- WriteByte( 0 );
- end;
-end;
-
-procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
-var
- a : TBytes;
-begin
- SetLength( a, 1);
- a[0] := Byte( b );
- FTrans.Write( a, 0, 1 );
-end;
-
-procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
-begin
- WriteI64(ConvertDoubleToInt64(d));
-end;
-
-procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
-begin
- WriteByte(ShortInt(field.Type_));
- WriteI16(field.ID);
-end;
-
-procedure TBinaryProtocolImpl.WriteFieldEnd;
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteFieldStop;
-begin
- WriteByte(ShortInt(TType.Stop));
-end;
-
-procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
-var
- i16out : TBytes;
-begin
- SetLength( i16out, 2);
- i16out[0] := Byte($FF and (i16 shr 8));
- i16out[1] := Byte($FF and i16);
- FTrans.Write( i16out );
-end;
-
-procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
-var
- i32out : TBytes;
-begin
- SetLength( i32out, 4);
- i32out[0] := Byte($FF and (i32 shr 24));
- i32out[1] := Byte($FF and (i32 shr 16));
- i32out[2] := Byte($FF and (i32 shr 8));
- i32out[3] := Byte($FF and i32);
- FTrans.Write( i32out, 0, 4);
-end;
-
-procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
-var
- i64out : TBytes;
-begin
- SetLength( i64out, 8);
- i64out[0] := Byte($FF and (i64 shr 56));
- i64out[1] := Byte($FF and (i64 shr 48));
- i64out[2] := Byte($FF and (i64 shr 40));
- i64out[3] := Byte($FF and (i64 shr 32));
- i64out[4] := Byte($FF and (i64 shr 24));
- i64out[5] := Byte($FF and (i64 shr 16));
- i64out[6] := Byte($FF and (i64 shr 8));
- i64out[7] := Byte($FF and i64);
- FTrans.Write( i64out, 0, 8);
-end;
-
-procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
-begin
- WriteByte(ShortInt(list.ElementType));
- WriteI32(list.Count);
-end;
-
-procedure TBinaryProtocolImpl.WriteListEnd;
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
-begin
- WriteByte(ShortInt(map.KeyType));
- WriteByte(ShortInt(map.ValueType));
- WriteI32(map.Count);
-end;
-
-procedure TBinaryProtocolImpl.WriteMapEnd;
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
-var
- version : Cardinal;
-begin
- if FStrictWrite then
- begin
- version := VERSION_1 or Cardinal( msg.Type_);
- WriteI32( Integer( version) );
- WriteString( msg.Name);
- WriteI32( msg.SeqID);
- end else
- begin
- WriteString( msg.Name);
- WriteByte(ShortInt( msg.Type_));
- WriteI32( msg.SeqID);
- end;
-end;
-
-procedure TBinaryProtocolImpl.WriteMessageEnd;
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
-begin
- WriteByte(ShortInt(set_.ElementType));
- WriteI32(set_.Count);
-end;
-
-procedure TBinaryProtocolImpl.WriteSetEnd;
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
-begin
-
-end;
-
-procedure TBinaryProtocolImpl.WriteStructEnd;
-begin
-
-end;
-
-{ TProtocolException }
-
-constructor TProtocolException.Create;
-begin
- inherited Create('');
- FType := UNKNOWN;
-end;
-
-constructor TProtocolException.Create(type_: Integer);
-begin
- inherited Create('');
- FType := type_;
-end;
-
-constructor TProtocolException.Create(type_: Integer; const msg: string);
-begin
- inherited Create( msg );
- FType := type_;
-end;
-
-{ TThriftStringBuilder }
-
-function TThriftStringBuilder.Append(const Value: TBytes): TStringBuilder;
-begin
- Result := Append( string( RawByteString(Value)) );
-end;
-
-function TThriftStringBuilder.Append(
- const Value: IThriftContainer): TStringBuilder;
-begin
- Result := Append( Value.ToString );
-end;
-
-{ TBinaryProtocolImpl.TFactory }
-
-constructor TBinaryProtocolImpl.TFactory.Create(AStrictRead, AStrictWrite: Boolean);
-begin
- inherited Create;
- FStrictRead := AStrictRead;
- FStrictWrite := AStrictWrite;
-end;
-
-constructor TBinaryProtocolImpl.TFactory.Create;
-begin
- //no inherited;
- Create( False, True )
-end;
-
-function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
-begin
- Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
-end;
-
-
-{ TProtocolDecorator }
-
-constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
-begin
- ASSERT( aProtocol <> nil);
- inherited Create( aProtocol.Transport);
- FWrappedProtocol := aProtocol;
-end;
-
-
-procedure TProtocolDecorator.WriteMessageBegin( const msg: IMessage);
-begin
- FWrappedProtocol.WriteMessageBegin( msg);
-end;
-
-
-procedure TProtocolDecorator.WriteMessageEnd;
-begin
- FWrappedProtocol.WriteMessageEnd;
-end;
-
-
-procedure TProtocolDecorator.WriteStructBegin( const struc: IStruct);
-begin
- FWrappedProtocol.WriteStructBegin( struc);
-end;
-
-
-procedure TProtocolDecorator.WriteStructEnd;
-begin
- FWrappedProtocol.WriteStructEnd;
-end;
-
-
-procedure TProtocolDecorator.WriteFieldBegin( const field: IField);
-begin
- FWrappedProtocol.WriteFieldBegin( field);
-end;
-
-
-procedure TProtocolDecorator.WriteFieldEnd;
-begin
- FWrappedProtocol.WriteFieldEnd;
-end;
-
-
-procedure TProtocolDecorator.WriteFieldStop;
-begin
- FWrappedProtocol.WriteFieldStop;
-end;
-
-
-procedure TProtocolDecorator.WriteMapBegin( const map: IMap);
-begin
- FWrappedProtocol.WriteMapBegin( map);
-end;
-
-
-procedure TProtocolDecorator.WriteMapEnd;
-begin
- FWrappedProtocol.WriteMapEnd;
-end;
-
-
-procedure TProtocolDecorator.WriteListBegin( const list: IList);
-begin
- FWrappedProtocol.WriteListBegin( list);
-end;
-
-
-procedure TProtocolDecorator.WriteListEnd();
-begin
- FWrappedProtocol.WriteListEnd();
-end;
-
-
-procedure TProtocolDecorator.WriteSetBegin( const set_: ISet );
-begin
- FWrappedProtocol.WriteSetBegin( set_);
-end;
-
-
-procedure TProtocolDecorator.WriteSetEnd();
-begin
- FWrappedProtocol.WriteSetEnd();
-end;
-
-
-procedure TProtocolDecorator.WriteBool( b: Boolean);
-begin
- FWrappedProtocol.WriteBool( b);
-end;
-
-
-procedure TProtocolDecorator.WriteByte( b: ShortInt);
-begin
- FWrappedProtocol.WriteByte( b);
-end;
-
-
-procedure TProtocolDecorator.WriteI16( i16: SmallInt);
-begin
- FWrappedProtocol.WriteI16( i16);
-end;
-
-
-procedure TProtocolDecorator.WriteI32( i32: Integer);
-begin
- FWrappedProtocol.WriteI32( i32);
-end;
-
-
-procedure TProtocolDecorator.WriteI64( const i64: Int64);
-begin
- FWrappedProtocol.WriteI64( i64);
-end;
-
-
-procedure TProtocolDecorator.WriteDouble( const d: Double);
-begin
- FWrappedProtocol.WriteDouble( d);
-end;
-
-
-procedure TProtocolDecorator.WriteString( const s: string );
-begin
- FWrappedProtocol.WriteString( s);
-end;
-
-
-procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
-begin
- FWrappedProtocol.WriteAnsiString( s);
-end;
-
-
-procedure TProtocolDecorator.WriteBinary( const b: TBytes);
-begin
- FWrappedProtocol.WriteBinary( b);
-end;
-
-
-function TProtocolDecorator.ReadMessageBegin: IMessage;
-begin
- result := FWrappedProtocol.ReadMessageBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadMessageEnd();
-begin
- FWrappedProtocol.ReadMessageEnd();
-end;
-
-
-function TProtocolDecorator.ReadStructBegin: IStruct;
-begin
- result := FWrappedProtocol.ReadStructBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadStructEnd;
-begin
- FWrappedProtocol.ReadStructEnd;
-end;
-
-
-function TProtocolDecorator.ReadFieldBegin: IField;
-begin
- result := FWrappedProtocol.ReadFieldBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadFieldEnd();
-begin
- FWrappedProtocol.ReadFieldEnd();
-end;
-
-
-function TProtocolDecorator.ReadMapBegin: IMap;
-begin
- result := FWrappedProtocol.ReadMapBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadMapEnd();
-begin
- FWrappedProtocol.ReadMapEnd();
-end;
-
-
-function TProtocolDecorator.ReadListBegin: IList;
-begin
- result := FWrappedProtocol.ReadListBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadListEnd();
-begin
- FWrappedProtocol.ReadListEnd();
-end;
-
-
-function TProtocolDecorator.ReadSetBegin: ISet;
-begin
- result := FWrappedProtocol.ReadSetBegin;
-end;
-
-
-procedure TProtocolDecorator.ReadSetEnd();
-begin
- FWrappedProtocol.ReadSetEnd();
-end;
-
-
-function TProtocolDecorator.ReadBool: Boolean;
-begin
- result := FWrappedProtocol.ReadBool;
-end;
-
-
-function TProtocolDecorator.ReadByte: ShortInt;
-begin
- result := FWrappedProtocol.ReadByte;
-end;
-
-
-function TProtocolDecorator.ReadI16: SmallInt;
-begin
- result := FWrappedProtocol.ReadI16;
-end;
-
-
-function TProtocolDecorator.ReadI32: Integer;
-begin
- result := FWrappedProtocol.ReadI32;
-end;
-
-
-function TProtocolDecorator.ReadI64: Int64;
-begin
- result := FWrappedProtocol.ReadI64;
-end;
-
-
-function TProtocolDecorator.ReadDouble:Double;
-begin
- result := FWrappedProtocol.ReadDouble;
-end;
-
-
-function TProtocolDecorator.ReadBinary: TBytes;
-begin
- result := FWrappedProtocol.ReadBinary;
-end;
-
-
-function TProtocolDecorator.ReadString: string;
-begin
- result := FWrappedProtocol.ReadString;
-end;
-
-
-function TProtocolDecorator.ReadAnsiString: AnsiString;
-begin
- result := FWrappedProtocol.ReadAnsiString;
-end;
-
-
-
-end.
-
+
+
+implementation
+
+function ConvertInt64ToDouble( const n: Int64): Double;
+begin
+ ASSERT( SizeOf(n) = SizeOf(Result));
+ System.Move( n, Result, SizeOf(Result));
+end;
+
+function ConvertDoubleToInt64( const d: Double): Int64;
+begin
+ ASSERT( SizeOf(d) = SizeOf(Result));
+ System.Move( d, Result, SizeOf(Result));
+end;
+
+{ TFieldImpl }
+
+constructor TFieldImpl.Create(const AName: string; const AType: TType;
+ AId: SmallInt);
+begin
+ inherited Create;
+ FName := AName;
+ FType := AType;
+ FId := AId;
+end;
+
+constructor TFieldImpl.Create;
+begin
+ inherited Create;
+ FName := '';
+ FType := Low(TType);
+ FId := 0;
+end;
+
+function TFieldImpl.GetId: SmallInt;
+begin
+ Result := FId;
+end;
+
+function TFieldImpl.GetName: string;
+begin
+ Result := FName;
+end;
+
+function TFieldImpl.GetType: TType;
+begin
+ Result := FType;
+end;
+
+procedure TFieldImpl.SetId(Value: SmallInt);
+begin
+ FId := Value;
+end;
+
+procedure TFieldImpl.SetName(const Value: string);
+begin
+ FName := Value;
+end;
+
+procedure TFieldImpl.SetType(Value: TType);
+begin
+ FType := Value;
+end;
+
+{ TProtocolImpl }
+
+constructor TProtocolImpl.Create(trans: ITransport);
+begin
+ inherited Create;
+ FTrans := trans;
+end;
+
+function TProtocolImpl.GetTransport: ITransport;
+begin
+ Result := FTrans;
+end;
+
+function TProtocolImpl.ReadAnsiString: AnsiString;
+var
+ b : TBytes;
+ len : Integer;
+begin
+ Result := '';
+ b := ReadBinary;
+ len := Length( b );
+ if len > 0 then
+ begin
+ SetLength( Result, len);
+ System.Move( b[0], Pointer(Result)^, len );
+ end;
+end;
+
+function TProtocolImpl.ReadString: string;
+begin
+ Result := TEncoding.UTF8.GetString( ReadBinary );
+end;
+
+procedure TProtocolImpl.WriteAnsiString(const s: AnsiString);
+var
+ b : TBytes;
+ len : Integer;
+begin
+ len := Length(s);
+ SetLength( b, len);
+ if len > 0 then
+ begin
+ System.Move( Pointer(s)^, b[0], len );
+ end;
+ WriteBinary( b );
+end;
+
+procedure TProtocolImpl.WriteString(const s: string);
+var
+ b : TBytes;
+begin
+ b := TEncoding.UTF8.GetBytes(s);
+ WriteBinary( b );
+end;
+
+{ TProtocolUtil }
+
+class procedure TProtocolUtil.Skip( prot: IProtocol; type_: TType);
+var field : IField;
+ map : IMap;
+ set_ : ISet;
+ list : IList;
+ i : Integer;
+begin
+ case type_ of
+ // simple types
+ TType.Bool_ : prot.ReadBool();
+ TType.Byte_ : prot.ReadByte();
+ TType.I16 : prot.ReadI16();
+ TType.I32 : prot.ReadI32();
+ TType.I64 : prot.ReadI64();
+ TType.Double_ : prot.ReadDouble();
+ TType.String_ : prot.ReadBinary();// Don't try to decode the string, just skip it.
+
+ // structured types
+ TType.Struct : begin
+ prot.ReadStructBegin();
+ while TRUE do begin
+ field := prot.ReadFieldBegin();
+ if (field.Type_ = TType.Stop) then Break;
+ Skip(prot, field.Type_);
+ prot.ReadFieldEnd();
+ end;
+ prot.ReadStructEnd();
+ end;
+
+ TType.Map : begin
+ map := prot.ReadMapBegin();
+ for i := 0 to map.Count-1 do begin
+ Skip(prot, map.KeyType);
+ Skip(prot, map.ValueType);
+ end;
+ prot.ReadMapEnd();
+ end;
+
+ TType.Set_ : begin
+ set_ := prot.ReadSetBegin();
+ for i := 0 to set_.Count-1
+ do Skip( prot, set_.ElementType);
+ prot.ReadSetEnd();
+ end;
+
+ TType.List : begin
+ list := prot.ReadListBegin();
+ for i := 0 to list.Count-1
+ do Skip( prot, list.ElementType);
+ prot.ReadListEnd();
+ end;
+
+ else
+ ASSERT( FALSE); // any new types?
+ end;
+end;
+
+{ TStructImpl }
+
+constructor TStructImpl.Create(const AName: string);
+begin
+ inherited Create;
+ FName := AName;
+end;
+
+function TStructImpl.GetName: string;
+begin
+ Result := FName;
+end;
+
+procedure TStructImpl.SetName(const Value: string);
+begin
+ FName := Value;
+end;
+
+{ TMapImpl }
+
+constructor TMapImpl.Create(AValueType, AKeyType: TType; ACount: Integer);
+begin
+ inherited Create;
+ FValueType := AValueType;
+ FKeyType := AKeyType;
+ FCount := ACount;
+end;
+
+constructor TMapImpl.Create;
+begin
+ inherited Create;
+end;
+
+function TMapImpl.GetCount: Integer;
+begin
+ Result := FCount;
+end;
+
+function TMapImpl.GetKeyType: TType;
+begin
+ Result := FKeyType;
+end;
+
+function TMapImpl.GetValueType: TType;
+begin
+ Result := FValueType;
+end;
+
+procedure TMapImpl.SetCount(Value: Integer);
+begin
+ FCount := Value;
+end;
+
+procedure TMapImpl.SetKeyType(Value: TType);
+begin
+ FKeyType := Value;
+end;
+
+procedure TMapImpl.SetValueType(Value: TType);
+begin
+ FValueType := Value;
+end;
+
+{ IMessage }
+
+constructor TMessageImpl.Create(AName: string; AMessageType: TMessageType;
+ ASeqID: Integer);
+begin
+ inherited Create;
+ FName := AName;
+ FMessageType := AMessageType;
+ FSeqID := ASeqID;
+end;
+
+constructor TMessageImpl.Create;
+begin
+ inherited;
+end;
+
+function TMessageImpl.GetName: string;
+begin
+ Result := FName;
+end;
+
+function TMessageImpl.GetSeqID: Integer;
+begin
+ Result := FSeqID;
+end;
+
+function TMessageImpl.GetType: TMessageType;
+begin
+ Result := FMessageType;
+end;
+
+procedure TMessageImpl.SetName(const Value: string);
+begin
+ FName := Value;
+end;
+
+procedure TMessageImpl.SetSeqID(Value: Integer);
+begin
+ FSeqID := Value;
+end;
+
+procedure TMessageImpl.SetType(Value: TMessageType);
+begin
+ FMessageType := Value;
+end;
+
+{ ISet }
+
+constructor TSetImpl.Create( AElementType: TType; ACount: Integer);
+begin
+ inherited Create;
+ FCount := ACount;
+ FElementType := AElementType;
+end;
+
+constructor TSetImpl.Create;
+begin
+ inherited Create;
+end;
+
+function TSetImpl.GetCount: Integer;
+begin
+ Result := FCount;
+end;
+
+function TSetImpl.GetElementType: TType;
+begin
+ Result := FElementType;
+end;
+
+procedure TSetImpl.SetCount(Value: Integer);
+begin
+ FCount := Value;
+end;
+
+procedure TSetImpl.SetElementType(Value: TType);
+begin
+ FElementType := Value;
+end;
+
+{ IList }
+
+constructor TListImpl.Create( AElementType: TType; ACount: Integer);
+begin
+ inherited Create;
+ FCount := ACount;
+ FElementType := AElementType;
+end;
+
+constructor TListImpl.Create;
+begin
+ inherited Create;
+end;
+
+function TListImpl.GetCount: Integer;
+begin
+ Result := FCount;
+end;
+
+function TListImpl.GetElementType: TType;
+begin
+ Result := FElementType;
+end;
+
+procedure TListImpl.SetCount(Value: Integer);
+begin
+ FCount := Value;
+end;
+
+procedure TListImpl.SetElementType(Value: TType);
+begin
+ FElementType := Value;
+end;
+
+{ TBinaryProtocolImpl }
+
+constructor TBinaryProtocolImpl.Create( const trans: ITransport);
+begin
+ //no inherited
+ Create( trans, False, True);
+end;
+
+constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
+ strictWrite: Boolean);
+begin
+ inherited Create( trans );
+ FStrictRead := strictRead;
+ FStrictWrite := strictWrite;
+end;
+
+function TBinaryProtocolImpl.ReadAll( var buf: TBytes; off,
+ len: Integer): Integer;
+begin
+ Result := FTrans.ReadAll( buf, off, len );
+end;
+
+function TBinaryProtocolImpl.ReadBinary: TBytes;
+var
+ size : Integer;
+ buf : TBytes;
+begin
+ size := ReadI32;
+ SetLength( buf, size );
+ FTrans.ReadAll( buf, 0, size);
+ Result := buf;
+end;
+
+function TBinaryProtocolImpl.ReadBool: Boolean;
+begin
+ Result := ReadByte = 1;
+end;
+
+function TBinaryProtocolImpl.ReadByte: ShortInt;
+var
+ bin : TBytes;
+begin
+ SetLength( bin, 1);
+ ReadAll( bin, 0, 1 );
+ Result := ShortInt( bin[0]);
+end;
+
+function TBinaryProtocolImpl.ReadDouble: Double;
+begin
+ Result := ConvertInt64ToDouble( ReadI64 )
+end;
+
+function TBinaryProtocolImpl.ReadFieldBegin: IField;
+var
+ field : IField;
+begin
+ field := TFieldImpl.Create;
+ field.Type_ := TType( ReadByte);
+ if ( field.Type_ <> TType.Stop ) then
+ begin
+ field.Id := ReadI16;
+ end;
+ Result := field;
+end;
+
+procedure TBinaryProtocolImpl.ReadFieldEnd;
+begin
+
+end;
+
+function TBinaryProtocolImpl.ReadI16: SmallInt;
+var
+ i16in : TBytes;
+begin
+ SetLength( i16in, 2 );
+ ReadAll( i16in, 0, 2);
+ Result := SmallInt(((i16in[0] and $FF) shl 8) or (i16in[1] and $FF));
+end;
+
+function TBinaryProtocolImpl.ReadI32: Integer;
+var
+ i32in : TBytes;
+begin
+ SetLength( i32in, 4 );
+ ReadAll( i32in, 0, 4);
+
+ Result := Integer(
+ ((i32in[0] and $FF) shl 24) or
+ ((i32in[1] and $FF) shl 16) or
+ ((i32in[2] and $FF) shl 8) or
+ (i32in[3] and $FF));
+
+end;
+
+function TBinaryProtocolImpl.ReadI64: Int64;
+var
+ i64in : TBytes;
+begin
+ SetLength( i64in, 8);
+ ReadAll( i64in, 0, 8);
+ Result :=
+ (Int64( i64in[0] and $FF) shl 56) or
+ (Int64( i64in[1] and $FF) shl 48) or
+ (Int64( i64in[2] and $FF) shl 40) or
+ (Int64( i64in[3] and $FF) shl 32) or
+ (Int64( i64in[4] and $FF) shl 24) or
+ (Int64( i64in[5] and $FF) shl 16) or
+ (Int64( i64in[6] and $FF) shl 8) or
+ (Int64( i64in[7] and $FF));
+end;
+
+function TBinaryProtocolImpl.ReadListBegin: IList;
+var
+ list : IList;
+begin
+ list := TListImpl.Create;
+ list.ElementType := TType( ReadByte );
+ list.Count := ReadI32;
+ Result := list;
+end;
+
+procedure TBinaryProtocolImpl.ReadListEnd;
+begin
+
+end;
+
+function TBinaryProtocolImpl.ReadMapBegin: IMap;
+var
+ map : IMap;
+begin
+ map := TMapImpl.Create;
+ map.KeyType := TType( ReadByte );
+ map.ValueType := TType( ReadByte );
+ map.Count := ReadI32;
+ Result := map;
+end;
+
+procedure TBinaryProtocolImpl.ReadMapEnd;
+begin
+
+end;
+
+function TBinaryProtocolImpl.ReadMessageBegin: IMessage;
+var
+ size : Integer;
+ version : Integer;
+ message : IMessage;
+begin
+ message := TMessageImpl.Create;
+ size := ReadI32;
+ if (size < 0) then
+ begin
+ version := size and Integer( VERSION_MASK);
+ if ( version <> Integer( VERSION_1)) then
+ begin
+ raise TProtocolException.Create(TProtocolException.BAD_VERSION, 'Bad version in ReadMessageBegin: ' + IntToStr(version) );
+ end;
+ message.Type_ := TMessageType( size and $000000ff);
+ message.Name := ReadString;
+ message.SeqID := ReadI32;
+ end else
+ begin
+ if FStrictRead then
+ begin
+ raise TProtocolException.Create( TProtocolException.BAD_VERSION, 'Missing version in readMessageBegin, old client?' );
+ end;
+ message.Name := ReadStringBody( size );
+ message.Type_ := TMessageType( ReadByte );
+ message.SeqID := ReadI32;
+ end;
+ Result := message;
+end;
+
+procedure TBinaryProtocolImpl.ReadMessageEnd;
+begin
+ inherited;
+
+end;
+
+function TBinaryProtocolImpl.ReadSetBegin: ISet;
+var
+ set_ : ISet;
+begin
+ set_ := TSetImpl.Create;
+ set_.ElementType := TType( ReadByte );
+ set_.Count := ReadI32;
+ Result := set_;
+end;
+
+procedure TBinaryProtocolImpl.ReadSetEnd;
+begin
+
+end;
+
+function TBinaryProtocolImpl.ReadStringBody( size: Integer): string;
+var
+ buf : TBytes;
+begin
+ SetLength( buf, size );
+ FTrans.ReadAll( buf, 0, size );
+ Result := TEncoding.UTF8.GetString( buf);
+end;
+
+function TBinaryProtocolImpl.ReadStructBegin: IStruct;
+begin
+ Result := TStructImpl.Create('');
+end;
+
+procedure TBinaryProtocolImpl.ReadStructEnd;
+begin
+ inherited;
+
+end;
+
+procedure TBinaryProtocolImpl.WriteBinary( const b: TBytes);
+var iLen : Integer;
+begin
+ iLen := Length(b);
+ WriteI32( iLen);
+ if iLen > 0 then FTrans.Write(b, 0, iLen);
+end;
+
+procedure TBinaryProtocolImpl.WriteBool(b: Boolean);
+begin
+ if b then
+ begin
+ WriteByte( 1 );
+ end else
+ begin
+ WriteByte( 0 );
+ end;
+end;
+
+procedure TBinaryProtocolImpl.WriteByte(b: ShortInt);
+var
+ a : TBytes;
+begin
+ SetLength( a, 1);
+ a[0] := Byte( b );
+ FTrans.Write( a, 0, 1 );
+end;
+
+procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
+begin
+ WriteI64(ConvertDoubleToInt64(d));
+end;
+
+procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
+begin
+ WriteByte(ShortInt(field.Type_));
+ WriteI16(field.ID);
+end;
+
+procedure TBinaryProtocolImpl.WriteFieldEnd;
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteFieldStop;
+begin
+ WriteByte(ShortInt(TType.Stop));
+end;
+
+procedure TBinaryProtocolImpl.WriteI16(i16: SmallInt);
+var
+ i16out : TBytes;
+begin
+ SetLength( i16out, 2);
+ i16out[0] := Byte($FF and (i16 shr 8));
+ i16out[1] := Byte($FF and i16);
+ FTrans.Write( i16out );
+end;
+
+procedure TBinaryProtocolImpl.WriteI32(i32: Integer);
+var
+ i32out : TBytes;
+begin
+ SetLength( i32out, 4);
+ i32out[0] := Byte($FF and (i32 shr 24));
+ i32out[1] := Byte($FF and (i32 shr 16));
+ i32out[2] := Byte($FF and (i32 shr 8));
+ i32out[3] := Byte($FF and i32);
+ FTrans.Write( i32out, 0, 4);
+end;
+
+procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
+var
+ i64out : TBytes;
+begin
+ SetLength( i64out, 8);
+ i64out[0] := Byte($FF and (i64 shr 56));
+ i64out[1] := Byte($FF and (i64 shr 48));
+ i64out[2] := Byte($FF and (i64 shr 40));
+ i64out[3] := Byte($FF and (i64 shr 32));
+ i64out[4] := Byte($FF and (i64 shr 24));
+ i64out[5] := Byte($FF and (i64 shr 16));
+ i64out[6] := Byte($FF and (i64 shr 8));
+ i64out[7] := Byte($FF and i64);
+ FTrans.Write( i64out, 0, 8);
+end;
+
+procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
+begin
+ WriteByte(ShortInt(list.ElementType));
+ WriteI32(list.Count);
+end;
+
+procedure TBinaryProtocolImpl.WriteListEnd;
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
+begin
+ WriteByte(ShortInt(map.KeyType));
+ WriteByte(ShortInt(map.ValueType));
+ WriteI32(map.Count);
+end;
+
+procedure TBinaryProtocolImpl.WriteMapEnd;
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
+var
+ version : Cardinal;
+begin
+ if FStrictWrite then
+ begin
+ version := VERSION_1 or Cardinal( msg.Type_);
+ WriteI32( Integer( version) );
+ WriteString( msg.Name);
+ WriteI32( msg.SeqID);
+ end else
+ begin
+ WriteString( msg.Name);
+ WriteByte(ShortInt( msg.Type_));
+ WriteI32( msg.SeqID);
+ end;
+end;
+
+procedure TBinaryProtocolImpl.WriteMessageEnd;
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
+begin
+ WriteByte(ShortInt(set_.ElementType));
+ WriteI32(set_.Count);
+end;
+
+procedure TBinaryProtocolImpl.WriteSetEnd;
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
+begin
+
+end;
+
+procedure TBinaryProtocolImpl.WriteStructEnd;
+begin
+
+end;
+
+{ TProtocolException }
+
+constructor TProtocolException.Create;
+begin
+ inherited Create('');
+ FType := UNKNOWN;
+end;
+
+constructor TProtocolException.Create(type_: Integer);
+begin
+ inherited Create('');
+ FType := type_;
+end;
+
+constructor TProtocolException.Create(type_: Integer; const msg: string);
+begin
+ inherited Create( msg );
+ FType := type_;
+end;
+
+{ TThriftStringBuilder }
+
+function TThriftStringBuilder.Append(const Value: TBytes): TStringBuilder;
+begin
+ Result := Append( string( RawByteString(Value)) );
+end;
+
+function TThriftStringBuilder.Append(
+ const Value: IThriftContainer): TStringBuilder;
+begin
+ Result := Append( Value.ToString );
+end;
+
+{ TBinaryProtocolImpl.TFactory }
+
+constructor TBinaryProtocolImpl.TFactory.Create(AStrictRead, AStrictWrite: Boolean);
+begin
+ inherited Create;
+ FStrictRead := AStrictRead;
+ FStrictWrite := AStrictWrite;
+end;
+
+constructor TBinaryProtocolImpl.TFactory.Create;
+begin
+ //no inherited;
+ Create( False, True )
+end;
+
+function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
+begin
+ Result := TBinaryProtocolImpl.Create( trans, FStrictRead, FStrictWrite);
+end;
+
+
+{ TProtocolDecorator }
+
+constructor TProtocolDecorator.Create( const aProtocol : IProtocol);
+begin
+ ASSERT( aProtocol <> nil);
+ inherited Create( aProtocol.Transport);
+ FWrappedProtocol := aProtocol;
+end;
+
+
+procedure TProtocolDecorator.WriteMessageBegin( const msg: IMessage);
+begin
+ FWrappedProtocol.WriteMessageBegin( msg);
+end;
+
+
+procedure TProtocolDecorator.WriteMessageEnd;
+begin
+ FWrappedProtocol.WriteMessageEnd;
+end;
+
+
+procedure TProtocolDecorator.WriteStructBegin( const struc: IStruct);
+begin
+ FWrappedProtocol.WriteStructBegin( struc);
+end;
+
+
+procedure TProtocolDecorator.WriteStructEnd;
+begin
+ FWrappedProtocol.WriteStructEnd;
+end;
+
+
+procedure TProtocolDecorator.WriteFieldBegin( const field: IField);
+begin
+ FWrappedProtocol.WriteFieldBegin( field);
+end;
+
+
+procedure TProtocolDecorator.WriteFieldEnd;
+begin
+ FWrappedProtocol.WriteFieldEnd;
+end;
+
+
+procedure TProtocolDecorator.WriteFieldStop;
+begin
+ FWrappedProtocol.WriteFieldStop;
+end;
+
+
+procedure TProtocolDecorator.WriteMapBegin( const map: IMap);
+begin
+ FWrappedProtocol.WriteMapBegin( map);
+end;
+
+
+procedure TProtocolDecorator.WriteMapEnd;
+begin
+ FWrappedProtocol.WriteMapEnd;
+end;
+
+
+procedure TProtocolDecorator.WriteListBegin( const list: IList);
+begin
+ FWrappedProtocol.WriteListBegin( list);
+end;
+
+
+procedure TProtocolDecorator.WriteListEnd();
+begin
+ FWrappedProtocol.WriteListEnd();
+end;
+
+
+procedure TProtocolDecorator.WriteSetBegin( const set_: ISet );
+begin
+ FWrappedProtocol.WriteSetBegin( set_);
+end;
+
+
+procedure TProtocolDecorator.WriteSetEnd();
+begin
+ FWrappedProtocol.WriteSetEnd();
+end;
+
+
+procedure TProtocolDecorator.WriteBool( b: Boolean);
+begin
+ FWrappedProtocol.WriteBool( b);
+end;
+
+
+procedure TProtocolDecorator.WriteByte( b: ShortInt);
+begin
+ FWrappedProtocol.WriteByte( b);
+end;
+
+
+procedure TProtocolDecorator.WriteI16( i16: SmallInt);
+begin
+ FWrappedProtocol.WriteI16( i16);
+end;
+
+
+procedure TProtocolDecorator.WriteI32( i32: Integer);
+begin
+ FWrappedProtocol.WriteI32( i32);
+end;
+
+
+procedure TProtocolDecorator.WriteI64( const i64: Int64);
+begin
+ FWrappedProtocol.WriteI64( i64);
+end;
+
+
+procedure TProtocolDecorator.WriteDouble( const d: Double);
+begin
+ FWrappedProtocol.WriteDouble( d);
+end;
+
+
+procedure TProtocolDecorator.WriteString( const s: string );
+begin
+ FWrappedProtocol.WriteString( s);
+end;
+
+
+procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
+begin
+ FWrappedProtocol.WriteAnsiString( s);
+end;
+
+
+procedure TProtocolDecorator.WriteBinary( const b: TBytes);
+begin
+ FWrappedProtocol.WriteBinary( b);
+end;
+
+
+function TProtocolDecorator.ReadMessageBegin: IMessage;
+begin
+ result := FWrappedProtocol.ReadMessageBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadMessageEnd();
+begin
+ FWrappedProtocol.ReadMessageEnd();
+end;
+
+
+function TProtocolDecorator.ReadStructBegin: IStruct;
+begin
+ result := FWrappedProtocol.ReadStructBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadStructEnd;
+begin
+ FWrappedProtocol.ReadStructEnd;
+end;
+
+
+function TProtocolDecorator.ReadFieldBegin: IField;
+begin
+ result := FWrappedProtocol.ReadFieldBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadFieldEnd();
+begin
+ FWrappedProtocol.ReadFieldEnd();
+end;
+
+
+function TProtocolDecorator.ReadMapBegin: IMap;
+begin
+ result := FWrappedProtocol.ReadMapBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadMapEnd();
+begin
+ FWrappedProtocol.ReadMapEnd();
+end;
+
+
+function TProtocolDecorator.ReadListBegin: IList;
+begin
+ result := FWrappedProtocol.ReadListBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadListEnd();
+begin
+ FWrappedProtocol.ReadListEnd();
+end;
+
+
+function TProtocolDecorator.ReadSetBegin: ISet;
+begin
+ result := FWrappedProtocol.ReadSetBegin;
+end;
+
+
+procedure TProtocolDecorator.ReadSetEnd();
+begin
+ FWrappedProtocol.ReadSetEnd();
+end;
+
+
+function TProtocolDecorator.ReadBool: Boolean;
+begin
+ result := FWrappedProtocol.ReadBool;
+end;
+
+
+function TProtocolDecorator.ReadByte: ShortInt;
+begin
+ result := FWrappedProtocol.ReadByte;
+end;
+
+
+function TProtocolDecorator.ReadI16: SmallInt;
+begin
+ result := FWrappedProtocol.ReadI16;
+end;
+
+
+function TProtocolDecorator.ReadI32: Integer;
+begin
+ result := FWrappedProtocol.ReadI32;
+end;
+
+
+function TProtocolDecorator.ReadI64: Int64;
+begin
+ result := FWrappedProtocol.ReadI64;
+end;
+
+
+function TProtocolDecorator.ReadDouble:Double;
+begin
+ result := FWrappedProtocol.ReadDouble;
+end;
+
+
+function TProtocolDecorator.ReadBinary: TBytes;
+begin
+ result := FWrappedProtocol.ReadBinary;
+end;
+
+
+function TProtocolDecorator.ReadString: string;
+begin
+ result := FWrappedProtocol.ReadString;
+end;
+
+
+function TProtocolDecorator.ReadAnsiString: AnsiString;
+begin
+ result := FWrappedProtocol.ReadAnsiString;
+end;
+
+
+
+end.
+
diff --git a/lib/delphi/src/Thrift.Serializer.pas b/lib/delphi/src/Thrift.Serializer.pas
index 43b5d29..cf646c8 100644
--- a/lib/delphi/src/Thrift.Serializer.pas
+++ b/lib/delphi/src/Thrift.Serializer.pas
@@ -86,7 +86,7 @@
constructor TSerializer.Create();
// Create a new TSerializer that uses the TBinaryProtocol by default.
begin
- //no inherited;
+ //no inherited;
Create( TBinaryProtocolImpl.TFactory.Create);
end;
@@ -138,7 +138,7 @@
procedure TSerializer.Serialize( const input : IBase; const aStm : TStream);
// Serialize the Thrift object into a byte array. The process is simple,
// just clear the byte array output, write the object into it, and grab the
-// raw bytes.
+// raw bytes.
const COPY_ENTIRE_STREAM = 0;
begin
try
@@ -157,7 +157,7 @@
constructor TDeserializer.Create();
// Create a new TDeserializer that uses the TBinaryProtocol by default.
begin
- //no inherited;
+ //no inherited;
Create( TBinaryProtocolImpl.TFactory.Create);
end;
diff --git a/lib/delphi/src/Thrift.Server.pas b/lib/delphi/src/Thrift.Server.pas
index 2fb5c90..2935747 100644
--- a/lib/delphi/src/Thrift.Server.pas
+++ b/lib/delphi/src/Thrift.Server.pas
@@ -87,7 +87,7 @@
constructor Create(
const AProcessor :IProcessor;
const AServerTransport: IServerTransport
- ); overload;
+ ); overload;
constructor Create(
const AProcessor :IProcessor;
@@ -166,7 +166,7 @@
InputTransFactory := TTransportFactoryImpl.Create;
OutputTransFactory := TTransportFactoryImpl.Create;
- //no inherited;
+ //no inherited;
Create(
AProcessor,
AServerTransport,
@@ -187,7 +187,7 @@
InputProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
OutputProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
- //no inherited;
+ //no inherited;
Create( AProcessor, AServerTransport, ATransportFactory, ATransportFactory,
InputProtocolFactory, OutputProtocolFactory, DefaultLogDelegate);
end;
@@ -338,16 +338,16 @@
client := FServerTransport.Accept( procedure
begin
- if FServerEvents <> nil
+ if FServerEvents <> nil
then FServerEvents.PreAccept;
- end);
-
- if client = nil then begin
- if FStop
- then Abort // silent exception
- else raise TTransportException.Create( 'ServerTransport.Accept() may not return NULL' );
- end;
-
+ end);
+
+ if client = nil then begin
+ if FStop
+ then Abort // silent exception
+ else raise TTransportException.Create( 'ServerTransport.Accept() may not return NULL' );
+ end;
+
FLogDelegate( 'Client Connected!');
InputTransport := FInputTransportFactory.GetTransport( client );
diff --git a/lib/delphi/src/Thrift.Stream.pas b/lib/delphi/src/Thrift.Stream.pas
index c08f5ea..d1f6384 100644
--- a/lib/delphi/src/Thrift.Stream.pas
+++ b/lib/delphi/src/Thrift.Stream.pas
@@ -1,300 +1,300 @@
-(*
- * 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.
- *)
-
-unit Thrift.Stream;
-
-interface
-
-uses
- Classes,
- SysUtils,
- SysConst,
- RTLConsts,
- Thrift.Utils,
- ActiveX;
-
-type
-
- IThriftStream = interface
- ['{732621B3-F697-4D76-A1B0-B4DD5A8E4018}']
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer);
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
- procedure Open;
- procedure Close;
- procedure Flush;
- function IsOpen: Boolean;
- function ToArray: TBytes;
- end;
-
- TThriftStreamImpl = class( TInterfacedObject, IThriftStream)
- private
- procedure CheckSizeAndOffset( const buffer: TBytes; offset: Integer; count: Integer);
- protected
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer); virtual;
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; virtual;
- procedure Open; virtual; abstract;
- procedure Close; virtual; abstract;
- procedure Flush; virtual; abstract;
- function IsOpen: Boolean; virtual; abstract;
- function ToArray: TBytes; virtual; abstract;
- end;
-
- TThriftStreamAdapterDelphi = class( TThriftStreamImpl )
- private
- FStream : TStream;
- FOwnsStream : Boolean;
- protected
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
- procedure Open; override;
- procedure Close; override;
- procedure Flush; override;
- function IsOpen: Boolean; override;
- function ToArray: TBytes; override;
- public
- constructor Create( const AStream: TStream; AOwnsStream : Boolean);
- destructor Destroy; override;
- end;
-
- TThriftStreamAdapterCOM = class( TThriftStreamImpl)
- private
- FStream : IStream;
- protected
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
- procedure Open; override;
- procedure Close; override;
- procedure Flush; override;
- function IsOpen: Boolean; override;
- function ToArray: TBytes; override;
- public
- constructor Create( const AStream: IStream);
- end;
-
-implementation
-
-{ TThriftStreamAdapterCOM }
-
-procedure TThriftStreamAdapterCOM.Close;
-begin
- FStream := nil;
-end;
-
-constructor TThriftStreamAdapterCOM.Create( const AStream: IStream);
-begin
- inherited Create;
- FStream := AStream;
-end;
-
-procedure TThriftStreamAdapterCOM.Flush;
-begin
- if IsOpen then
- begin
- if FStream <> nil then
- begin
- FStream.Commit( STGC_DEFAULT );
- end;
- end;
-end;
-
-function TThriftStreamAdapterCOM.IsOpen: Boolean;
-begin
- Result := FStream <> nil;
-end;
-
-procedure TThriftStreamAdapterCOM.Open;
-begin
-
-end;
-
-function TThriftStreamAdapterCOM.Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
-begin
- inherited;
- Result := 0;
- if FStream <> nil then
- begin
- if count > 0 then
- begin
- FStream.Read( @buffer[offset], count, @Result);
- end;
- end;
-end;
-
-function TThriftStreamAdapterCOM.ToArray: TBytes;
-var
- statstg: TStatStg;
- len : Integer;
- NewPos : Int64;
- cbRead : Integer;
-begin
- FillChar( statstg, SizeOf( statstg), 0);
- len := 0;
- if IsOpen then
- begin
- if Succeeded( FStream.Stat( statstg, STATFLAG_NONAME )) then
- begin
- len := statstg.cbSize;
- end;
- end;
-
- SetLength( Result, len );
-
- if len > 0 then
- begin
- if Succeeded( FStream.Seek( 0, STREAM_SEEK_SET, NewPos) ) then
- begin
- FStream.Read( @Result[0], len, @cbRead);
- end;
- end;
-end;
-
-procedure TThriftStreamAdapterCOM.Write( const buffer: TBytes; offset: Integer; count: Integer);
-var
- nWritten : Integer;
-begin
- inherited;
- if IsOpen then
- begin
- if count > 0 then
- begin
- FStream.Write( @buffer[0], count, @nWritten);
- end;
- end;
-end;
-
-{ TThriftStreamImpl }
-
-procedure TThriftStreamImpl.CheckSizeAndOffset(const buffer: TBytes; offset,
- count: Integer);
-var
- len : Integer;
-begin
- if count > 0 then
- begin
- len := Length( buffer );
- if (offset < 0) or ( offset >= len) then
- begin
- raise ERangeError.Create( SBitsIndexError );
- end;
- if count > len then
- begin
- raise ERangeError.Create( SBitsIndexError );
- end;
- end;
-end;
-
-function TThriftStreamImpl.Read(var buffer: TBytes; offset,
- count: Integer): Integer;
-begin
- Result := 0;
- CheckSizeAndOffset( buffer, offset, count );
-end;
-
-procedure TThriftStreamImpl.Write(const buffer: TBytes; offset, count: Integer);
-begin
- CheckSizeAndOffset( buffer, offset, count );
-end;
-
-{ TThriftStreamAdapterDelphi }
-
-procedure TThriftStreamAdapterDelphi.Close;
-begin
- FStream.Free;
- FStream := nil;
- FOwnsStream := False;
-end;
-
-constructor TThriftStreamAdapterDelphi.Create( const AStream: TStream; AOwnsStream: Boolean);
-begin
- inherited Create;
- FStream := AStream;
- FOwnsStream := AOwnsStream;
-end;
-
-destructor TThriftStreamAdapterDelphi.Destroy;
-begin
- if FOwnsStream then
- begin
- FStream.Free;
- end;
- inherited;
-end;
-
-procedure TThriftStreamAdapterDelphi.Flush;
-begin
-
-end;
-
-function TThriftStreamAdapterDelphi.IsOpen: Boolean;
-begin
- Result := FStream <> nil;
-end;
-
-procedure TThriftStreamAdapterDelphi.Open;
-begin
-
-end;
-
-function TThriftStreamAdapterDelphi.Read(var buffer: TBytes; offset,
- count: Integer): Integer;
-begin
- inherited;
- Result := 0;
- if count > 0 then
- begin
- Result := FStream.Read( Pointer(@buffer[offset])^, count)
- end;
-end;
-
-function TThriftStreamAdapterDelphi.ToArray: TBytes;
-var
- OrgPos : Integer;
- len : Integer;
-begin
- len := 0;
- if FStream <> nil then
- begin
- len := FStream.Size;
- end;
-
- SetLength( Result, len );
-
- if len > 0 then
- begin
- OrgPos := FStream.Position;
- try
- FStream.Position := 0;
- FStream.ReadBuffer( Pointer(@Result[0])^, len );
- finally
- FStream.Position := OrgPos;
- end;
- end
-end;
-
-procedure TThriftStreamAdapterDelphi.Write(const buffer: TBytes; offset,
- count: Integer);
-begin
- inherited;
- if count > 0 then
- begin
- FStream.Write( Pointer(@buffer[offset])^, count)
- end;
-end;
-
-end.
+(*
+ * 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.
+ *)
+
+unit Thrift.Stream;
+
+interface
+
+uses
+ Classes,
+ SysUtils,
+ SysConst,
+ RTLConsts,
+ Thrift.Utils,
+ ActiveX;
+
+type
+
+ IThriftStream = interface
+ ['{732621B3-F697-4D76-A1B0-B4DD5A8E4018}']
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer);
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
+ procedure Open;
+ procedure Close;
+ procedure Flush;
+ function IsOpen: Boolean;
+ function ToArray: TBytes;
+ end;
+
+ TThriftStreamImpl = class( TInterfacedObject, IThriftStream)
+ private
+ procedure CheckSizeAndOffset( const buffer: TBytes; offset: Integer; count: Integer);
+ protected
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer); virtual;
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; virtual;
+ procedure Open; virtual; abstract;
+ procedure Close; virtual; abstract;
+ procedure Flush; virtual; abstract;
+ function IsOpen: Boolean; virtual; abstract;
+ function ToArray: TBytes; virtual; abstract;
+ end;
+
+ TThriftStreamAdapterDelphi = class( TThriftStreamImpl )
+ private
+ FStream : TStream;
+ FOwnsStream : Boolean;
+ protected
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
+ procedure Open; override;
+ procedure Close; override;
+ procedure Flush; override;
+ function IsOpen: Boolean; override;
+ function ToArray: TBytes; override;
+ public
+ constructor Create( const AStream: TStream; AOwnsStream : Boolean);
+ destructor Destroy; override;
+ end;
+
+ TThriftStreamAdapterCOM = class( TThriftStreamImpl)
+ private
+ FStream : IStream;
+ protected
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
+ procedure Open; override;
+ procedure Close; override;
+ procedure Flush; override;
+ function IsOpen: Boolean; override;
+ function ToArray: TBytes; override;
+ public
+ constructor Create( const AStream: IStream);
+ end;
+
+implementation
+
+{ TThriftStreamAdapterCOM }
+
+procedure TThriftStreamAdapterCOM.Close;
+begin
+ FStream := nil;
+end;
+
+constructor TThriftStreamAdapterCOM.Create( const AStream: IStream);
+begin
+ inherited Create;
+ FStream := AStream;
+end;
+
+procedure TThriftStreamAdapterCOM.Flush;
+begin
+ if IsOpen then
+ begin
+ if FStream <> nil then
+ begin
+ FStream.Commit( STGC_DEFAULT );
+ end;
+ end;
+end;
+
+function TThriftStreamAdapterCOM.IsOpen: Boolean;
+begin
+ Result := FStream <> nil;
+end;
+
+procedure TThriftStreamAdapterCOM.Open;
+begin
+
+end;
+
+function TThriftStreamAdapterCOM.Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
+begin
+ inherited;
+ Result := 0;
+ if FStream <> nil then
+ begin
+ if count > 0 then
+ begin
+ FStream.Read( @buffer[offset], count, @Result);
+ end;
+ end;
+end;
+
+function TThriftStreamAdapterCOM.ToArray: TBytes;
+var
+ statstg: TStatStg;
+ len : Integer;
+ NewPos : Int64;
+ cbRead : Integer;
+begin
+ FillChar( statstg, SizeOf( statstg), 0);
+ len := 0;
+ if IsOpen then
+ begin
+ if Succeeded( FStream.Stat( statstg, STATFLAG_NONAME )) then
+ begin
+ len := statstg.cbSize;
+ end;
+ end;
+
+ SetLength( Result, len );
+
+ if len > 0 then
+ begin
+ if Succeeded( FStream.Seek( 0, STREAM_SEEK_SET, NewPos) ) then
+ begin
+ FStream.Read( @Result[0], len, @cbRead);
+ end;
+ end;
+end;
+
+procedure TThriftStreamAdapterCOM.Write( const buffer: TBytes; offset: Integer; count: Integer);
+var
+ nWritten : Integer;
+begin
+ inherited;
+ if IsOpen then
+ begin
+ if count > 0 then
+ begin
+ FStream.Write( @buffer[0], count, @nWritten);
+ end;
+ end;
+end;
+
+{ TThriftStreamImpl }
+
+procedure TThriftStreamImpl.CheckSizeAndOffset(const buffer: TBytes; offset,
+ count: Integer);
+var
+ len : Integer;
+begin
+ if count > 0 then
+ begin
+ len := Length( buffer );
+ if (offset < 0) or ( offset >= len) then
+ begin
+ raise ERangeError.Create( SBitsIndexError );
+ end;
+ if count > len then
+ begin
+ raise ERangeError.Create( SBitsIndexError );
+ end;
+ end;
+end;
+
+function TThriftStreamImpl.Read(var buffer: TBytes; offset,
+ count: Integer): Integer;
+begin
+ Result := 0;
+ CheckSizeAndOffset( buffer, offset, count );
+end;
+
+procedure TThriftStreamImpl.Write(const buffer: TBytes; offset, count: Integer);
+begin
+ CheckSizeAndOffset( buffer, offset, count );
+end;
+
+{ TThriftStreamAdapterDelphi }
+
+procedure TThriftStreamAdapterDelphi.Close;
+begin
+ FStream.Free;
+ FStream := nil;
+ FOwnsStream := False;
+end;
+
+constructor TThriftStreamAdapterDelphi.Create( const AStream: TStream; AOwnsStream: Boolean);
+begin
+ inherited Create;
+ FStream := AStream;
+ FOwnsStream := AOwnsStream;
+end;
+
+destructor TThriftStreamAdapterDelphi.Destroy;
+begin
+ if FOwnsStream then
+ begin
+ FStream.Free;
+ end;
+ inherited;
+end;
+
+procedure TThriftStreamAdapterDelphi.Flush;
+begin
+
+end;
+
+function TThriftStreamAdapterDelphi.IsOpen: Boolean;
+begin
+ Result := FStream <> nil;
+end;
+
+procedure TThriftStreamAdapterDelphi.Open;
+begin
+
+end;
+
+function TThriftStreamAdapterDelphi.Read(var buffer: TBytes; offset,
+ count: Integer): Integer;
+begin
+ inherited;
+ Result := 0;
+ if count > 0 then
+ begin
+ Result := FStream.Read( Pointer(@buffer[offset])^, count)
+ end;
+end;
+
+function TThriftStreamAdapterDelphi.ToArray: TBytes;
+var
+ OrgPos : Integer;
+ len : Integer;
+begin
+ len := 0;
+ if FStream <> nil then
+ begin
+ len := FStream.Size;
+ end;
+
+ SetLength( Result, len );
+
+ if len > 0 then
+ begin
+ OrgPos := FStream.Position;
+ try
+ FStream.Position := 0;
+ FStream.ReadBuffer( Pointer(@Result[0])^, len );
+ finally
+ FStream.Position := OrgPos;
+ end;
+ end
+end;
+
+procedure TThriftStreamAdapterDelphi.Write(const buffer: TBytes; offset,
+ count: Integer);
+begin
+ inherited;
+ if count > 0 then
+ begin
+ FStream.Write( Pointer(@buffer[offset])^, count)
+ end;
+end;
+
+end.
diff --git a/lib/delphi/src/Thrift.Transport.Pipes.pas b/lib/delphi/src/Thrift.Transport.Pipes.pas
index eb4e8e3..48eb5e2 100644
--- a/lib/delphi/src/Thrift.Transport.Pipes.pas
+++ b/lib/delphi/src/Thrift.Transport.Pipes.pas
@@ -781,7 +781,7 @@
FWriteHandle := hPipeW;
result := TRUE;
-
+
finally
if sd <> nil then LocalFree( Cardinal(sd));
end;
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index bc66c64..96735ec 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -1,1389 +1,1389 @@
-(*
- * 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.
- *)
-
- {$SCOPEDENUMS ON}
-
-unit Thrift.Transport;
-
-interface
-
-uses
- Classes,
- SysUtils,
- Math,
- Sockets, WinSock,
- Generics.Collections,
- Thrift.Collections,
- Thrift.Utils,
- Thrift.Stream,
- ActiveX,
- msxml;
-
-type
- ITransport = interface
- ['{A4A9FC37-D620-44DC-AD21-662D16364CE4}']
- function GetIsOpen: Boolean;
- property IsOpen: Boolean read GetIsOpen;
- function Peek: Boolean;
- procedure Open;
- procedure Close;
- function Read(var buf: TBytes; off: Integer; len: Integer): Integer;
- function ReadAll(var buf: TBytes; off: Integer; len: Integer): Integer;
- procedure Write( const buf: TBytes); overload;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); overload;
- procedure Flush;
- end;
-
- TTransportImpl = class( TInterfacedObject, ITransport)
- protected
- function GetIsOpen: Boolean; virtual; abstract;
- property IsOpen: Boolean read GetIsOpen;
- function Peek: Boolean; virtual;
- procedure Open(); virtual; abstract;
- procedure Close(); virtual; abstract;
- function Read(var buf: TBytes; off: Integer; len: Integer): Integer; virtual; abstract;
- function ReadAll(var buf: TBytes; off: Integer; len: Integer): Integer; virtual;
- procedure Write( const buf: TBytes); overload; virtual;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); overload; virtual; abstract;
- procedure Flush; virtual;
- end;
-
- TTransportException = class( Exception )
- public
- type
- TExceptionType = (
- Unknown,
- NotOpen,
- AlreadyOpen,
- TimedOut,
- EndOfFile
- );
- private
- FType : TExceptionType;
- public
- constructor Create( AType: TExceptionType); overload;
- constructor Create( const msg: string); overload;
- constructor Create( AType: TExceptionType; const msg: string); overload;
- property Type_: TExceptionType read FType;
- end;
-
- IHTTPClient = interface( ITransport )
- ['{0F5DB8AB-710D-4338-AAC9-46B5734C5057}']
- procedure SetConnectionTimeout(const Value: Integer);
- function GetConnectionTimeout: Integer;
- procedure SetReadTimeout(const Value: Integer);
- function GetReadTimeout: Integer;
- function GetCustomHeaders: IThriftDictionary<string,string>;
- procedure SendRequest;
- property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
- property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
- property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
- end;
-
- THTTPClientImpl = class( TTransportImpl, IHTTPClient)
- private
- FUri : string;
- FInputStream : IThriftStream;
- FOutputStream : IThriftStream;
- FConnectionTimeout : Integer;
- FReadTimeout : Integer;
- FCustomHeaders : IThriftDictionary<string,string>;
-
- function CreateRequest: IXMLHTTPRequest;
- protected
- function GetIsOpen: Boolean; override;
- procedure Open(); override;
- procedure Close(); override;
- function Read( var buf: TBytes; off: Integer; len: Integer): Integer; override;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
- procedure Flush; override;
-
- procedure SetConnectionTimeout(const Value: Integer);
- function GetConnectionTimeout: Integer;
- procedure SetReadTimeout(const Value: Integer);
- function GetReadTimeout: Integer;
- function GetCustomHeaders: IThriftDictionary<string,string>;
- procedure SendRequest;
- property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
- property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
- property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
- public
- constructor Create( const AUri: string);
- destructor Destroy; override;
- end;
-
- IServerTransport = interface
- ['{C43B87ED-69EA-47C4-B77C-15E288252900}']
- procedure Listen;
- procedure Close;
- function Accept( const fnAccepting: TProc): ITransport;
- end;
-
- TServerTransportImpl = class( TInterfacedObject, IServerTransport)
- protected
- procedure Listen; virtual; abstract;
- procedure Close; virtual; abstract;
- function Accept( const fnAccepting: TProc): ITransport; virtual; abstract;
- end;
-
- ITransportFactory = interface
- ['{DD809446-000F-49E1-9BFF-E0D0DC76A9D7}']
- function GetTransport( const ATrans: ITransport): ITransport;
- end;
-
- TTransportFactoryImpl = class( TInterfacedObject, ITransportFactory)
- function GetTransport( const ATrans: ITransport): ITransport; virtual;
- end;
-
- TTcpSocketStreamImpl = class( TThriftStreamImpl )
- private type
- TWaitForData = ( wfd_HaveData, wfd_Timeout, wfd_Error);
- private
- FTcpClient : TCustomIpClient;
- FTimeout : Integer;
- function Select( ReadReady, WriteReady, ExceptFlag: PBoolean;
- TimeOut: Integer; var wsaError : Integer): Integer;
- function WaitForData( TimeOut : Integer; pBuf : Pointer; DesiredBytes: Integer;
- var wsaError : Integer): TWaitForData;
- protected
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
- procedure Open; override;
- procedure Close; override;
- procedure Flush; override;
-
- function IsOpen: Boolean; override;
- function ToArray: TBytes; override;
- public
- constructor Create( const ATcpClient: TCustomIpClient; const aTimeout : Integer = 0);
- end;
-
- IStreamTransport = interface( ITransport )
- ['{A8479B47-2A3E-4421-A9A0-D5A9EDCC634A}']
- function GetInputStream: IThriftStream;
- function GetOutputStream: IThriftStream;
- property InputStream : IThriftStream read GetInputStream;
- property OutputStream : IThriftStream read GetOutputStream;
- end;
-
- TStreamTransportImpl = class( TTransportImpl, IStreamTransport)
- protected
- FInputStream : IThriftStream;
- FOutputStream : IThriftStream;
- protected
- function GetIsOpen: Boolean; override;
-
- function GetInputStream: IThriftStream;
- function GetOutputStream: IThriftStream;
- public
- property InputStream : IThriftStream read GetInputStream;
- property OutputStream : IThriftStream read GetOutputStream;
-
- procedure Open; override;
- procedure Close; override;
- procedure Flush; override;
- function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
- constructor Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
- destructor Destroy; override;
- end;
-
- TBufferedStreamImpl = class( TThriftStreamImpl)
- private
- FStream : IThriftStream;
- FBufSize : Integer;
- FReadBuffer : TMemoryStream;
- FWriteBuffer : TMemoryStream;
- protected
- procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
- function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
- procedure Open; override;
- procedure Close; override;
- procedure Flush; override;
- function IsOpen: Boolean; override;
- function ToArray: TBytes; override;
- public
- constructor Create( const AStream: IThriftStream; ABufSize: Integer);
- destructor Destroy; override;
- end;
-
- TServerSocketImpl = class( TServerTransportImpl)
- private
- FServer : TTcpServer;
- FPort : Integer;
- FClientTimeout : Integer;
- FUseBufferedSocket : Boolean;
- FOwnsServer : Boolean;
- protected
- function Accept( const fnAccepting: TProc) : ITransport; override;
- public
- constructor Create( const AServer: TTcpServer; AClientTimeout: Integer = 0); overload;
- constructor Create( APort: Integer; AClientTimeout: Integer = 0; AUseBufferedSockets: Boolean = FALSE); overload;
- destructor Destroy; override;
- procedure Listen; override;
- procedure Close; override;
- end;
-
- TBufferedTransportImpl = class( TTransportImpl )
- private
- FInputBuffer : IThriftStream;
- FOutputBuffer : IThriftStream;
- FTransport : IStreamTransport;
- FBufSize : Integer;
-
- procedure InitBuffers;
- function GetUnderlyingTransport: ITransport;
- protected
- function GetIsOpen: Boolean; override;
- procedure Flush; override;
- public
- procedure Open(); override;
- procedure Close(); override;
- function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
- constructor Create( const ATransport : IStreamTransport ); overload;
- constructor Create( const ATransport : IStreamTransport; ABufSize: Integer); overload;
- property UnderlyingTransport: ITransport read GetUnderlyingTransport;
- property IsOpen: Boolean read GetIsOpen;
- end;
-
- TSocketImpl = class(TStreamTransportImpl)
- private
- FClient : TCustomIpClient;
- FOwnsClient : Boolean;
- FHost : string;
- FPort : Integer;
- FTimeout : Integer;
-
- procedure InitSocket;
- protected
- function GetIsOpen: Boolean; override;
- public
- procedure Open; override;
- constructor Create( const AClient : TCustomIpClient; aOwnsClient : Boolean; ATimeout: Integer = 0); overload;
- constructor Create( const AHost: string; APort: Integer; ATimeout: Integer = 0); overload;
- destructor Destroy; override;
- procedure Close; override;
- property TcpClient: TCustomIpClient read FClient;
- property Host : string read FHost;
- property Port: Integer read FPort;
- end;
-
- TFramedTransportImpl = class( TTransportImpl)
- private const
- FHeaderSize : Integer = 4;
- private class var
- FHeader_Dummy : array of Byte;
- protected
- FTransport : ITransport;
- FWriteBuffer : TMemoryStream;
- FReadBuffer : TMemoryStream;
-
- procedure InitWriteBuffer;
- procedure ReadFrame;
- public
- type
- TFactory = class( TTransportFactoryImpl )
- public
- function GetTransport( const ATrans: ITransport): ITransport; override;
- end;
-
-{$IF CompilerVersion >= 21.0}
- class constructor Create;
-{$IFEND}
- constructor Create; overload;
- constructor Create( const ATrans: ITransport); overload;
- destructor Destroy; override;
-
- procedure Open(); override;
- function GetIsOpen: Boolean; override;
-
- procedure Close(); override;
- function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
- procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
- procedure Flush; override;
- end;
-
-{$IF CompilerVersion < 21.0}
-procedure TFramedTransportImpl_Initialize;
-{$IFEND}
-
-const
- DEFAULT_THRIFT_TIMEOUT = 5 * 1000; // ms
-
-
-implementation
-
-{ TTransportImpl }
-
-procedure TTransportImpl.Flush;
-begin
-
-end;
-
-function TTransportImpl.Peek: Boolean;
-begin
- Result := IsOpen;
-end;
-
-function TTransportImpl.ReadAll( var buf: TBytes; off, len: Integer): Integer;
-var
- got : Integer;
- ret : Integer;
-begin
- got := 0;
- while ( got < len) do
- begin
- ret := Read( buf, off + got, len - got);
- if ( ret <= 0 ) then
- begin
- raise TTransportException.Create( 'Cannot read, Remote side has closed' );
- end;
- got := got + ret;
- end;
- Result := got;
-end;
-
-procedure TTransportImpl.Write( const buf: TBytes);
-begin
- Self.Write( buf, 0, Length(buf) );
-end;
-
-{ THTTPClientImpl }
-
-procedure THTTPClientImpl.Close;
-begin
- FInputStream := nil;
- FOutputStream := nil;
-end;
-
-constructor THTTPClientImpl.Create(const AUri: string);
-begin
- inherited Create;
- FUri := AUri;
- FCustomHeaders := TThriftDictionaryImpl<string,string>.Create;
- FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
-end;
-
-function THTTPClientImpl.CreateRequest: IXMLHTTPRequest;
-var
- pair : TPair<string,string>;
-begin
-{$IF CompilerVersion >= 21.0}
- Result := CoXMLHTTP.Create;
-{$ELSE}
- Result := CoXMLHTTPRequest.Create;
-{$IFEND}
-
- Result.open('POST', FUri, False, '', '');
- Result.setRequestHeader( 'Content-Type', 'application/x-thrift');
- Result.setRequestHeader( 'Accept', 'application/x-thrift');
- Result.setRequestHeader( 'User-Agent', 'Delphi/IHTTPClient');
-
- for pair in FCustomHeaders do
- begin
- Result.setRequestHeader( pair.Key, pair.Value );
- end;
-end;
-
-destructor THTTPClientImpl.Destroy;
-begin
- Close;
- inherited;
-end;
-
-procedure THTTPClientImpl.Flush;
-begin
- try
- SendRequest;
- finally
- FOutputStream := nil;
- FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
- end;
-end;
-
-function THTTPClientImpl.GetConnectionTimeout: Integer;
-begin
- Result := FConnectionTimeout;
-end;
-
-function THTTPClientImpl.GetCustomHeaders: IThriftDictionary<string,string>;
-begin
- Result := FCustomHeaders;
-end;
-
-function THTTPClientImpl.GetIsOpen: Boolean;
-begin
- Result := True;
-end;
-
-function THTTPClientImpl.GetReadTimeout: Integer;
-begin
- Result := FReadTimeout;
-end;
-
-procedure THTTPClientImpl.Open;
-begin
-
-end;
-
-function THTTPClientImpl.Read( var buf: TBytes; off, len: Integer): Integer;
-begin
- if FInputStream = nil then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
- 'No request has been sent');
- end;
- try
- Result := FInputStream.Read( buf, off, len )
- except
- on E: Exception do
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.Unknown,
- E.Message);
- end;
- end;
-end;
-
-procedure THTTPClientImpl.SendRequest;
-var
- xmlhttp : IXMLHTTPRequest;
- ms : TMemoryStream;
- a : TBytes;
- len : Integer;
-begin
- xmlhttp := CreateRequest;
-
- ms := TMemoryStream.Create;
- try
- a := FOutputStream.ToArray;
- len := Length(a);
- if len > 0 then
- begin
- ms.WriteBuffer( Pointer(@a[0])^, len);
- end;
- ms.Position := 0;
- xmlhttp.send( IUnknown( TStreamAdapter.Create( ms, soReference )));
- FInputStream := nil;
- FInputStream := TThriftStreamAdapterCOM.Create( IUnknown( xmlhttp.responseStream) as IStream);
- finally
- ms.Free;
- end;
-end;
-
-procedure THTTPClientImpl.SetConnectionTimeout(const Value: Integer);
-begin
- FConnectionTimeout := Value;
-end;
-
-procedure THTTPClientImpl.SetReadTimeout(const Value: Integer);
-begin
- FReadTimeout := Value
-end;
-
-procedure THTTPClientImpl.Write( const buf: TBytes; off, len: Integer);
-begin
- FOutputStream.Write( buf, off, len);
-end;
-
-{ TTransportException }
-
-constructor TTransportException.Create(AType: TExceptionType);
-begin
- //no inherited;
- Create( AType, '' )
-end;
-
-constructor TTransportException.Create(AType: TExceptionType;
- const msg: string);
-begin
- inherited Create(msg);
- FType := AType;
-end;
-
-constructor TTransportException.Create(const msg: string);
-begin
- inherited Create(msg);
-end;
-
-{ TTransportFactoryImpl }
-
-function TTransportFactoryImpl.GetTransport( const ATrans: ITransport): ITransport;
-begin
- Result := ATrans;
-end;
-
-{ TServerSocket }
-
-constructor TServerSocketImpl.Create( const AServer: TTcpServer; AClientTimeout: Integer);
-begin
- inherited Create;
- FServer := AServer;
- FClientTimeout := AClientTimeout;
-end;
-
-constructor TServerSocketImpl.Create(APort, AClientTimeout: Integer; AUseBufferedSockets: Boolean);
-begin
- inherited Create;
- FPort := APort;
- FClientTimeout := AClientTimeout;
- FUseBufferedSocket := AUseBufferedSockets;
- FOwnsServer := True;
- FServer := TTcpServer.Create( nil );
- FServer.BlockMode := bmBlocking;
-{$IF CompilerVersion >= 21.0}
- FServer.LocalPort := AnsiString( IntToStr( FPort));
-{$ELSE}
- FServer.LocalPort := IntToStr( FPort);
-{$IFEND}
-end;
-
-destructor TServerSocketImpl.Destroy;
-begin
- if FOwnsServer then begin
- FServer.Free;
- FServer := nil;
- end;
- inherited;
-end;
-
-function TServerSocketImpl.Accept( const fnAccepting: TProc): ITransport;
-var
- client : TCustomIpClient;
- trans : IStreamTransport;
-begin
- if FServer = nil then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
- 'No underlying server socket.');
- end;
-
- client := nil;
- try
- client := TCustomIpClient.Create(nil);
-
- if Assigned(fnAccepting)
- then fnAccepting();
-
- if not FServer.Accept( client) then
- begin
- client.Free;
- Result := nil;
- Exit;
- end;
-
- if client = nil then
- begin
- Result := nil;
- Exit;
- end;
-
- trans := TSocketImpl.Create( client, TRUE, FClientTimeout);
- client := nil; // trans owns it now
-
- if FUseBufferedSocket
- then result := TBufferedTransportImpl.Create( trans)
- else result := trans;
-
- except
- on E: Exception do begin
- client.Free;
- raise TTransportException.Create( E.ToString );
- end;
- end;
-end;
-
-procedure TServerSocketImpl.Listen;
-begin
- if FServer <> nil then
- begin
- try
- FServer.Active := True;
- except
- on E: Exception do
- begin
- raise TTransportException.Create('Could not accept on listening socket: ' + E.Message);
- end;
- end;
- end;
-end;
-
-procedure TServerSocketImpl.Close;
-begin
- if FServer <> nil then
- begin
- try
- FServer.Active := False;
- except
- on E: Exception do
- begin
- raise TTransportException.Create('Error on closing socket : ' + E.Message);
- end;
- end;
- end;
-end;
-
-{ TSocket }
-
-constructor TSocketImpl.Create( const AClient : TCustomIpClient; aOwnsClient : Boolean; ATimeout: Integer = 0);
-var stream : IThriftStream;
-begin
- FClient := AClient;
- FTimeout := ATimeout;
- FOwnsClient := aOwnsClient;
- stream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
- inherited Create( stream, stream);
-end;
-
-constructor TSocketImpl.Create(const AHost: string; APort, ATimeout: Integer);
-begin
- inherited Create(nil,nil);
- FHost := AHost;
- FPort := APort;
- FTimeout := ATimeout;
- InitSocket;
-end;
-
-destructor TSocketImpl.Destroy;
-begin
- if FOwnsClient
- then FreeAndNil( FClient);
- inherited;
-end;
-
-procedure TSocketImpl.Close;
-begin
- inherited Close;
- if FOwnsClient
- then FreeAndNil( FClient);
-end;
-
-function TSocketImpl.GetIsOpen: Boolean;
-begin
- Result := (FClient <> nil) and FClient.Connected;
-end;
-
-procedure TSocketImpl.InitSocket;
-var
- stream : IThriftStream;
-begin
- if FOwnsClient
- then FreeAndNil( FClient)
- else FClient := nil;
-
- FClient := TTcpClient.Create( nil);
- FOwnsClient := True;
-
- stream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
- FInputStream := stream;
- FOutputStream := stream;
-end;
-
-procedure TSocketImpl.Open;
-begin
- if IsOpen then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.AlreadyOpen,
- 'Socket already connected');
- end;
-
- if FHost = '' then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
- 'Cannot open null host');
- end;
-
- if Port <= 0 then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
- 'Cannot open without port');
- end;
-
- if FClient = nil then
- begin
- InitSocket;
- end;
-
- FClient.RemoteHost := TSocketHost( Host);
- FClient.RemotePort := TSocketPort( IntToStr( Port));
- FClient.Connect;
-
- FInputStream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
- FOutputStream := FInputStream;
-end;
-
-{ TBufferedStream }
-
-procedure TBufferedStreamImpl.Close;
-begin
- Flush;
- FStream := nil;
-
- FReadBuffer.Free;
- FReadBuffer := nil;
-
- FWriteBuffer.Free;
- FWriteBuffer := nil;
-end;
-
-constructor TBufferedStreamImpl.Create( const AStream: IThriftStream; ABufSize: Integer);
-begin
- inherited Create;
- FStream := AStream;
- FBufSize := ABufSize;
- FReadBuffer := TMemoryStream.Create;
- FWriteBuffer := TMemoryStream.Create;
-end;
-
-destructor TBufferedStreamImpl.Destroy;
-begin
- Close;
- inherited;
-end;
-
-procedure TBufferedStreamImpl.Flush;
-var
- buf : TBytes;
- len : Integer;
-begin
- if IsOpen then
- begin
- len := FWriteBuffer.Size;
- if len > 0 then
- begin
- SetLength( buf, len );
- FWriteBuffer.Position := 0;
- FWriteBuffer.Read( Pointer(@buf[0])^, len );
- FStream.Write( buf, 0, len );
- end;
- FWriteBuffer.Clear;
- end;
-end;
-
-function TBufferedStreamImpl.IsOpen: Boolean;
-begin
- Result := (FWriteBuffer <> nil)
- and (FReadBuffer <> nil)
- and (FStream <> nil);
-end;
-
-procedure TBufferedStreamImpl.Open;
-begin
-
-end;
-
-function TBufferedStreamImpl.Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
-var
- nRead : Integer;
- tempbuf : TBytes;
-begin
- inherited;
- Result := 0;
- if IsOpen then
- begin
- while count > 0 do begin
-
- if FReadBuffer.Position >= FReadBuffer.Size then
- begin
- FReadBuffer.Clear;
- SetLength( tempbuf, FBufSize);
- nRead := FStream.Read( tempbuf, 0, FBufSize );
- if nRead = 0 then Break; // avoid infinite loop
-
- FReadBuffer.WriteBuffer( Pointer(@tempbuf[0])^, nRead );
- FReadBuffer.Position := 0;
- end;
-
- if FReadBuffer.Position < FReadBuffer.Size then
- begin
- nRead := Min( FReadBuffer.Size - FReadBuffer.Position, count);
- Inc( Result, FReadBuffer.Read( Pointer(@buffer[offset])^, nRead));
- Dec( count, nRead);
- Inc( offset, nRead);
- end;
- end;
- end;
-end;
-
-function TBufferedStreamImpl.ToArray: TBytes;
-var
- len : Integer;
-begin
- len := 0;
-
- if IsOpen then
- begin
- len := FReadBuffer.Size;
- end;
-
- SetLength( Result, len);
-
- if len > 0 then
- begin
- FReadBuffer.Position := 0;
- FReadBuffer.Read( Pointer(@Result[0])^, len );
- end;
-end;
-
-procedure TBufferedStreamImpl.Write( const buffer: TBytes; offset: Integer; count: Integer);
-begin
- inherited;
- if count > 0 then
- begin
- if IsOpen then
- begin
- FWriteBuffer.Write( Pointer(@buffer[offset])^, count );
- if FWriteBuffer.Size > FBufSize then
- begin
- Flush;
- end;
- end;
- end;
-end;
-
-{ TStreamTransportImpl }
-
-procedure TStreamTransportImpl.Close;
-begin
- if FInputStream <> FOutputStream then
- begin
- if FInputStream <> nil then
- begin
- FInputStream := nil;
- end;
- if FOutputStream <> nil then
- begin
- FOutputStream := nil;
- end;
- end else
- begin
- FInputStream := nil;
- FOutputStream := nil;
- end;
-end;
-
-constructor TStreamTransportImpl.Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
-begin
- inherited Create;
- FInputStream := AInputStream;
- FOutputStream := AOutputStream;
-end;
-
-destructor TStreamTransportImpl.Destroy;
-begin
- FInputStream := nil;
- FOutputStream := nil;
- inherited;
-end;
-
-procedure TStreamTransportImpl.Flush;
-begin
- if FOutputStream = nil then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot flush null outputstream' );
- end;
-
- FOutputStream.Flush;
-end;
-
-function TStreamTransportImpl.GetInputStream: IThriftStream;
-begin
- Result := FInputStream;
-end;
-
-function TStreamTransportImpl.GetIsOpen: Boolean;
-begin
- Result := True;
-end;
-
-function TStreamTransportImpl.GetOutputStream: IThriftStream;
-begin
- Result := FInputStream;
-end;
-
-procedure TStreamTransportImpl.Open;
-begin
-
-end;
-
-function TStreamTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
-begin
- if FInputStream = nil then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot read from null inputstream' );
- end;
- Result := FInputStream.Read( buf, off, len );
-end;
-
-procedure TStreamTransportImpl.Write(const buf: TBytes; off, len: Integer);
-begin
- if FOutputStream = nil then
- begin
- raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot write to null outputstream' );
- end;
-
- FOutputStream.Write( buf, off, len );
-end;
-
-{ TBufferedTransportImpl }
-
-constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport);
-begin
- //no inherited;
- Create( ATransport, 1024 );
-end;
-
-procedure TBufferedTransportImpl.Close;
-begin
- FTransport.Close;
-end;
-
-constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport;
- ABufSize: Integer);
-begin
- inherited Create;
- FTransport := ATransport;
- FBufSize := ABufSize;
- InitBuffers;
-end;
-
-procedure TBufferedTransportImpl.Flush;
-begin
- if FOutputBuffer <> nil then
- begin
- FOutputBuffer.Flush;
- end;
-end;
-
-function TBufferedTransportImpl.GetIsOpen: Boolean;
-begin
- Result := FTransport.IsOpen;
-end;
-
-function TBufferedTransportImpl.GetUnderlyingTransport: ITransport;
-begin
- Result := FTransport;
-end;
-
-procedure TBufferedTransportImpl.InitBuffers;
-begin
- if FTransport.InputStream <> nil then
- begin
- FInputBuffer := TBufferedStreamImpl.Create( FTransport.InputStream, FBufSize );
- end;
- if FTransport.OutputStream <> nil then
- begin
- FOutputBuffer := TBufferedStreamImpl.Create( FTransport.OutputStream, FBufSize );
- end;
-end;
-
-procedure TBufferedTransportImpl.Open;
-begin
- FTransport.Open
-end;
-
-function TBufferedTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
-begin
- Result := 0;
- if FInputBuffer <> nil then
- begin
- Result := FInputBuffer.Read( buf, off, len );
- end;
-end;
-
-procedure TBufferedTransportImpl.Write(const buf: TBytes; off, len: Integer);
-begin
- if FOutputBuffer <> nil then
- begin
- FOutputBuffer.Write( buf, off, len );
- end;
-end;
-
-{ TFramedTransportImpl }
-
-{$IF CompilerVersion < 21.0}
-procedure TFramedTransportImpl_Initialize;
-begin
- SetLength( TFramedTransportImpl.FHeader_Dummy, TFramedTransportImpl.FHeaderSize);
- FillChar( TFramedTransportImpl.FHeader_Dummy[0],
- Length( TFramedTransportImpl.FHeader_Dummy) * SizeOf( Byte ), 0);
-end;
-{$ELSE}
-class constructor TFramedTransportImpl.Create;
-begin
- SetLength( FHeader_Dummy, FHeaderSize);
- FillChar( FHeader_Dummy[0], Length( FHeader_Dummy) * SizeOf( Byte ), 0);
-end;
-{$IFEND}
-
-constructor TFramedTransportImpl.Create;
-begin
- inherited Create;
- InitWriteBuffer;
-end;
-
-procedure TFramedTransportImpl.Close;
-begin
- FTransport.Close;
-end;
-
-constructor TFramedTransportImpl.Create( const ATrans: ITransport);
-begin
- inherited Create;
- InitWriteBuffer;
- FTransport := ATrans;
-end;
-
-destructor TFramedTransportImpl.Destroy;
-begin
- FWriteBuffer.Free;
- FReadBuffer.Free;
- inherited;
-end;
-
-procedure TFramedTransportImpl.Flush;
-var
- buf : TBytes;
- len : Integer;
- data_len : Integer;
-
-begin
- len := FWriteBuffer.Size;
- SetLength( buf, len);
- if len > 0 then
- begin
- System.Move( FWriteBuffer.Memory^, buf[0], len );
- end;
-
- data_len := len - FHeaderSize;
- if (data_len < 0) then
- begin
- raise Exception.Create( 'TFramedTransport.Flush: data_len < 0' );
- end;
-
- InitWriteBuffer;
-
- buf[0] := Byte($FF and (data_len shr 24));
- buf[1] := Byte($FF and (data_len shr 16));
- buf[2] := Byte($FF and (data_len shr 8));
- buf[3] := Byte($FF and data_len);
-
- FTransport.Write( buf, 0, len );
- FTransport.Flush;
-end;
-
-function TFramedTransportImpl.GetIsOpen: Boolean;
-begin
- Result := FTransport.IsOpen;
-end;
-
-type
- TAccessMemoryStream = class(TMemoryStream)
- end;
-
-procedure TFramedTransportImpl.InitWriteBuffer;
-begin
- FWriteBuffer.Free;
- FWriteBuffer := TMemoryStream.Create;
- TAccessMemoryStream(FWriteBuffer).Capacity := 1024;
- FWriteBuffer.Write( Pointer(@FHeader_Dummy[0])^, FHeaderSize);
-end;
-
-procedure TFramedTransportImpl.Open;
-begin
- FTransport.Open;
-end;
-
-function TFramedTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
-var
- got : Integer;
-begin
- if FReadBuffer <> nil then
- begin
- if len > 0
- then got := FReadBuffer.Read( Pointer(@buf[off])^, len )
- else got := 0;
- if got > 0 then
- begin
- Result := got;
- Exit;
- end;
- end;
-
- ReadFrame;
- if len > 0
- then Result := FReadBuffer.Read( Pointer(@buf[off])^, len)
- else Result := 0;
-end;
-
-procedure TFramedTransportImpl.ReadFrame;
-var
- i32rd : TBytes;
- size : Integer;
- buff : TBytes;
-begin
- SetLength( i32rd, FHeaderSize );
- FTransport.ReadAll( i32rd, 0, FHeaderSize);
- size :=
- ((i32rd[0] and $FF) shl 24) or
- ((i32rd[1] and $FF) shl 16) or
- ((i32rd[2] and $FF) shl 8) or
- (i32rd[3] and $FF);
- SetLength( buff, size );
- FTransport.ReadAll( buff, 0, size );
- FReadBuffer.Free;
- FReadBuffer := TMemoryStream.Create;
- FReadBuffer.Write( Pointer(@buff[0])^, size );
- FReadBuffer.Position := 0;
-end;
-
-procedure TFramedTransportImpl.Write(const buf: TBytes; off, len: Integer);
-begin
- if len > 0
- then FWriteBuffer.Write( Pointer(@buf[off])^, len );
-end;
-
-{ TFramedTransport.TFactory }
-
-function TFramedTransportImpl.TFactory.GetTransport( const ATrans: ITransport): ITransport;
-begin
- Result := TFramedTransportImpl.Create( ATrans );
-end;
-
-{ TTcpSocketStreamImpl }
-
-procedure TTcpSocketStreamImpl.Close;
-begin
- FTcpClient.Close;
-end;
-
-constructor TTcpSocketStreamImpl.Create( const ATcpClient: TCustomIpClient; const aTimeout : Integer);
-begin
- inherited Create;
- FTcpClient := ATcpClient;
- FTimeout := aTimeout;
-end;
-
-procedure TTcpSocketStreamImpl.Flush;
-begin
-
-end;
-
-function TTcpSocketStreamImpl.IsOpen: Boolean;
-begin
- Result := FTcpClient.Active;
-end;
-
-procedure TTcpSocketStreamImpl.Open;
-begin
- FTcpClient.Open;
-end;
-
-
-function TTcpSocketStreamImpl.Select( ReadReady, WriteReady, ExceptFlag: PBoolean;
- TimeOut: Integer; var wsaError : Integer): Integer;
-var
- ReadFds: TFDset;
- ReadFdsptr: PFDset;
- WriteFds: TFDset;
- WriteFdsptr: PFDset;
- ExceptFds: TFDset;
- ExceptFdsptr: PFDset;
- tv: timeval;
- Timeptr: PTimeval;
- socket : TSocket;
-begin
- if not FTcpClient.Active then begin
- wsaError := WSAEINVAL;
- Exit( SOCKET_ERROR);
- end;
-
- socket := FTcpClient.Handle;
-
- if Assigned(ReadReady) then
- begin
- ReadFdsptr := @ReadFds;
- FD_ZERO(ReadFds);
- FD_SET(socket, ReadFds);
- end
- else
- ReadFdsptr := nil;
-
- if Assigned(WriteReady) then
- begin
- WriteFdsptr := @WriteFds;
- FD_ZERO(WriteFds);
- FD_SET(socket, WriteFds);
- end
- else
- WriteFdsptr := nil;
-
- if Assigned(ExceptFlag) then
- begin
- ExceptFdsptr := @ExceptFds;
- FD_ZERO(ExceptFds);
- FD_SET(socket, ExceptFds);
- end
- else
- ExceptFdsptr := nil;
-
- if TimeOut >= 0 then
- begin
- tv.tv_sec := TimeOut div 1000;
- tv.tv_usec := 1000 * (TimeOut mod 1000);
- Timeptr := @tv;
- end
- else
- Timeptr := nil; // wait forever
-
- wsaError := 0;
- try
-{$IFDEF MSWINDOWS}
- result := WinSock.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
-{$ENDIF}
-{$IFDEF LINUX}
- result := Libc.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
-{$ENDIF}
- if result = SOCKET_ERROR
- then wsaError := WSAGetLastError;
-
- except
- result := SOCKET_ERROR;
- end;
-
- if Assigned(ReadReady) then
- ReadReady^ := FD_ISSET(socket, ReadFds);
- if Assigned(WriteReady) then
- WriteReady^ := FD_ISSET(socket, WriteFds);
- if Assigned(ExceptFlag) then
- ExceptFlag^ := FD_ISSET(socket, ExceptFds);
-end;
-
-function TTcpSocketStreamImpl.WaitForData( TimeOut : Integer; pBuf : Pointer;
- DesiredBytes : Integer;
- var wsaError : Integer): TWaitForData;
-var bCanRead, bError : Boolean;
- retval : Integer;
-begin
- // The select function returns the total number of socket handles that are ready
- // and contained in the fd_set structures, zero if the time limit expired,
- // or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR,
- // WSAGetLastError can be used to retrieve a specific error code.
- retval := Self.Select( @bCanRead, nil, @bError, TimeOut, wsaError);
- if retval = SOCKET_ERROR
- then Exit( TWaitForData.wfd_Error);
- if (retval = 0) or not bCanRead
- then Exit( TWaitForData.wfd_Timeout);
-
- // recv() returns the number of bytes received, or -1 if an error occurred.
- // The return value will be 0 when the peer has performed an orderly shutdown.
- retval := recv( FTcpClient.Handle, pBuf^, DesiredBytes, WinSock.MSG_PEEK);
- if retval <= 0
- then Exit( TWaitForData.wfd_Error);
-
- // Enough data ready to be read?
- if retval = DesiredBytes
- then result := TWaitForData.wfd_HaveData
- else result := TWaitForData.wfd_Timeout;
-end;
-
-function TTcpSocketStreamImpl.Read(var buffer: TBytes; offset, count: Integer): Integer;
-var wfd : TWaitForData;
- wsaError : Integer;
- pDest : Pointer;
-const
- SLEEP_TIME = 200;
-begin
- inherited;
-
- pDest := Pointer(@buffer[offset]);
-
- while TRUE do begin
- if FTimeout > 0
- then wfd := WaitForData( FTimeout, pDest, count, wsaError)
- else wfd := WaitForData( SLEEP_TIME, pDest, count, wsaError);
-
- case wfd of
- TWaitForData.wfd_Error : Exit(0);
- TWaitForData.wfd_HaveData : Break;
- TWaitForData.wfd_Timeout : begin
- if (FTimeout > 0)
- then raise TTransportException.Create( TTransportException.TExceptionType.TimedOut,
- SysErrorMessage(Cardinal(wsaError)));
- end;
- else
- ASSERT( FALSE);
- end;
- end;
-
- Result := FTcpClient.ReceiveBuf( pDest^, count);
-end;
-
-function TTcpSocketStreamImpl.ToArray: TBytes;
-var
- len : Integer;
-begin
- len := 0;
- if IsOpen then
- begin
- len := FTcpClient.BytesReceived;
- end;
-
- SetLength( Result, len );
-
- if len > 0 then
- begin
- FTcpClient.ReceiveBuf( Pointer(@Result[0])^, len);
- end;
-end;
-
-procedure TTcpSocketStreamImpl.Write(const buffer: TBytes; offset, count: Integer);
-var bCanWrite, bError : Boolean;
- retval, wsaError : Integer;
-begin
- inherited;
-
- if not FTcpClient.Active
- then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen);
-
- // The select function returns the total number of socket handles that are ready
- // and contained in the fd_set structures, zero if the time limit expired,
- // or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR,
- // WSAGetLastError can be used to retrieve a specific error code.
- retval := Self.Select( nil, @bCanWrite, @bError, FTimeOut, wsaError);
- if retval = SOCKET_ERROR
- then raise TTransportException.Create( TTransportException.TExceptionType.Unknown,
- SysErrorMessage(Cardinal(wsaError)));
- if (retval = 0)
- then raise TTransportException.Create( TTransportException.TExceptionType.TimedOut);
- if bError or not bCanWrite
- then raise TTransportException.Create( TTransportException.TExceptionType.Unknown);
-
- FTcpClient.SendBuf( Pointer(@buffer[offset])^, count);
-end;
-
-{$IF CompilerVersion < 21.0}
-initialization
-begin
- TFramedTransportImpl_Initialize;
-end;
-{$IFEND}
-
-
-end.
+(*
+ * 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.
+ *)
+
+ {$SCOPEDENUMS ON}
+
+unit Thrift.Transport;
+
+interface
+
+uses
+ Classes,
+ SysUtils,
+ Math,
+ Sockets, WinSock,
+ Generics.Collections,
+ Thrift.Collections,
+ Thrift.Utils,
+ Thrift.Stream,
+ ActiveX,
+ msxml;
+
+type
+ ITransport = interface
+ ['{A4A9FC37-D620-44DC-AD21-662D16364CE4}']
+ function GetIsOpen: Boolean;
+ property IsOpen: Boolean read GetIsOpen;
+ function Peek: Boolean;
+ procedure Open;
+ procedure Close;
+ function Read(var buf: TBytes; off: Integer; len: Integer): Integer;
+ function ReadAll(var buf: TBytes; off: Integer; len: Integer): Integer;
+ procedure Write( const buf: TBytes); overload;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); overload;
+ procedure Flush;
+ end;
+
+ TTransportImpl = class( TInterfacedObject, ITransport)
+ protected
+ function GetIsOpen: Boolean; virtual; abstract;
+ property IsOpen: Boolean read GetIsOpen;
+ function Peek: Boolean; virtual;
+ procedure Open(); virtual; abstract;
+ procedure Close(); virtual; abstract;
+ function Read(var buf: TBytes; off: Integer; len: Integer): Integer; virtual; abstract;
+ function ReadAll(var buf: TBytes; off: Integer; len: Integer): Integer; virtual;
+ procedure Write( const buf: TBytes); overload; virtual;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); overload; virtual; abstract;
+ procedure Flush; virtual;
+ end;
+
+ TTransportException = class( Exception )
+ public
+ type
+ TExceptionType = (
+ Unknown,
+ NotOpen,
+ AlreadyOpen,
+ TimedOut,
+ EndOfFile
+ );
+ private
+ FType : TExceptionType;
+ public
+ constructor Create( AType: TExceptionType); overload;
+ constructor Create( const msg: string); overload;
+ constructor Create( AType: TExceptionType; const msg: string); overload;
+ property Type_: TExceptionType read FType;
+ end;
+
+ IHTTPClient = interface( ITransport )
+ ['{0F5DB8AB-710D-4338-AAC9-46B5734C5057}']
+ procedure SetConnectionTimeout(const Value: Integer);
+ function GetConnectionTimeout: Integer;
+ procedure SetReadTimeout(const Value: Integer);
+ function GetReadTimeout: Integer;
+ function GetCustomHeaders: IThriftDictionary<string,string>;
+ procedure SendRequest;
+ property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
+ property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
+ property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
+ end;
+
+ THTTPClientImpl = class( TTransportImpl, IHTTPClient)
+ private
+ FUri : string;
+ FInputStream : IThriftStream;
+ FOutputStream : IThriftStream;
+ FConnectionTimeout : Integer;
+ FReadTimeout : Integer;
+ FCustomHeaders : IThriftDictionary<string,string>;
+
+ function CreateRequest: IXMLHTTPRequest;
+ protected
+ function GetIsOpen: Boolean; override;
+ procedure Open(); override;
+ procedure Close(); override;
+ function Read( var buf: TBytes; off: Integer; len: Integer): Integer; override;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
+ procedure Flush; override;
+
+ procedure SetConnectionTimeout(const Value: Integer);
+ function GetConnectionTimeout: Integer;
+ procedure SetReadTimeout(const Value: Integer);
+ function GetReadTimeout: Integer;
+ function GetCustomHeaders: IThriftDictionary<string,string>;
+ procedure SendRequest;
+ property ConnectionTimeout: Integer read GetConnectionTimeout write SetConnectionTimeout;
+ property ReadTimeout: Integer read GetReadTimeout write SetReadTimeout;
+ property CustomHeaders: IThriftDictionary<string,string> read GetCustomHeaders;
+ public
+ constructor Create( const AUri: string);
+ destructor Destroy; override;
+ end;
+
+ IServerTransport = interface
+ ['{C43B87ED-69EA-47C4-B77C-15E288252900}']
+ procedure Listen;
+ procedure Close;
+ function Accept( const fnAccepting: TProc): ITransport;
+ end;
+
+ TServerTransportImpl = class( TInterfacedObject, IServerTransport)
+ protected
+ procedure Listen; virtual; abstract;
+ procedure Close; virtual; abstract;
+ function Accept( const fnAccepting: TProc): ITransport; virtual; abstract;
+ end;
+
+ ITransportFactory = interface
+ ['{DD809446-000F-49E1-9BFF-E0D0DC76A9D7}']
+ function GetTransport( const ATrans: ITransport): ITransport;
+ end;
+
+ TTransportFactoryImpl = class( TInterfacedObject, ITransportFactory)
+ function GetTransport( const ATrans: ITransport): ITransport; virtual;
+ end;
+
+ TTcpSocketStreamImpl = class( TThriftStreamImpl )
+ private type
+ TWaitForData = ( wfd_HaveData, wfd_Timeout, wfd_Error);
+ private
+ FTcpClient : TCustomIpClient;
+ FTimeout : Integer;
+ function Select( ReadReady, WriteReady, ExceptFlag: PBoolean;
+ TimeOut: Integer; var wsaError : Integer): Integer;
+ function WaitForData( TimeOut : Integer; pBuf : Pointer; DesiredBytes: Integer;
+ var wsaError : Integer): TWaitForData;
+ protected
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
+ procedure Open; override;
+ procedure Close; override;
+ procedure Flush; override;
+
+ function IsOpen: Boolean; override;
+ function ToArray: TBytes; override;
+ public
+ constructor Create( const ATcpClient: TCustomIpClient; const aTimeout : Integer = 0);
+ end;
+
+ IStreamTransport = interface( ITransport )
+ ['{A8479B47-2A3E-4421-A9A0-D5A9EDCC634A}']
+ function GetInputStream: IThriftStream;
+ function GetOutputStream: IThriftStream;
+ property InputStream : IThriftStream read GetInputStream;
+ property OutputStream : IThriftStream read GetOutputStream;
+ end;
+
+ TStreamTransportImpl = class( TTransportImpl, IStreamTransport)
+ protected
+ FInputStream : IThriftStream;
+ FOutputStream : IThriftStream;
+ protected
+ function GetIsOpen: Boolean; override;
+
+ function GetInputStream: IThriftStream;
+ function GetOutputStream: IThriftStream;
+ public
+ property InputStream : IThriftStream read GetInputStream;
+ property OutputStream : IThriftStream read GetOutputStream;
+
+ procedure Open; override;
+ procedure Close; override;
+ procedure Flush; override;
+ function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
+ constructor Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
+ destructor Destroy; override;
+ end;
+
+ TBufferedStreamImpl = class( TThriftStreamImpl)
+ private
+ FStream : IThriftStream;
+ FBufSize : Integer;
+ FReadBuffer : TMemoryStream;
+ FWriteBuffer : TMemoryStream;
+ protected
+ procedure Write( const buffer: TBytes; offset: Integer; count: Integer); override;
+ function Read( var buffer: TBytes; offset: Integer; count: Integer): Integer; override;
+ procedure Open; override;
+ procedure Close; override;
+ procedure Flush; override;
+ function IsOpen: Boolean; override;
+ function ToArray: TBytes; override;
+ public
+ constructor Create( const AStream: IThriftStream; ABufSize: Integer);
+ destructor Destroy; override;
+ end;
+
+ TServerSocketImpl = class( TServerTransportImpl)
+ private
+ FServer : TTcpServer;
+ FPort : Integer;
+ FClientTimeout : Integer;
+ FUseBufferedSocket : Boolean;
+ FOwnsServer : Boolean;
+ protected
+ function Accept( const fnAccepting: TProc) : ITransport; override;
+ public
+ constructor Create( const AServer: TTcpServer; AClientTimeout: Integer = 0); overload;
+ constructor Create( APort: Integer; AClientTimeout: Integer = 0; AUseBufferedSockets: Boolean = FALSE); overload;
+ destructor Destroy; override;
+ procedure Listen; override;
+ procedure Close; override;
+ end;
+
+ TBufferedTransportImpl = class( TTransportImpl )
+ private
+ FInputBuffer : IThriftStream;
+ FOutputBuffer : IThriftStream;
+ FTransport : IStreamTransport;
+ FBufSize : Integer;
+
+ procedure InitBuffers;
+ function GetUnderlyingTransport: ITransport;
+ protected
+ function GetIsOpen: Boolean; override;
+ procedure Flush; override;
+ public
+ procedure Open(); override;
+ procedure Close(); override;
+ function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
+ constructor Create( const ATransport : IStreamTransport ); overload;
+ constructor Create( const ATransport : IStreamTransport; ABufSize: Integer); overload;
+ property UnderlyingTransport: ITransport read GetUnderlyingTransport;
+ property IsOpen: Boolean read GetIsOpen;
+ end;
+
+ TSocketImpl = class(TStreamTransportImpl)
+ private
+ FClient : TCustomIpClient;
+ FOwnsClient : Boolean;
+ FHost : string;
+ FPort : Integer;
+ FTimeout : Integer;
+
+ procedure InitSocket;
+ protected
+ function GetIsOpen: Boolean; override;
+ public
+ procedure Open; override;
+ constructor Create( const AClient : TCustomIpClient; aOwnsClient : Boolean; ATimeout: Integer = 0); overload;
+ constructor Create( const AHost: string; APort: Integer; ATimeout: Integer = 0); overload;
+ destructor Destroy; override;
+ procedure Close; override;
+ property TcpClient: TCustomIpClient read FClient;
+ property Host : string read FHost;
+ property Port: Integer read FPort;
+ end;
+
+ TFramedTransportImpl = class( TTransportImpl)
+ private const
+ FHeaderSize : Integer = 4;
+ private class var
+ FHeader_Dummy : array of Byte;
+ protected
+ FTransport : ITransport;
+ FWriteBuffer : TMemoryStream;
+ FReadBuffer : TMemoryStream;
+
+ procedure InitWriteBuffer;
+ procedure ReadFrame;
+ public
+ type
+ TFactory = class( TTransportFactoryImpl )
+ public
+ function GetTransport( const ATrans: ITransport): ITransport; override;
+ end;
+
+{$IF CompilerVersion >= 21.0}
+ class constructor Create;
+{$IFEND}
+ constructor Create; overload;
+ constructor Create( const ATrans: ITransport); overload;
+ destructor Destroy; override;
+
+ procedure Open(); override;
+ function GetIsOpen: Boolean; override;
+
+ procedure Close(); override;
+ function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
+ procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
+ procedure Flush; override;
+ end;
+
+{$IF CompilerVersion < 21.0}
+procedure TFramedTransportImpl_Initialize;
+{$IFEND}
+
+const
+ DEFAULT_THRIFT_TIMEOUT = 5 * 1000; // ms
+
+
+implementation
+
+{ TTransportImpl }
+
+procedure TTransportImpl.Flush;
+begin
+
+end;
+
+function TTransportImpl.Peek: Boolean;
+begin
+ Result := IsOpen;
+end;
+
+function TTransportImpl.ReadAll( var buf: TBytes; off, len: Integer): Integer;
+var
+ got : Integer;
+ ret : Integer;
+begin
+ got := 0;
+ while ( got < len) do
+ begin
+ ret := Read( buf, off + got, len - got);
+ if ( ret <= 0 ) then
+ begin
+ raise TTransportException.Create( 'Cannot read, Remote side has closed' );
+ end;
+ got := got + ret;
+ end;
+ Result := got;
+end;
+
+procedure TTransportImpl.Write( const buf: TBytes);
+begin
+ Self.Write( buf, 0, Length(buf) );
+end;
+
+{ THTTPClientImpl }
+
+procedure THTTPClientImpl.Close;
+begin
+ FInputStream := nil;
+ FOutputStream := nil;
+end;
+
+constructor THTTPClientImpl.Create(const AUri: string);
+begin
+ inherited Create;
+ FUri := AUri;
+ FCustomHeaders := TThriftDictionaryImpl<string,string>.Create;
+ FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
+end;
+
+function THTTPClientImpl.CreateRequest: IXMLHTTPRequest;
+var
+ pair : TPair<string,string>;
+begin
+{$IF CompilerVersion >= 21.0}
+ Result := CoXMLHTTP.Create;
+{$ELSE}
+ Result := CoXMLHTTPRequest.Create;
+{$IFEND}
+
+ Result.open('POST', FUri, False, '', '');
+ Result.setRequestHeader( 'Content-Type', 'application/x-thrift');
+ Result.setRequestHeader( 'Accept', 'application/x-thrift');
+ Result.setRequestHeader( 'User-Agent', 'Delphi/IHTTPClient');
+
+ for pair in FCustomHeaders do
+ begin
+ Result.setRequestHeader( pair.Key, pair.Value );
+ end;
+end;
+
+destructor THTTPClientImpl.Destroy;
+begin
+ Close;
+ inherited;
+end;
+
+procedure THTTPClientImpl.Flush;
+begin
+ try
+ SendRequest;
+ finally
+ FOutputStream := nil;
+ FOutputStream := TThriftStreamAdapterDelphi.Create( TMemoryStream.Create, True);
+ end;
+end;
+
+function THTTPClientImpl.GetConnectionTimeout: Integer;
+begin
+ Result := FConnectionTimeout;
+end;
+
+function THTTPClientImpl.GetCustomHeaders: IThriftDictionary<string,string>;
+begin
+ Result := FCustomHeaders;
+end;
+
+function THTTPClientImpl.GetIsOpen: Boolean;
+begin
+ Result := True;
+end;
+
+function THTTPClientImpl.GetReadTimeout: Integer;
+begin
+ Result := FReadTimeout;
+end;
+
+procedure THTTPClientImpl.Open;
+begin
+
+end;
+
+function THTTPClientImpl.Read( var buf: TBytes; off, len: Integer): Integer;
+begin
+ if FInputStream = nil then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+ 'No request has been sent');
+ end;
+ try
+ Result := FInputStream.Read( buf, off, len )
+ except
+ on E: Exception do
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.Unknown,
+ E.Message);
+ end;
+ end;
+end;
+
+procedure THTTPClientImpl.SendRequest;
+var
+ xmlhttp : IXMLHTTPRequest;
+ ms : TMemoryStream;
+ a : TBytes;
+ len : Integer;
+begin
+ xmlhttp := CreateRequest;
+
+ ms := TMemoryStream.Create;
+ try
+ a := FOutputStream.ToArray;
+ len := Length(a);
+ if len > 0 then
+ begin
+ ms.WriteBuffer( Pointer(@a[0])^, len);
+ end;
+ ms.Position := 0;
+ xmlhttp.send( IUnknown( TStreamAdapter.Create( ms, soReference )));
+ FInputStream := nil;
+ FInputStream := TThriftStreamAdapterCOM.Create( IUnknown( xmlhttp.responseStream) as IStream);
+ finally
+ ms.Free;
+ end;
+end;
+
+procedure THTTPClientImpl.SetConnectionTimeout(const Value: Integer);
+begin
+ FConnectionTimeout := Value;
+end;
+
+procedure THTTPClientImpl.SetReadTimeout(const Value: Integer);
+begin
+ FReadTimeout := Value
+end;
+
+procedure THTTPClientImpl.Write( const buf: TBytes; off, len: Integer);
+begin
+ FOutputStream.Write( buf, off, len);
+end;
+
+{ TTransportException }
+
+constructor TTransportException.Create(AType: TExceptionType);
+begin
+ //no inherited;
+ Create( AType, '' )
+end;
+
+constructor TTransportException.Create(AType: TExceptionType;
+ const msg: string);
+begin
+ inherited Create(msg);
+ FType := AType;
+end;
+
+constructor TTransportException.Create(const msg: string);
+begin
+ inherited Create(msg);
+end;
+
+{ TTransportFactoryImpl }
+
+function TTransportFactoryImpl.GetTransport( const ATrans: ITransport): ITransport;
+begin
+ Result := ATrans;
+end;
+
+{ TServerSocket }
+
+constructor TServerSocketImpl.Create( const AServer: TTcpServer; AClientTimeout: Integer);
+begin
+ inherited Create;
+ FServer := AServer;
+ FClientTimeout := AClientTimeout;
+end;
+
+constructor TServerSocketImpl.Create(APort, AClientTimeout: Integer; AUseBufferedSockets: Boolean);
+begin
+ inherited Create;
+ FPort := APort;
+ FClientTimeout := AClientTimeout;
+ FUseBufferedSocket := AUseBufferedSockets;
+ FOwnsServer := True;
+ FServer := TTcpServer.Create( nil );
+ FServer.BlockMode := bmBlocking;
+{$IF CompilerVersion >= 21.0}
+ FServer.LocalPort := AnsiString( IntToStr( FPort));
+{$ELSE}
+ FServer.LocalPort := IntToStr( FPort);
+{$IFEND}
+end;
+
+destructor TServerSocketImpl.Destroy;
+begin
+ if FOwnsServer then begin
+ FServer.Free;
+ FServer := nil;
+ end;
+ inherited;
+end;
+
+function TServerSocketImpl.Accept( const fnAccepting: TProc): ITransport;
+var
+ client : TCustomIpClient;
+ trans : IStreamTransport;
+begin
+ if FServer = nil then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+ 'No underlying server socket.');
+ end;
+
+ client := nil;
+ try
+ client := TCustomIpClient.Create(nil);
+
+ if Assigned(fnAccepting)
+ then fnAccepting();
+
+ if not FServer.Accept( client) then
+ begin
+ client.Free;
+ Result := nil;
+ Exit;
+ end;
+
+ if client = nil then
+ begin
+ Result := nil;
+ Exit;
+ end;
+
+ trans := TSocketImpl.Create( client, TRUE, FClientTimeout);
+ client := nil; // trans owns it now
+
+ if FUseBufferedSocket
+ then result := TBufferedTransportImpl.Create( trans)
+ else result := trans;
+
+ except
+ on E: Exception do begin
+ client.Free;
+ raise TTransportException.Create( E.ToString );
+ end;
+ end;
+end;
+
+procedure TServerSocketImpl.Listen;
+begin
+ if FServer <> nil then
+ begin
+ try
+ FServer.Active := True;
+ except
+ on E: Exception do
+ begin
+ raise TTransportException.Create('Could not accept on listening socket: ' + E.Message);
+ end;
+ end;
+ end;
+end;
+
+procedure TServerSocketImpl.Close;
+begin
+ if FServer <> nil then
+ begin
+ try
+ FServer.Active := False;
+ except
+ on E: Exception do
+ begin
+ raise TTransportException.Create('Error on closing socket : ' + E.Message);
+ end;
+ end;
+ end;
+end;
+
+{ TSocket }
+
+constructor TSocketImpl.Create( const AClient : TCustomIpClient; aOwnsClient : Boolean; ATimeout: Integer = 0);
+var stream : IThriftStream;
+begin
+ FClient := AClient;
+ FTimeout := ATimeout;
+ FOwnsClient := aOwnsClient;
+ stream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
+ inherited Create( stream, stream);
+end;
+
+constructor TSocketImpl.Create(const AHost: string; APort, ATimeout: Integer);
+begin
+ inherited Create(nil,nil);
+ FHost := AHost;
+ FPort := APort;
+ FTimeout := ATimeout;
+ InitSocket;
+end;
+
+destructor TSocketImpl.Destroy;
+begin
+ if FOwnsClient
+ then FreeAndNil( FClient);
+ inherited;
+end;
+
+procedure TSocketImpl.Close;
+begin
+ inherited Close;
+ if FOwnsClient
+ then FreeAndNil( FClient);
+end;
+
+function TSocketImpl.GetIsOpen: Boolean;
+begin
+ Result := (FClient <> nil) and FClient.Connected;
+end;
+
+procedure TSocketImpl.InitSocket;
+var
+ stream : IThriftStream;
+begin
+ if FOwnsClient
+ then FreeAndNil( FClient)
+ else FClient := nil;
+
+ FClient := TTcpClient.Create( nil);
+ FOwnsClient := True;
+
+ stream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
+ FInputStream := stream;
+ FOutputStream := stream;
+end;
+
+procedure TSocketImpl.Open;
+begin
+ if IsOpen then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.AlreadyOpen,
+ 'Socket already connected');
+ end;
+
+ if FHost = '' then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+ 'Cannot open null host');
+ end;
+
+ if Port <= 0 then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen,
+ 'Cannot open without port');
+ end;
+
+ if FClient = nil then
+ begin
+ InitSocket;
+ end;
+
+ FClient.RemoteHost := TSocketHost( Host);
+ FClient.RemotePort := TSocketPort( IntToStr( Port));
+ FClient.Connect;
+
+ FInputStream := TTcpSocketStreamImpl.Create( FClient, FTimeout);
+ FOutputStream := FInputStream;
+end;
+
+{ TBufferedStream }
+
+procedure TBufferedStreamImpl.Close;
+begin
+ Flush;
+ FStream := nil;
+
+ FReadBuffer.Free;
+ FReadBuffer := nil;
+
+ FWriteBuffer.Free;
+ FWriteBuffer := nil;
+end;
+
+constructor TBufferedStreamImpl.Create( const AStream: IThriftStream; ABufSize: Integer);
+begin
+ inherited Create;
+ FStream := AStream;
+ FBufSize := ABufSize;
+ FReadBuffer := TMemoryStream.Create;
+ FWriteBuffer := TMemoryStream.Create;
+end;
+
+destructor TBufferedStreamImpl.Destroy;
+begin
+ Close;
+ inherited;
+end;
+
+procedure TBufferedStreamImpl.Flush;
+var
+ buf : TBytes;
+ len : Integer;
+begin
+ if IsOpen then
+ begin
+ len := FWriteBuffer.Size;
+ if len > 0 then
+ begin
+ SetLength( buf, len );
+ FWriteBuffer.Position := 0;
+ FWriteBuffer.Read( Pointer(@buf[0])^, len );
+ FStream.Write( buf, 0, len );
+ end;
+ FWriteBuffer.Clear;
+ end;
+end;
+
+function TBufferedStreamImpl.IsOpen: Boolean;
+begin
+ Result := (FWriteBuffer <> nil)
+ and (FReadBuffer <> nil)
+ and (FStream <> nil);
+end;
+
+procedure TBufferedStreamImpl.Open;
+begin
+
+end;
+
+function TBufferedStreamImpl.Read( var buffer: TBytes; offset: Integer; count: Integer): Integer;
+var
+ nRead : Integer;
+ tempbuf : TBytes;
+begin
+ inherited;
+ Result := 0;
+ if IsOpen then
+ begin
+ while count > 0 do begin
+
+ if FReadBuffer.Position >= FReadBuffer.Size then
+ begin
+ FReadBuffer.Clear;
+ SetLength( tempbuf, FBufSize);
+ nRead := FStream.Read( tempbuf, 0, FBufSize );
+ if nRead = 0 then Break; // avoid infinite loop
+
+ FReadBuffer.WriteBuffer( Pointer(@tempbuf[0])^, nRead );
+ FReadBuffer.Position := 0;
+ end;
+
+ if FReadBuffer.Position < FReadBuffer.Size then
+ begin
+ nRead := Min( FReadBuffer.Size - FReadBuffer.Position, count);
+ Inc( Result, FReadBuffer.Read( Pointer(@buffer[offset])^, nRead));
+ Dec( count, nRead);
+ Inc( offset, nRead);
+ end;
+ end;
+ end;
+end;
+
+function TBufferedStreamImpl.ToArray: TBytes;
+var
+ len : Integer;
+begin
+ len := 0;
+
+ if IsOpen then
+ begin
+ len := FReadBuffer.Size;
+ end;
+
+ SetLength( Result, len);
+
+ if len > 0 then
+ begin
+ FReadBuffer.Position := 0;
+ FReadBuffer.Read( Pointer(@Result[0])^, len );
+ end;
+end;
+
+procedure TBufferedStreamImpl.Write( const buffer: TBytes; offset: Integer; count: Integer);
+begin
+ inherited;
+ if count > 0 then
+ begin
+ if IsOpen then
+ begin
+ FWriteBuffer.Write( Pointer(@buffer[offset])^, count );
+ if FWriteBuffer.Size > FBufSize then
+ begin
+ Flush;
+ end;
+ end;
+ end;
+end;
+
+{ TStreamTransportImpl }
+
+procedure TStreamTransportImpl.Close;
+begin
+ if FInputStream <> FOutputStream then
+ begin
+ if FInputStream <> nil then
+ begin
+ FInputStream := nil;
+ end;
+ if FOutputStream <> nil then
+ begin
+ FOutputStream := nil;
+ end;
+ end else
+ begin
+ FInputStream := nil;
+ FOutputStream := nil;
+ end;
+end;
+
+constructor TStreamTransportImpl.Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
+begin
+ inherited Create;
+ FInputStream := AInputStream;
+ FOutputStream := AOutputStream;
+end;
+
+destructor TStreamTransportImpl.Destroy;
+begin
+ FInputStream := nil;
+ FOutputStream := nil;
+ inherited;
+end;
+
+procedure TStreamTransportImpl.Flush;
+begin
+ if FOutputStream = nil then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot flush null outputstream' );
+ end;
+
+ FOutputStream.Flush;
+end;
+
+function TStreamTransportImpl.GetInputStream: IThriftStream;
+begin
+ Result := FInputStream;
+end;
+
+function TStreamTransportImpl.GetIsOpen: Boolean;
+begin
+ Result := True;
+end;
+
+function TStreamTransportImpl.GetOutputStream: IThriftStream;
+begin
+ Result := FInputStream;
+end;
+
+procedure TStreamTransportImpl.Open;
+begin
+
+end;
+
+function TStreamTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
+begin
+ if FInputStream = nil then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot read from null inputstream' );
+ end;
+ Result := FInputStream.Read( buf, off, len );
+end;
+
+procedure TStreamTransportImpl.Write(const buf: TBytes; off, len: Integer);
+begin
+ if FOutputStream = nil then
+ begin
+ raise TTransportException.Create( TTransportException.TExceptionType.NotOpen, 'Cannot write to null outputstream' );
+ end;
+
+ FOutputStream.Write( buf, off, len );
+end;
+
+{ TBufferedTransportImpl }
+
+constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport);
+begin
+ //no inherited;
+ Create( ATransport, 1024 );
+end;
+
+procedure TBufferedTransportImpl.Close;
+begin
+ FTransport.Close;
+end;
+
+constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport;
+ ABufSize: Integer);
+begin
+ inherited Create;
+ FTransport := ATransport;
+ FBufSize := ABufSize;
+ InitBuffers;
+end;
+
+procedure TBufferedTransportImpl.Flush;
+begin
+ if FOutputBuffer <> nil then
+ begin
+ FOutputBuffer.Flush;
+ end;
+end;
+
+function TBufferedTransportImpl.GetIsOpen: Boolean;
+begin
+ Result := FTransport.IsOpen;
+end;
+
+function TBufferedTransportImpl.GetUnderlyingTransport: ITransport;
+begin
+ Result := FTransport;
+end;
+
+procedure TBufferedTransportImpl.InitBuffers;
+begin
+ if FTransport.InputStream <> nil then
+ begin
+ FInputBuffer := TBufferedStreamImpl.Create( FTransport.InputStream, FBufSize );
+ end;
+ if FTransport.OutputStream <> nil then
+ begin
+ FOutputBuffer := TBufferedStreamImpl.Create( FTransport.OutputStream, FBufSize );
+ end;
+end;
+
+procedure TBufferedTransportImpl.Open;
+begin
+ FTransport.Open
+end;
+
+function TBufferedTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
+begin
+ Result := 0;
+ if FInputBuffer <> nil then
+ begin
+ Result := FInputBuffer.Read( buf, off, len );
+ end;
+end;
+
+procedure TBufferedTransportImpl.Write(const buf: TBytes; off, len: Integer);
+begin
+ if FOutputBuffer <> nil then
+ begin
+ FOutputBuffer.Write( buf, off, len );
+ end;
+end;
+
+{ TFramedTransportImpl }
+
+{$IF CompilerVersion < 21.0}
+procedure TFramedTransportImpl_Initialize;
+begin
+ SetLength( TFramedTransportImpl.FHeader_Dummy, TFramedTransportImpl.FHeaderSize);
+ FillChar( TFramedTransportImpl.FHeader_Dummy[0],
+ Length( TFramedTransportImpl.FHeader_Dummy) * SizeOf( Byte ), 0);
+end;
+{$ELSE}
+class constructor TFramedTransportImpl.Create;
+begin
+ SetLength( FHeader_Dummy, FHeaderSize);
+ FillChar( FHeader_Dummy[0], Length( FHeader_Dummy) * SizeOf( Byte ), 0);
+end;
+{$IFEND}
+
+constructor TFramedTransportImpl.Create;
+begin
+ inherited Create;
+ InitWriteBuffer;
+end;
+
+procedure TFramedTransportImpl.Close;
+begin
+ FTransport.Close;
+end;
+
+constructor TFramedTransportImpl.Create( const ATrans: ITransport);
+begin
+ inherited Create;
+ InitWriteBuffer;
+ FTransport := ATrans;
+end;
+
+destructor TFramedTransportImpl.Destroy;
+begin
+ FWriteBuffer.Free;
+ FReadBuffer.Free;
+ inherited;
+end;
+
+procedure TFramedTransportImpl.Flush;
+var
+ buf : TBytes;
+ len : Integer;
+ data_len : Integer;
+
+begin
+ len := FWriteBuffer.Size;
+ SetLength( buf, len);
+ if len > 0 then
+ begin
+ System.Move( FWriteBuffer.Memory^, buf[0], len );
+ end;
+
+ data_len := len - FHeaderSize;
+ if (data_len < 0) then
+ begin
+ raise Exception.Create( 'TFramedTransport.Flush: data_len < 0' );
+ end;
+
+ InitWriteBuffer;
+
+ buf[0] := Byte($FF and (data_len shr 24));
+ buf[1] := Byte($FF and (data_len shr 16));
+ buf[2] := Byte($FF and (data_len shr 8));
+ buf[3] := Byte($FF and data_len);
+
+ FTransport.Write( buf, 0, len );
+ FTransport.Flush;
+end;
+
+function TFramedTransportImpl.GetIsOpen: Boolean;
+begin
+ Result := FTransport.IsOpen;
+end;
+
+type
+ TAccessMemoryStream = class(TMemoryStream)
+ end;
+
+procedure TFramedTransportImpl.InitWriteBuffer;
+begin
+ FWriteBuffer.Free;
+ FWriteBuffer := TMemoryStream.Create;
+ TAccessMemoryStream(FWriteBuffer).Capacity := 1024;
+ FWriteBuffer.Write( Pointer(@FHeader_Dummy[0])^, FHeaderSize);
+end;
+
+procedure TFramedTransportImpl.Open;
+begin
+ FTransport.Open;
+end;
+
+function TFramedTransportImpl.Read(var buf: TBytes; off, len: Integer): Integer;
+var
+ got : Integer;
+begin
+ if FReadBuffer <> nil then
+ begin
+ if len > 0
+ then got := FReadBuffer.Read( Pointer(@buf[off])^, len )
+ else got := 0;
+ if got > 0 then
+ begin
+ Result := got;
+ Exit;
+ end;
+ end;
+
+ ReadFrame;
+ if len > 0
+ then Result := FReadBuffer.Read( Pointer(@buf[off])^, len)
+ else Result := 0;
+end;
+
+procedure TFramedTransportImpl.ReadFrame;
+var
+ i32rd : TBytes;
+ size : Integer;
+ buff : TBytes;
+begin
+ SetLength( i32rd, FHeaderSize );
+ FTransport.ReadAll( i32rd, 0, FHeaderSize);
+ size :=
+ ((i32rd[0] and $FF) shl 24) or
+ ((i32rd[1] and $FF) shl 16) or
+ ((i32rd[2] and $FF) shl 8) or
+ (i32rd[3] and $FF);
+ SetLength( buff, size );
+ FTransport.ReadAll( buff, 0, size );
+ FReadBuffer.Free;
+ FReadBuffer := TMemoryStream.Create;
+ FReadBuffer.Write( Pointer(@buff[0])^, size );
+ FReadBuffer.Position := 0;
+end;
+
+procedure TFramedTransportImpl.Write(const buf: TBytes; off, len: Integer);
+begin
+ if len > 0
+ then FWriteBuffer.Write( Pointer(@buf[off])^, len );
+end;
+
+{ TFramedTransport.TFactory }
+
+function TFramedTransportImpl.TFactory.GetTransport( const ATrans: ITransport): ITransport;
+begin
+ Result := TFramedTransportImpl.Create( ATrans );
+end;
+
+{ TTcpSocketStreamImpl }
+
+procedure TTcpSocketStreamImpl.Close;
+begin
+ FTcpClient.Close;
+end;
+
+constructor TTcpSocketStreamImpl.Create( const ATcpClient: TCustomIpClient; const aTimeout : Integer);
+begin
+ inherited Create;
+ FTcpClient := ATcpClient;
+ FTimeout := aTimeout;
+end;
+
+procedure TTcpSocketStreamImpl.Flush;
+begin
+
+end;
+
+function TTcpSocketStreamImpl.IsOpen: Boolean;
+begin
+ Result := FTcpClient.Active;
+end;
+
+procedure TTcpSocketStreamImpl.Open;
+begin
+ FTcpClient.Open;
+end;
+
+
+function TTcpSocketStreamImpl.Select( ReadReady, WriteReady, ExceptFlag: PBoolean;
+ TimeOut: Integer; var wsaError : Integer): Integer;
+var
+ ReadFds: TFDset;
+ ReadFdsptr: PFDset;
+ WriteFds: TFDset;
+ WriteFdsptr: PFDset;
+ ExceptFds: TFDset;
+ ExceptFdsptr: PFDset;
+ tv: timeval;
+ Timeptr: PTimeval;
+ socket : TSocket;
+begin
+ if not FTcpClient.Active then begin
+ wsaError := WSAEINVAL;
+ Exit( SOCKET_ERROR);
+ end;
+
+ socket := FTcpClient.Handle;
+
+ if Assigned(ReadReady) then
+ begin
+ ReadFdsptr := @ReadFds;
+ FD_ZERO(ReadFds);
+ FD_SET(socket, ReadFds);
+ end
+ else
+ ReadFdsptr := nil;
+
+ if Assigned(WriteReady) then
+ begin
+ WriteFdsptr := @WriteFds;
+ FD_ZERO(WriteFds);
+ FD_SET(socket, WriteFds);
+ end
+ else
+ WriteFdsptr := nil;
+
+ if Assigned(ExceptFlag) then
+ begin
+ ExceptFdsptr := @ExceptFds;
+ FD_ZERO(ExceptFds);
+ FD_SET(socket, ExceptFds);
+ end
+ else
+ ExceptFdsptr := nil;
+
+ if TimeOut >= 0 then
+ begin
+ tv.tv_sec := TimeOut div 1000;
+ tv.tv_usec := 1000 * (TimeOut mod 1000);
+ Timeptr := @tv;
+ end
+ else
+ Timeptr := nil; // wait forever
+
+ wsaError := 0;
+ try
+{$IFDEF MSWINDOWS}
+ result := WinSock.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
+{$ENDIF}
+{$IFDEF LINUX}
+ result := Libc.select(socket + 1, ReadFdsptr, WriteFdsptr, ExceptFdsptr, Timeptr);
+{$ENDIF}
+ if result = SOCKET_ERROR
+ then wsaError := WSAGetLastError;
+
+ except
+ result := SOCKET_ERROR;
+ end;
+
+ if Assigned(ReadReady) then
+ ReadReady^ := FD_ISSET(socket, ReadFds);
+ if Assigned(WriteReady) then
+ WriteReady^ := FD_ISSET(socket, WriteFds);
+ if Assigned(ExceptFlag) then
+ ExceptFlag^ := FD_ISSET(socket, ExceptFds);
+end;
+
+function TTcpSocketStreamImpl.WaitForData( TimeOut : Integer; pBuf : Pointer;
+ DesiredBytes : Integer;
+ var wsaError : Integer): TWaitForData;
+var bCanRead, bError : Boolean;
+ retval : Integer;
+begin
+ // The select function returns the total number of socket handles that are ready
+ // and contained in the fd_set structures, zero if the time limit expired,
+ // or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR,
+ // WSAGetLastError can be used to retrieve a specific error code.
+ retval := Self.Select( @bCanRead, nil, @bError, TimeOut, wsaError);
+ if retval = SOCKET_ERROR
+ then Exit( TWaitForData.wfd_Error);
+ if (retval = 0) or not bCanRead
+ then Exit( TWaitForData.wfd_Timeout);
+
+ // recv() returns the number of bytes received, or -1 if an error occurred.
+ // The return value will be 0 when the peer has performed an orderly shutdown.
+ retval := recv( FTcpClient.Handle, pBuf^, DesiredBytes, WinSock.MSG_PEEK);
+ if retval <= 0
+ then Exit( TWaitForData.wfd_Error);
+
+ // Enough data ready to be read?
+ if retval = DesiredBytes
+ then result := TWaitForData.wfd_HaveData
+ else result := TWaitForData.wfd_Timeout;
+end;
+
+function TTcpSocketStreamImpl.Read(var buffer: TBytes; offset, count: Integer): Integer;
+var wfd : TWaitForData;
+ wsaError : Integer;
+ pDest : Pointer;
+const
+ SLEEP_TIME = 200;
+begin
+ inherited;
+
+ pDest := Pointer(@buffer[offset]);
+
+ while TRUE do begin
+ if FTimeout > 0
+ then wfd := WaitForData( FTimeout, pDest, count, wsaError)
+ else wfd := WaitForData( SLEEP_TIME, pDest, count, wsaError);
+
+ case wfd of
+ TWaitForData.wfd_Error : Exit(0);
+ TWaitForData.wfd_HaveData : Break;
+ TWaitForData.wfd_Timeout : begin
+ if (FTimeout > 0)
+ then raise TTransportException.Create( TTransportException.TExceptionType.TimedOut,
+ SysErrorMessage(Cardinal(wsaError)));
+ end;
+ else
+ ASSERT( FALSE);
+ end;
+ end;
+
+ Result := FTcpClient.ReceiveBuf( pDest^, count);
+end;
+
+function TTcpSocketStreamImpl.ToArray: TBytes;
+var
+ len : Integer;
+begin
+ len := 0;
+ if IsOpen then
+ begin
+ len := FTcpClient.BytesReceived;
+ end;
+
+ SetLength( Result, len );
+
+ if len > 0 then
+ begin
+ FTcpClient.ReceiveBuf( Pointer(@Result[0])^, len);
+ end;
+end;
+
+procedure TTcpSocketStreamImpl.Write(const buffer: TBytes; offset, count: Integer);
+var bCanWrite, bError : Boolean;
+ retval, wsaError : Integer;
+begin
+ inherited;
+
+ if not FTcpClient.Active
+ then raise TTransportException.Create( TTransportException.TExceptionType.NotOpen);
+
+ // The select function returns the total number of socket handles that are ready
+ // and contained in the fd_set structures, zero if the time limit expired,
+ // or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR,
+ // WSAGetLastError can be used to retrieve a specific error code.
+ retval := Self.Select( nil, @bCanWrite, @bError, FTimeOut, wsaError);
+ if retval = SOCKET_ERROR
+ then raise TTransportException.Create( TTransportException.TExceptionType.Unknown,
+ SysErrorMessage(Cardinal(wsaError)));
+ if (retval = 0)
+ then raise TTransportException.Create( TTransportException.TExceptionType.TimedOut);
+ if bError or not bCanWrite
+ then raise TTransportException.Create( TTransportException.TExceptionType.Unknown);
+
+ FTcpClient.SendBuf( Pointer(@buffer[offset])^, count);
+end;
+
+{$IF CompilerVersion < 21.0}
+initialization
+begin
+ TFramedTransportImpl_Initialize;
+end;
+{$IFEND}
+
+
+end.
diff --git a/lib/delphi/src/Thrift.TypeRegistry.pas b/lib/delphi/src/Thrift.TypeRegistry.pas
index cc22952..c18e97f 100644
--- a/lib/delphi/src/Thrift.TypeRegistry.pas
+++ b/lib/delphi/src/Thrift.TypeRegistry.pas
@@ -1,95 +1,95 @@
-(*
- * 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.
- *)
-
-unit Thrift.TypeRegistry;
-
-interface
-
-uses
- Generics.Collections, TypInfo,
- Thrift.Protocol;
-
-type
- TFactoryMethod<T> = function:T;
-
- TypeRegistry = class
- private
- class var FTypeInfoToFactoryLookup : TDictionary<Pointer, Pointer>;
- public
- class constructor Create;
- class destructor Destroy;
- class procedure RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);
- class function Construct<F>: F;
- class function ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;
- end;
-
-implementation
-
-
-{ TypeRegistration }
-
-class constructor TypeRegistry.Create;
-begin
- FTypeInfoToFactoryLookup := TDictionary<Pointer, Pointer>.Create;
-end;
-
-class destructor TypeRegistry.Destroy;
-begin
- FTypeInfoToFactoryLookup.Free;
-end;
-
-class procedure TypeRegistry.RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);
-var
- TypeInfo : Pointer;
-begin
- TypeInfo := System.TypeInfo(F);
-
- if (TypeInfo <> nil) and (PTypeInfo(TypeInfo).Kind = tkInterface)
- then FTypeInfoToFactoryLookup.AddOrSetValue(TypeInfo, @aFactoryMethod);
-end;
-
-class function TypeRegistry.Construct<F>: F;
-var
- TypeInfo : PTypeInfo;
- Factory : Pointer;
-begin
- Result := default(F);
-
- TypeInfo := System.TypeInfo(F);
-
- if Assigned(TypeInfo) and (TypeInfo.Kind = tkInterface)
- then begin
- if FTypeInfoToFactoryLookup.TryGetValue(TypeInfo, Factory)
- then Result := TFactoryMethod<F>(Factory)();
- end;
-end;
-
-class function TypeRegistry.ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;
-var
- Factory : Pointer;
-begin
- Result := nil;
- if FTypeInfoToFactoryLookup.TryGetValue(aTypeInfo, Factory)
- then Result := IBase(TFactoryMethod<IBase>(Factory)());
-end;
-
-
-
-
-end.
+(*
+ * 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.
+ *)
+
+unit Thrift.TypeRegistry;
+
+interface
+
+uses
+ Generics.Collections, TypInfo,
+ Thrift.Protocol;
+
+type
+ TFactoryMethod<T> = function:T;
+
+ TypeRegistry = class
+ private
+ class var FTypeInfoToFactoryLookup : TDictionary<Pointer, Pointer>;
+ public
+ class constructor Create;
+ class destructor Destroy;
+ class procedure RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);
+ class function Construct<F>: F;
+ class function ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;
+ end;
+
+implementation
+
+
+{ TypeRegistration }
+
+class constructor TypeRegistry.Create;
+begin
+ FTypeInfoToFactoryLookup := TDictionary<Pointer, Pointer>.Create;
+end;
+
+class destructor TypeRegistry.Destroy;
+begin
+ FTypeInfoToFactoryLookup.Free;
+end;
+
+class procedure TypeRegistry.RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);
+var
+ TypeInfo : Pointer;
+begin
+ TypeInfo := System.TypeInfo(F);
+
+ if (TypeInfo <> nil) and (PTypeInfo(TypeInfo).Kind = tkInterface)
+ then FTypeInfoToFactoryLookup.AddOrSetValue(TypeInfo, @aFactoryMethod);
+end;
+
+class function TypeRegistry.Construct<F>: F;
+var
+ TypeInfo : PTypeInfo;
+ Factory : Pointer;
+begin
+ Result := default(F);
+
+ TypeInfo := System.TypeInfo(F);
+
+ if Assigned(TypeInfo) and (TypeInfo.Kind = tkInterface)
+ then begin
+ if FTypeInfoToFactoryLookup.TryGetValue(TypeInfo, Factory)
+ then Result := TFactoryMethod<F>(Factory)();
+ end;
+end;
+
+class function TypeRegistry.ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;
+var
+ Factory : Pointer;
+begin
+ Result := nil;
+ if FTypeInfoToFactoryLookup.TryGetValue(aTypeInfo, Factory)
+ then Result := IBase(TFactoryMethod<IBase>(Factory)());
+end;
+
+
+
+
+end.
diff --git a/lib/delphi/src/Thrift.Utils.pas b/lib/delphi/src/Thrift.Utils.pas
index ec8190c..58ffe79 100644
--- a/lib/delphi/src/Thrift.Utils.pas
+++ b/lib/delphi/src/Thrift.Utils.pas
@@ -1,118 +1,118 @@
-(*
- * 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.
- *)
-
-unit Thrift.Utils;
-
-interface
-
-uses
- Classes, Windows, SysUtils, SyncObjs;
-
-type
- IOverlappedHelper = interface
- ['{A1832EFA-2E02-4884-8F09-F0A0277157FA}']
- function Overlapped : TOverlapped;
- function OverlappedPtr : POverlapped;
- function WaitHandle : THandle;
- function WaitFor(dwTimeout: DWORD) : DWORD;
- end;
-
- TOverlappedHelperImpl = class( TInterfacedObject, IOverlappedHelper)
- strict protected
- FOverlapped : TOverlapped;
- FEvent : TEvent;
-
- // IOverlappedHelper
- function Overlapped : TOverlapped;
- function OverlappedPtr : POverlapped;
- function WaitHandle : THandle;
- function WaitFor(dwTimeout: DWORD) : DWORD;
- public
- constructor Create;
- destructor Destroy; override;
- end;
-
-
-
-function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;
-
-implementation
-
-
-function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;
-begin
- if B then
- Result := TrueValue
- else
- Result := FalseValue;
-end;
-
-
-{ TOverlappedHelperImpl }
-
-constructor TOverlappedHelperImpl.Create;
-begin
- inherited Create;
- FillChar( FOverlapped, SizeOf(FOverlapped), 0);
- FEvent := TEvent.Create( nil, TRUE, FALSE, ''); // always ManualReset, see MSDN
- FOverlapped.hEvent := FEvent.Handle;
-end;
-
-
-
-destructor TOverlappedHelperImpl.Destroy;
-begin
- try
- FOverlapped.hEvent := 0;
- FreeAndNil( FEvent);
-
- finally
- inherited Destroy;
- end;
-
-end;
-
-
-function TOverlappedHelperImpl.Overlapped : TOverlapped;
-begin
- result := FOverlapped;
-end;
-
-
-function TOverlappedHelperImpl.OverlappedPtr : POverlapped;
-begin
- result := @FOverlapped;
-end;
-
-
-function TOverlappedHelperImpl.WaitHandle : THandle;
-begin
- result := FOverlapped.hEvent;
-end;
-
-
-function TOverlappedHelperImpl.WaitFor( dwTimeout : DWORD) : DWORD;
-begin
- result := WaitForSingleObject( FOverlapped.hEvent, dwTimeout);
-end;
-
-
-
-
-end.
+(*
+ * 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.
+ *)
+
+unit Thrift.Utils;
+
+interface
+
+uses
+ Classes, Windows, SysUtils, SyncObjs;
+
+type
+ IOverlappedHelper = interface
+ ['{A1832EFA-2E02-4884-8F09-F0A0277157FA}']
+ function Overlapped : TOverlapped;
+ function OverlappedPtr : POverlapped;
+ function WaitHandle : THandle;
+ function WaitFor(dwTimeout: DWORD) : DWORD;
+ end;
+
+ TOverlappedHelperImpl = class( TInterfacedObject, IOverlappedHelper)
+ strict protected
+ FOverlapped : TOverlapped;
+ FEvent : TEvent;
+
+ // IOverlappedHelper
+ function Overlapped : TOverlapped;
+ function OverlappedPtr : POverlapped;
+ function WaitHandle : THandle;
+ function WaitFor(dwTimeout: DWORD) : DWORD;
+ public
+ constructor Create;
+ destructor Destroy; override;
+ end;
+
+
+
+function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;
+
+implementation
+
+
+function IfValue(B: Boolean; const TrueValue, FalseValue: WideString): string;
+begin
+ if B then
+ Result := TrueValue
+ else
+ Result := FalseValue;
+end;
+
+
+{ TOverlappedHelperImpl }
+
+constructor TOverlappedHelperImpl.Create;
+begin
+ inherited Create;
+ FillChar( FOverlapped, SizeOf(FOverlapped), 0);
+ FEvent := TEvent.Create( nil, TRUE, FALSE, ''); // always ManualReset, see MSDN
+ FOverlapped.hEvent := FEvent.Handle;
+end;
+
+
+
+destructor TOverlappedHelperImpl.Destroy;
+begin
+ try
+ FOverlapped.hEvent := 0;
+ FreeAndNil( FEvent);
+
+ finally
+ inherited Destroy;
+ end;
+
+end;
+
+
+function TOverlappedHelperImpl.Overlapped : TOverlapped;
+begin
+ result := FOverlapped;
+end;
+
+
+function TOverlappedHelperImpl.OverlappedPtr : POverlapped;
+begin
+ result := @FOverlapped;
+end;
+
+
+function TOverlappedHelperImpl.WaitHandle : THandle;
+begin
+ result := FOverlapped.hEvent;
+end;
+
+
+function TOverlappedHelperImpl.WaitFor( dwTimeout : DWORD) : DWORD;
+begin
+ result := WaitForSingleObject( FOverlapped.hEvent, dwTimeout);
+end;
+
+
+
+
+end.
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index cbd825e..dc39828 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -825,7 +825,7 @@
Expect( crazy.Xtructs.Count = 2, 'crazy.Xtructs.Count = '+IntToStr(crazy.Xtructs.Count));
goodbye := crazy.Xtructs[0]; // lists are ordered, so we are allowed to assume this order
- hello := crazy.Xtructs[1];
+ hello := crazy.Xtructs[1];
Expect( goodbye.String_thing = 'Goodbye4', 'goodbye.String_thing = "'+goodbye.String_thing+'"');
Expect( goodbye.Byte_thing = 4, 'goodbye.Byte_thing = '+IntToStr(goodbye.Byte_thing));
@@ -878,10 +878,10 @@
Expect( i.String_thing = 'run out of beer', 'i.String_thing = "' +i.String_thing+ '"');
Expect( i.__isset_String_thing, 'i.__isset_String_thing = '+BoolToString(i.__isset_String_thing));
{ this is not necessarily true, these fields are default-serialized
- Expect( not i.__isset_Byte_thing, 'i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing));
+ Expect( not i.__isset_Byte_thing, 'i.__isset_Byte_thing = '+BoolToString(i.__isset_Byte_thing));
Expect( not i.__isset_I32_thing, 'i.__isset_I32_thing = '+BoolToString(i.__isset_I32_thing));
Expect( not i.__isset_I64_thing, 'i.__isset_I64_thing = '+BoolToString(i.__isset_I64_thing));
- }
+ }
except
on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'"');
end;
@@ -915,7 +915,7 @@
Expect( not x.Struct_thing.__isset_Byte_thing, 'x.Struct_thing.__isset_Byte_thing = '+BoolToString(x.Struct_thing.__isset_Byte_thing));
Expect( not x.Struct_thing.__isset_I32_thing, 'x.Struct_thing.__isset_I32_thing = '+BoolToString(x.Struct_thing.__isset_I32_thing));
Expect( not x.Struct_thing.__isset_I64_thing, 'x.Struct_thing.__isset_I64_thing = '+BoolToString(x.Struct_thing.__isset_I64_thing));
- }
+ }
end;
on e:Exception do Expect( FALSE, 'Unexpected exception "'+e.ClassName+'"');
end;
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index 286047d..35f1ac8 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -316,7 +316,7 @@
Console.WriteLine('testMultiException(' + arg0 + ', ' + arg1 + ')');
if ( arg0 = 'Xception') then
begin
- raise TXception.Create( 1001, 'This is an Xception'); // test the new rich CTOR
+ raise TXception.Create( 1001, 'This is an Xception'); // test the new rich CTOR
end else
if ( arg0 = 'Xception2') then
begin
@@ -473,8 +473,8 @@
//This is a simple example and does not include elevation or other
//advanced features.
var pi : PROCESS_INFORMATION;
- si : STARTUPINFO;
- sArg, sHandles, sCmdLine : string;
+ si : STARTUPINFO;
+ sArg, sHandles, sCmdLine : string;
i : Integer;
begin
GetStartupInfo( si); //set startupinfo for the spawned process
@@ -505,7 +505,7 @@
Win32Check( CreateProcess( nil, PChar(sCmdLine), nil,nil,TRUE,0,nil,nil,si,pi));
CloseHandle( pi.hThread);
- CloseHandle( pi.hProcess);
+ CloseHandle( pi.hProcess);
end;
diff --git a/lib/delphi/test/TestServerEvents.pas b/lib/delphi/test/TestServerEvents.pas
index 8e931c4..2e776d2 100644
--- a/lib/delphi/test/TestServerEvents.pas
+++ b/lib/delphi/test/TestServerEvents.pas
@@ -47,128 +47,128 @@
TProcessorEventsImpl = class( TInterfacedObject, IProcessorEvents)
- protected
- FReqs : Integer;
- // IProcessorEvents
- procedure Processing( const transport : ITransport);
+ protected
+ FReqs : Integer;
+ // IProcessorEvents
+ procedure Processing( const transport : ITransport);
function CreateRequestContext( const aFunctionName : string) : IRequestEvents;
procedure CleanupContext;
public
constructor Create;
- end;
+ end;
TServerEventsImpl = class( TInterfacedObject, IServerEvents)
- protected
- // IServerEvents
- procedure PreServe;
- procedure PreAccept;
- function CreateProcessingContext( const input, output : IProtocol) : IProcessorEvents;
- end;
+ protected
+ // IServerEvents
+ procedure PreServe;
+ procedure PreAccept;
+ function CreateProcessingContext( const input, output : IProtocol) : IProcessorEvents;
+ end;
implementation
{ TServerEventsImpl }
-
+
procedure TServerEventsImpl.PreServe;
-begin
- Console.WriteLine('ServerEvents: Server starting to serve requests');
-end;
-
-
+begin
+ Console.WriteLine('ServerEvents: Server starting to serve requests');
+end;
+
+
procedure TServerEventsImpl.PreAccept;
-begin
- Console.WriteLine('ServerEvents: Server transport is ready to accept incoming calls');
-end;
-
-
+begin
+ Console.WriteLine('ServerEvents: Server transport is ready to accept incoming calls');
+end;
+
+
function TServerEventsImpl.CreateProcessingContext(const input, output: IProtocol): IProcessorEvents;
-begin
- result := TProcessorEventsImpl.Create;
-end;
-
-
+begin
+ result := TProcessorEventsImpl.Create;
+end;
+
+
{ TProcessorEventsImpl }
-
+
constructor TProcessorEventsImpl.Create;
-begin
- inherited Create;
- FReqs := 0;
- Console.WriteLine('ProcessorEvents: Client connected, processing begins');
-end;
-
-procedure TProcessorEventsImpl.Processing(const transport: ITransport);
-begin
- Console.WriteLine('ProcessorEvents: Processing of incoming request begins');
-end;
-
-
-function TProcessorEventsImpl.CreateRequestContext( const aFunctionName: string): IRequestEvents;
-begin
- result := TRequestEventsImpl.Create;
- Inc( FReqs);
-end;
-
-
-procedure TProcessorEventsImpl.CleanupContext;
-begin
- Console.WriteLine( 'ProcessorEvents: completed after handling '+IntToStr(FReqs)+' requests.');
-end;
-
-
-{ TRequestEventsImpl }
-
+begin
+ inherited Create;
+ FReqs := 0;
+ Console.WriteLine('ProcessorEvents: Client connected, processing begins');
+end;
+
+procedure TProcessorEventsImpl.Processing(const transport: ITransport);
+begin
+ Console.WriteLine('ProcessorEvents: Processing of incoming request begins');
+end;
+
+
+function TProcessorEventsImpl.CreateRequestContext( const aFunctionName: string): IRequestEvents;
+begin
+ result := TRequestEventsImpl.Create;
+ Inc( FReqs);
+end;
+
+
+procedure TProcessorEventsImpl.CleanupContext;
+begin
+ Console.WriteLine( 'ProcessorEvents: completed after handling '+IntToStr(FReqs)+' requests.');
+end;
+
+
+{ TRequestEventsImpl }
+
constructor TRequestEventsImpl.Create;
-begin
- inherited Create;
- FStart := Now;
- Console.WriteLine('RequestEvents: New request');
-end;
-
-
+begin
+ inherited Create;
+ FStart := Now;
+ Console.WriteLine('RequestEvents: New request');
+end;
+
+
procedure TRequestEventsImpl.PreRead;
-begin
- Console.WriteLine('RequestEvents: Reading request message ...');
-end;
-
+begin
+ Console.WriteLine('RequestEvents: Reading request message ...');
+end;
+
procedure TRequestEventsImpl.PostRead;
-begin
- Console.WriteLine('RequestEvents: Reading request message completed');
-end;
+begin
+ Console.WriteLine('RequestEvents: Reading request message completed');
+end;
procedure TRequestEventsImpl.PreWrite;
-begin
- Console.WriteLine('RequestEvents: Writing response message ...');
-end;
-
+begin
+ Console.WriteLine('RequestEvents: Writing response message ...');
+end;
+
procedure TRequestEventsImpl.PostWrite;
-begin
- Console.WriteLine('RequestEvents: Writing response message completed');
-end;
-
+begin
+ Console.WriteLine('RequestEvents: Writing response message completed');
+end;
+
procedure TRequestEventsImpl.OnewayComplete;
-begin
- Console.WriteLine('RequestEvents: Oneway message processed');
-end;
-
+begin
+ Console.WriteLine('RequestEvents: Oneway message processed');
+end;
+
procedure TRequestEventsImpl.UnhandledError(const e: Exception);
-begin
- Console.WriteLine('RequestEvents: Unhandled exception of type '+e.classname);
-end;
-
-
-procedure TRequestEventsImpl.CleanupContext;
-var millis : Double;
-begin
- millis := (Now - FStart) * (24*60*60*1000);
- Console.WriteLine( 'Request processing completed in '+IntToStr(Round(millis))+' ms');
-end;
-
-
+begin
+ Console.WriteLine('RequestEvents: Unhandled exception of type '+e.classname);
+end;
+
+
+procedure TRequestEventsImpl.CleanupContext;
+var millis : Double;
+begin
+ millis := (Now - FStart) * (24*60*60*1000);
+ Console.WriteLine( 'Request processing completed in '+IntToStr(Round(millis))+' ms');
+end;
+
+
end.
diff --git a/lib/delphi/test/codegen/README.md b/lib/delphi/test/codegen/README.md
index d1447a1..a014589 100644
--- a/lib/delphi/test/codegen/README.md
+++ b/lib/delphi/test/codegen/README.md
@@ -1,17 +1,17 @@
How to use the test case:
----------------------------------------------
-- copy and the template batch file
+- copy and the template batch file
- open the batch file and adjust configuration as necessary
- run the batch
Configuration:
----------------------------------------------
-SVNWORKDIR
+SVNWORKDIR
should point to the Thrift working copy root
-MY_THRIFT_FILES
-can be set to point to a folder with more thrift IDL files.
+MY_THRIFT_FILES
+can be set to point to a folder with more thrift IDL files.
If you don't have any such files, just leave the setting blank.
BIN
diff --git a/lib/delphi/test/codegen/ReservedKeywords.thrift b/lib/delphi/test/codegen/ReservedKeywords.thrift
index 83c1836..300adf9 100644
--- a/lib/delphi/test/codegen/ReservedKeywords.thrift
+++ b/lib/delphi/test/codegen/ReservedKeywords.thrift
@@ -17,7 +17,7 @@
* under the License.
*/
-// make sure generated code does not produce name collisions with predefined keywords
+// make sure generated code does not produce name collisions with predefined keywords
diff --git a/lib/delphi/test/codegen/run-Pascal-Codegen-Tests.bat.tmpl b/lib/delphi/test/codegen/run-Pascal-Codegen-Tests.bat.tmpl
index f1b56a3..4398545 100644
--- a/lib/delphi/test/codegen/run-Pascal-Codegen-Tests.bat.tmpl
+++ b/lib/delphi/test/codegen/run-Pascal-Codegen-Tests.bat.tmpl
@@ -62,7 +62,7 @@
rem * create and/or empty target dirs
if not exist "%TARGET%" md "%TARGET%"
if not exist "%TARGET%\%SUBDIR%" md "%TARGET%\%SUBDIR%"
-if not exist "%OUTDCU%" md "%OUTDCU%"
+if not exist "%OUTDCU%" md "%OUTDCU%"
if exist "%TARGET%\*.thrift" del "%TARGET%\*.thrift" /Q
if exist "%TARGET%\%SUBDIR%\*.*" del "%TARGET%\%SUBDIR%\*.*" /Q
if exist "%OUTDCU%\*.*" del "%OUTDCU%\*.*" /Q
@@ -88,31 +88,31 @@
rem * generate a minimal DPR file that uses all generated pascal units
cd "%TARGET%\%SUBDIR%\"
if exist inherited.* ren inherited.* _inherited.*
-echo program %TESTAPP%; > %TESTAPP%.dpr
-echo {$APPTYPE CONSOLE} >> %TESTAPP%.dpr
-echo. >> %TESTAPP%.dpr
-echo uses >> %TESTAPP%.dpr
-for %%a in (*.pas) do echo %%~na, >> %TESTAPP%.dpr
-echo Windows, Classes, SysUtils; >> %TESTAPP%.dpr
-echo. >> %TESTAPP%.dpr
-echo begin >> %TESTAPP%.dpr
-echo Writeln('Successfully compiled!'); >> %TESTAPP%.dpr
-echo Writeln('List of units:'); >> %TESTAPP%.dpr
-for %%a in (*.pas) do echo Write('%%~na':30,'':10); >> %TESTAPP%.dpr
-echo Writeln; >> %TESTAPP%.dpr
-echo end. >> %TESTAPP%.dpr
-echo. >> %TESTAPP%.dpr
+echo program %TESTAPP%; > %TESTAPP%.dpr
+echo {$APPTYPE CONSOLE} >> %TESTAPP%.dpr
+echo. >> %TESTAPP%.dpr
+echo uses >> %TESTAPP%.dpr
+for %%a in (*.pas) do echo %%~na, >> %TESTAPP%.dpr
+echo Windows, Classes, SysUtils; >> %TESTAPP%.dpr
+echo. >> %TESTAPP%.dpr
+echo begin >> %TESTAPP%.dpr
+echo Writeln('Successfully compiled!'); >> %TESTAPP%.dpr
+echo Writeln('List of units:'); >> %TESTAPP%.dpr
+for %%a in (*.pas) do echo Write('%%~na':30,'':10); >> %TESTAPP%.dpr
+echo Writeln; >> %TESTAPP%.dpr
+echo end. >> %TESTAPP%.dpr
+echo. >> %TESTAPP%.dpr
cd ..\..
rem * try to compile the DPR
rem * this should not throw any errors, warnings or hints
-"%DCC%" -B "%TARGET%\%SUBDIR%\%TESTAPP%" -U"%UNITSEARCH%" -I"%UNITSEARCH%" -N"%OUTDCU%" -E"%TARGET%\%SUBDIR%"
+"%DCC%" -B "%TARGET%\%SUBDIR%\%TESTAPP%" -U"%UNITSEARCH%" -I"%UNITSEARCH%" -N"%OUTDCU%" -E"%TARGET%\%SUBDIR%"
dir "%TARGET%\%SUBDIR%\%TESTAPP%.exe"
if not exist "%TARGET%\%SUBDIR%\%TESTAPP%.exe" goto CODEGEN_FAILED
echo.
echo -----------------------------------------------------------------
echo The compiled program is now executed. If it hangs or crashes, we
-echo have a serious problem with the generated code. Expected output
+echo have a serious problem with the generated code. Expected output
echo is "Successfully compiled:" followed by a list of generated units.
echo -----------------------------------------------------------------
"%TARGET%\%SUBDIR%\%TESTAPP%.exe"
@@ -124,7 +124,7 @@
REM -----------------------------------------------------
:DXE_NOT_FOUND
REM -----------------------------------------------------
-echo Delphi Compiler (dcc32.exe) not found.
+echo Delphi Compiler (dcc32.exe) not found.
echo Please check the "DCC" setting in this batch.
echo.
cmd /c start notepad README.MD
diff --git a/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas b/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
index a1af40b..34ee081 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Client.Main.pas
@@ -57,8 +57,8 @@
type
IServiceClient = interface
- ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
- procedure Test;
+ ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
+ procedure Test;
end;
//--- TTestClient -------------------------------------
@@ -70,15 +70,15 @@
client := TTestClient.Create(args);
try
client.Run;
- finally
- client.Free;
+ finally
+ client.Free;
end;
end;
constructor TTestClient.Create( const args: array of string);
begin
- inherited;
+ inherited;
ParseArgs(args);
Setup;
end;
@@ -121,8 +121,8 @@
do Write(IntToStr(i)+' ');
WriteLn;
except
- on e:Exception do Writeln(#10+e.Message);
- end;
+ on e:Exception do Writeln(#10+e.Message);
+ end;
end;
diff --git a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
index 4f5cd13..37f84bb 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Server.Main.pas
@@ -72,20 +72,20 @@
TAggrImpl = class( TTestHandlerImpl, TAggr.Iface)
protected
FList : IThriftList<Integer>;
-
+
// TAggr.Iface
procedure addValue(value: Integer);
- function getValues(): IThriftList<Integer>;
- public
- constructor Create;
- destructor Destroy; override;
- end;
+ function getValues(): IThriftList<Integer>;
+ public
+ constructor Create;
+ destructor Destroy; override;
+ end;
public
class procedure Execute( const args: array of string);
end;
-
+
implementation
@@ -105,45 +105,45 @@
prev := 0;
result := 1;
while n > 0 do begin
- next := result + prev;
- prev := result;
- result := next;
- Dec(n);
+ next := result + prev;
+ prev := result;
+ result := next;
+ Dec(n);
end;
end;
{ TTestServer.TAggrImpl }
constructor TTestServer.TAggrImpl.Create;
-begin
+begin
inherited Create;
FList := TThriftListImpl<Integer>.Create;
end;
-
-destructor TTestServer.TAggrImpl.Destroy;
+
+destructor TTestServer.TAggrImpl.Destroy;
begin
try
- FreeAndNil( FList);
- finally
- inherited Destroy;
- end;
+ FreeAndNil( FList);
+ finally
+ inherited Destroy;
+ end;
end;
-
+
procedure TTestServer.TAggrImpl.addValue(value: Integer);
begin
FList.Add( value);
end;
-
+
function TTestServer.TAggrImpl.getValues(): IThriftList<Integer>;
begin
result := FList;
end;
-
-{ TTestServer }
+
+{ TTestServer }
class procedure TTestServer.Execute( const args: array of string);
var
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
index 23e296a..f7ccba1 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Client.dpr
@@ -23,19 +23,19 @@
{$APPTYPE CONSOLE}
uses
- SysUtils,
- Multiplex.Client.Main in 'Multiplex.Client.Main.pas',
- Thrift in '..\..\src\Thrift.pas',
- Thrift.Transport in '..\..\src\Thrift.Transport.pas',
- Thrift.Transport.Pipes in '..\..\src\Thrift.Transport.Pipes.pas',
- Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
- Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
- Thrift.Collections in '..\..\src\Thrift.Collections.pas',
- Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Stream in '..\..\src\Thrift.Stream.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
- Thrift.Utils in '..\..\src\Thrift.Utils.pas';
-
+ SysUtils,
+ Multiplex.Client.Main in 'Multiplex.Client.Main.pas',
+ Thrift in '..\..\src\Thrift.pas',
+ Thrift.Transport in '..\..\src\Thrift.Transport.pas',
+ Thrift.Transport.Pipes in '..\..\src\Thrift.Transport.Pipes.pas',
+ Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
+ Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
+ Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Server in '..\..\src\Thrift.Server.pas',
+ Thrift.Stream in '..\..\src\Thrift.Stream.pas',
+ Thrift.Console in '..\..\src\Thrift.Console.pas',
+ Thrift.Utils in '..\..\src\Thrift.Utils.pas';
+
var
nParamCount : Integer;
args : array of string;
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Common.pas b/lib/delphi/test/multiplexed/Multiplex.Test.Common.pas
index 231c3ad..2caf081 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Common.pas
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Common.pas
@@ -1,35 +1,35 @@
-(*
- * 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.
- *)
-
-unit Multiplex.Test.Common;
-
-interface
-
-const
- NAME_BENCHMARKSERVICE = 'BenchmarkService';
- NAME_AGGR = 'Aggr';
-
-
-implementation
-
-// nix
-
-end.
-
-
+(*
+ * 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.
+ *)
+
+unit Multiplex.Test.Common;
+
+interface
+
+const
+ NAME_BENCHMARKSERVICE = 'BenchmarkService';
+ NAME_AGGR = 'Aggr';
+
+
+implementation
+
+// nix
+
+end.
+
+
diff --git a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
index 9da1cdc..cf03c44 100644
--- a/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
+++ b/lib/delphi/test/multiplexed/Multiplex.Test.Server.dpr
@@ -22,20 +22,20 @@
{$APPTYPE CONSOLE}
uses
- SysUtils,
- Multiplex.Server.Main in 'Multiplex.Server.Main.pas',
- Thrift in '..\..\src\Thrift.pas',
- Thrift.Transport in '..\..\src\Thrift.Transport.pas',
- Thrift.Transport.Pipes in '..\..\src\Thrift.Transport.Pipes.pas',
- Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
- Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
- Thrift.Processor.Multiplex in '..\..\src\Thrift.Processor.Multiplex.pas',
- Thrift.Collections in '..\..\src\Thrift.Collections.pas',
- Thrift.Server in '..\..\src\Thrift.Server.pas',
- Thrift.Console in '..\..\src\Thrift.Console.pas',
- Thrift.Utils in '..\..\src\Thrift.Utils.pas',
- Thrift.Stream in '..\..\src\Thrift.Stream.pas';
-
+ SysUtils,
+ Multiplex.Server.Main in 'Multiplex.Server.Main.pas',
+ Thrift in '..\..\src\Thrift.pas',
+ Thrift.Transport in '..\..\src\Thrift.Transport.pas',
+ Thrift.Transport.Pipes in '..\..\src\Thrift.Transport.Pipes.pas',
+ Thrift.Protocol in '..\..\src\Thrift.Protocol.pas',
+ Thrift.Protocol.Multiplex in '..\..\src\Thrift.Protocol.Multiplex.pas',
+ Thrift.Processor.Multiplex in '..\..\src\Thrift.Processor.Multiplex.pas',
+ Thrift.Collections in '..\..\src\Thrift.Collections.pas',
+ Thrift.Server in '..\..\src\Thrift.Server.pas',
+ Thrift.Console in '..\..\src\Thrift.Console.pas',
+ Thrift.Utils in '..\..\src\Thrift.Utils.pas',
+ Thrift.Stream in '..\..\src\Thrift.Stream.pas';
+
var
nParamCount : Integer;
args : array of string;
diff --git a/lib/delphi/test/skip/README.md b/lib/delphi/test/skip/README.md
index 90d5ff5..9975a0b 100644
--- a/lib/delphi/test/skip/README.md
+++ b/lib/delphi/test/skip/README.md
@@ -1,11 +1,11 @@
-These two projects belong together. Both programs
-simulate server and client for different versions
+These two projects belong together. Both programs
+simulate server and client for different versions
of the same protocol.
The intention of this test is to ensure fully
-working compatibilty features of the Delphi Thrift
+working compatibilty features of the Delphi Thrift
implementation.
-The expected test result is, that no errors occur
-with both programs, regardless in which order they
+The expected test result is, that no errors occur
+with both programs, regardless in which order they
might be started.
diff --git a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
index 64d5771..9a6503a 100644
--- a/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
+++ b/lib/delphi/test/typeregistry/TestTypeRegistry.dpr
@@ -48,42 +48,42 @@
begin
instance := TypeRegistry.Construct<T>;
name := GetTypeName(TypeInfo(T));
- if instance <> nil
- then Writeln( name, ' = ok')
- else begin
- Writeln( name, ' = failed');
- raise Exception.Create( 'Test with '+name+' failed!');
- end;
+ if instance <> nil
+ then Writeln( name, ' = ok')
+ else begin
+ Writeln( name, ' = failed');
+ raise Exception.Create( 'Test with '+name+' failed!');
+ end;
end;
begin
Writeln('Testing ...');
Tester<IDoubles>.Test;
- Tester<IOneOfEach>.Test;
- Tester<IBonk>.Test;
- Tester<INesting>.Test;
- Tester<IHolyMoley>.Test;
- Tester<IBackwards>.Test;
- Tester<IEmpty>.Test;
- Tester<IWrapper>.Test;
- Tester<IRandomStuff>.Test;
- Tester<IBase64>.Test;
- Tester<ICompactProtoTestStruct>.Test;
- Tester<ISingleMapTestStruct>.Test;
- Tester<IBlowUp>.Test;
- Tester<IReverseOrderStruct>.Test;
- Tester<IStructWithSomeEnum>.Test;
- Tester<ITestUnion>.Test;
- Tester<ITestUnionMinusStringField>.Test;
- Tester<IComparableUnion>.Test;
- Tester<IStructWithAUnion>.Test;
- Tester<IPrimitiveThenStruct>.Test;
- Tester<IStructWithASomemap>.Test;
- Tester<IBigFieldIdStruct>.Test;
- Tester<IBreaksRubyCompactProtocol>.Test;
- Tester<ITupleProtocolTestStruct>.Test;
- Writeln('Completed.');
-
-
-end.
+ Tester<IOneOfEach>.Test;
+ Tester<IBonk>.Test;
+ Tester<INesting>.Test;
+ Tester<IHolyMoley>.Test;
+ Tester<IBackwards>.Test;
+ Tester<IEmpty>.Test;
+ Tester<IWrapper>.Test;
+ Tester<IRandomStuff>.Test;
+ Tester<IBase64>.Test;
+ Tester<ICompactProtoTestStruct>.Test;
+ Tester<ISingleMapTestStruct>.Test;
+ Tester<IBlowUp>.Test;
+ Tester<IReverseOrderStruct>.Test;
+ Tester<IStructWithSomeEnum>.Test;
+ Tester<ITestUnion>.Test;
+ Tester<ITestUnionMinusStringField>.Test;
+ Tester<IComparableUnion>.Test;
+ Tester<IStructWithAUnion>.Test;
+ Tester<IPrimitiveThenStruct>.Test;
+ Tester<IStructWithASomemap>.Test;
+ Tester<IBigFieldIdStruct>.Test;
+ Tester<IBreaksRubyCompactProtocol>.Test;
+ Tester<ITupleProtocolTestStruct>.Test;
+ Writeln('Completed.');
+
+
+end.