THRIFT-5009 Serializer implemtation lacks support for layered transports
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Serializer.pas b/lib/delphi/src/Thrift.Serializer.pas
index 71b695c..b95cf61 100644
--- a/lib/delphi/src/Thrift.Serializer.pas
+++ b/lib/delphi/src/Thrift.Serializer.pas
@@ -49,6 +49,10 @@
// It will use the TProtocol specified by the factory that is passed in.
constructor Create( const factory : IProtocolFactory); overload;
+ // Create a new TSerializer.
+ // It will use the TProtocol and layered transports specified by the factories that are passed in.
+ constructor Create( const protfact : IProtocolFactory; const transfact : ITransportFactory); overload;
+
// DTOR
destructor Destroy; override;
@@ -73,6 +77,10 @@
// It will use the TProtocol specified by the factory that is passed in.
constructor Create( const factory : IProtocolFactory); overload;
+ // Create a new TDeserializer.
+ // It will use the TProtocol and layered transports specified by the factories that are passed in.
+ constructor Create( const protfact : IProtocolFactory; const transfact : ITransportFactory); overload;
+
// DTOR
destructor Destroy; override;
@@ -89,24 +97,37 @@
{ TSerializer }
-constructor TSerializer.Create();
+constructor TSerializer.Create;
// Create a new TSerializer that uses the TBinaryProtocol by default.
begin
//no inherited;
- Create( TBinaryProtocolImpl.TFactory.Create);
+ Create( TBinaryProtocolImpl.TFactory.Create, nil);
end;
constructor TSerializer.Create( const factory : IProtocolFactory);
// Create a new TSerializer.
// It will use the TProtocol specified by the factory that is passed in.
+begin
+ //no inherited;
+ Create( factory, nil);
+end;
+
+
+constructor TSerializer.Create( const protfact : IProtocolFactory; const transfact : ITransportFactory);
+// Create a new TSerializer.
+// It will use the TProtocol specified by the factory that is passed in.
var adapter : IThriftStream;
begin
inherited Create;
FStream := TMemoryStream.Create;
adapter := TThriftStreamAdapterDelphi.Create( FStream, FALSE);
FTransport := TStreamTransportImpl.Create( nil, adapter);
- FProtocol := factory.GetProtocol( FTransport);
+ if transfact <> nil then FTransport := transfact.GetTransport( FTransport);
+ FProtocol := protfact.GetProtocol( FTransport);
+
+ if not FTransport.IsOpen
+ then FTransport.Open;
end;
@@ -131,6 +152,8 @@
try
FStream.Size := 0;
input.Write( FProtocol);
+ FTransport.Flush;
+
SetLength( result, FStream.Size);
iBytes := Length(result);
if iBytes > 0
@@ -150,6 +173,8 @@
try
FStream.Size := 0;
input.Write( FProtocol);
+ FTransport.Flush;
+
aStm.CopyFrom( FStream, COPY_ENTIRE_STREAM);
finally
FStream.Size := 0; // free any allocated memory
@@ -160,24 +185,37 @@
{ TDeserializer }
-constructor TDeserializer.Create();
+constructor TDeserializer.Create;
// Create a new TDeserializer that uses the TBinaryProtocol by default.
begin
//no inherited;
- Create( TBinaryProtocolImpl.TFactory.Create);
+ Create( TBinaryProtocolImpl.TFactory.Create, nil);
end;
constructor TDeserializer.Create( const factory : IProtocolFactory);
// Create a new TDeserializer.
// It will use the TProtocol specified by the factory that is passed in.
+begin
+ //no inherited;
+ Create( factory, nil);
+end;
+
+
+constructor TDeserializer.Create( const protfact : IProtocolFactory; const transfact : ITransportFactory);
+// Create a new TDeserializer.
+// It will use the TProtocol specified by the factory that is passed in.
var adapter : IThriftStream;
begin
inherited Create;
FStream := TMemoryStream.Create;
adapter := TThriftStreamAdapterDelphi.Create( FStream, FALSE);
FTransport := TStreamTransportImpl.Create( adapter, nil);
- FProtocol := factory.GetProtocol( FTransport);
+ if transfact <> nil then FTransport := transfact.GetTransport( FTransport);
+ FProtocol := protfact.GetProtocol( FTransport);
+
+ if not FTransport.IsOpen
+ then FTransport.Open;
end;