You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2021/07/01 21:35:14 UTC

[thrift] branch master updated: THRIFT-5437 Make TProtocolImpl CTOR virtual Client: Delphi Patch: Jens Geyer

This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b68653  THRIFT-5437 Make TProtocolImpl CTOR virtual Client: Delphi Patch: Jens Geyer
3b68653 is described below

commit 3b686533f7cf8c949c389bdaadc2d67f43cac3bd
Author: Jens Geyer <je...@apache.org>
AuthorDate: Thu Jul 1 23:04:08 2021 +0200

    THRIFT-5437 Make TProtocolImpl CTOR virtual
    Client: Delphi
    Patch: Jens Geyer
---
 lib/delphi/src/Thrift.Protocol.Compact.pas |  2 +-
 lib/delphi/src/Thrift.Protocol.JSON.pas    |  2 +-
 lib/delphi/src/Thrift.Protocol.pas         | 15 ++++++++++++---
 lib/delphi/test/TestClient.pas             |  9 +--------
 lib/delphi/test/TestConstants.pas          | 14 +++++++++-----
 lib/delphi/test/TestServer.pas             |  2 +-
 6 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/lib/delphi/src/Thrift.Protocol.Compact.pas b/lib/delphi/src/Thrift.Protocol.Compact.pas
index 424b267..3a1dbfd 100644
--- a/lib/delphi/src/Thrift.Protocol.Compact.pas
+++ b/lib/delphi/src/Thrift.Protocol.Compact.pas
@@ -134,7 +134,7 @@ type
     strict private  boolValue_  : ( unused, bool_true, bool_false);
 
   public
-    constructor Create(const trans : ITransport);
+    constructor Create(const trans : ITransport);  override;
     destructor Destroy;  override;
 
   strict private
diff --git a/lib/delphi/src/Thrift.Protocol.JSON.pas b/lib/delphi/src/Thrift.Protocol.JSON.pas
index 515d85c..52909b7 100644
--- a/lib/delphi/src/Thrift.Protocol.JSON.pas
+++ b/lib/delphi/src/Thrift.Protocol.JSON.pas
@@ -140,7 +140,7 @@ type
 
   public
     // TJSONProtocolImpl Constructor
-    constructor Create( const aTrans : ITransport);
+    constructor Create( const aTrans : ITransport);  override;
     destructor Destroy;   override;
 
   strict protected
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index aa12ad3..03cc371 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -250,6 +250,8 @@ type
     function Configuration : IThriftConfiguration;
   end;
 
+  TProtocolImplClass = class of TProtocolImpl;
+
   TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
   strict protected
     FTrans : ITransport;
@@ -317,7 +319,7 @@ type
     property  Transport: ITransport read GetTransport;
 
   public
-    constructor Create( const aTransport : ITransport);
+    constructor Create( const aTransport : ITransport); virtual;
   end;
 
   IBase = interface( ISupportsToString)
@@ -352,7 +354,8 @@ type
         constructor Create( const aStrictRead : Boolean = FALSE; const aStrictWrite: Boolean = TRUE); reintroduce;
       end;
 
-    constructor Create( const trans: ITransport; strictRead: Boolean = FALSE; strictWrite: Boolean = TRUE); reintroduce;
+    constructor Create( const trans: ITransport); overload; override;
+    constructor Create( const trans: ITransport; strictRead, strictWrite: Boolean); reintroduce; overload;
 
     procedure WriteMessageBegin( const msg: TThriftMessage); override;
     procedure WriteMessageEnd; override;
@@ -414,7 +417,7 @@ type
   public
     // Encloses the specified protocol.
     // All operations will be forward to the given protocol.  Must be non-null.
-    constructor Create( const aProtocol : IProtocol);
+    constructor Create( const aProtocol : IProtocol);  reintroduce;
 
     procedure WriteMessageBegin( const msg: TThriftMessage); override;
     procedure WriteMessageEnd; override;
@@ -714,6 +717,12 @@ end;
 
 { TBinaryProtocolImpl }
 
+constructor TBinaryProtocolImpl.Create( const trans: ITransport);
+begin
+  // call the real CTOR
+  Self.Create( trans, FALSE, TRUE);
+end;
+
 constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead, strictWrite: Boolean);
 begin
   inherited Create( trans);
diff --git a/lib/delphi/test/TestClient.pas b/lib/delphi/test/TestClient.pas
index ebc0796..c8d3fc2 100644
--- a/lib/delphi/test/TestClient.pas
+++ b/lib/delphi/test/TestClient.pas
@@ -1451,14 +1451,7 @@ begin
   end;
 
   // create protocol instance, default to BinaryProtocol
-  case FSetup.protType of
-    prot_Binary  :  FProtocol := TBinaryProtocolImpl.Create( FTransport, BINARY_STRICT_READ, BINARY_STRICT_WRITE);
-    prot_JSON    :  FProtocol := TJSONProtocolImpl.Create( FTransport);
-    prot_Compact :  FProtocol := TCompactProtocolImpl.Create( FTransport);
-  else
-    raise Exception.Create('Unhandled protocol');
-  end;
-
+  FProtocol := PROTOCOL_CLASSES[FSetup.protType].Create(FTransport);
   ASSERT( (FTransport <> nil) and (FProtocol <> nil));
 end;
 
diff --git a/lib/delphi/test/TestConstants.pas b/lib/delphi/test/TestConstants.pas
index ae3b3e8..9ac4808 100644
--- a/lib/delphi/test/TestConstants.pas
+++ b/lib/delphi/test/TestConstants.pas
@@ -21,7 +21,8 @@ unit TestConstants;
 
 interface
 
-uses SysUtils;
+uses SysUtils,
+     Thrift.Protocol, Thrift.Protocol.Compact, Thrift.Protocol.JSON;
 
 type
   TKnownProtocol = (
@@ -55,6 +56,13 @@ type
   TLayeredTransports = set of TLayeredTransport;
 
 const
+  PROTOCOL_CLASSES : array[TKnownProtocol] of TProtocolImplClass = (
+    TBinaryProtocolImpl,
+    TJSONProtocolImpl,
+    TCompactProtocolImpl
+  );
+
+const
   SERVER_TYPES : array[TServerType] of string
                   = ('Simple', 'Nonblocking', 'Threadpool', 'Threaded');
 
@@ -67,10 +75,6 @@ const
   ENDPOINT_TRANSPORTS : array[TEndpointTransport] of string
                   = ('Sockets', 'Http', 'WinHttp', 'Named Pipes','Anon Pipes', 'EvHttp');
 
-  // defaults are: read=false, write=true
-  BINARY_STRICT_READ  = FALSE;
-  BINARY_STRICT_WRITE = FALSE;
-
   HUGE_TEST_STRING = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy '
                    + 'eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam '
                    + 'voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet '
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index adbbccf..8aaf9f3 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -567,7 +567,7 @@ begin
 
     // create protocol factory, default to BinaryProtocol
     case protType of
-      prot_Binary  :  ProtocolFactory := TBinaryProtocolImpl.TFactory.Create( BINARY_STRICT_READ, BINARY_STRICT_WRITE);
+      prot_Binary  :  ProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
       prot_JSON    :  ProtocolFactory := TJSONProtocolImpl.TFactory.Create;
       prot_Compact :  ProtocolFactory := TCompactProtocolImpl.TFactory.Create;
     else