THRIFT-5437 Make TProtocolImpl CTOR virtual
Client: Delphi
Patch: Jens Geyer
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 @@
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 @@
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 @@
function Configuration : IThriftConfiguration;
end;
+ TProtocolImplClass = class of TProtocolImpl;
+
TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
strict protected
FTrans : ITransport;
@@ -317,7 +319,7 @@
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 @@
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 @@
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 @@
{ 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 @@
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 @@
interface
-uses SysUtils;
+uses SysUtils,
+ Thrift.Protocol, Thrift.Protocol.Compact, Thrift.Protocol.JSON;
type
TKnownProtocol = (
@@ -55,6 +56,13 @@
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 @@
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 @@
// 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