THRIFT-5764 Extra CTOR for TThriftBytesImpl
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index f5cb454..4c02d3f 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -28,6 +28,7 @@
Classes,
SysUtils,
Contnrs,
+ Math,
Thrift.Exception,
Thrift.Stream,
Thrift.Utils,
@@ -388,6 +389,7 @@
constructor Create; overload;
constructor Create( const bytes : TBytes); overload;
constructor Create( var bytes : TBytes; const aTakeOwnership : Boolean = FALSE); overload;
+ constructor Create( const pData : Pointer; const nCount : Integer); overload;
function ToString : string; override;
end;
@@ -802,6 +804,13 @@
end;
+constructor TThriftBytesImpl.Create( const pData : Pointer; const nCount : Integer);
+begin
+ SetLength(FData, Max(nCount,0));
+ if Length(FData) > 0 then Move( pData^, FData[0], Length(FData));
+end;
+
+
function TThriftBytesImpl.ToString : string;
var sb : TThriftStringBuilder;
begin
diff --git a/lib/delphi/test/serializer/TestSerializer.Tests.pas b/lib/delphi/test/serializer/TestSerializer.Tests.pas
index 6ed1a48..91ced8a 100644
--- a/lib/delphi/test/serializer/TestSerializer.Tests.pas
+++ b/lib/delphi/test/serializer/TestSerializer.Tests.pas
@@ -81,6 +81,7 @@
procedure Test_Serializer_Deserializer;
procedure Test_COM_Types;
+ procedure Test_ThriftBytesCTORs;
procedure Test_OneOfEach( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
procedure Test_CompactStruct( const method : TMethod; const factory : TFactoryPair; const stream : TFileStream);
@@ -325,11 +326,28 @@
end;
+procedure TTestSerializer.Test_ThriftBytesCTORs;
+var one, two : IThriftBytes;
+ bytes : TBytes;
+ sAscii : AnsiString;
+begin
+ sAscii := 'ABC/xzy';
+ bytes := TEncoding.ASCII.GetBytes(sAscii);
+
+ one := TThriftBytesImpl.Create( PAnsiChar(sAscii), Length(sAscii));
+ two := TThriftBytesImpl.Create( bytes, TRUE);
+
+ ASSERT( one.Count = two.Count);
+ ASSERT( CompareMem( one.QueryRawDataPtr, two.QueryRawDataPtr, one.Count));
+end;
+
+
procedure TTestSerializer.RunTests;
begin
try
Test_Serializer_Deserializer;
Test_COM_Types;
+ Test_ThriftBytesCTORs;
except
on e:Exception do begin
Writeln( e.ClassName+': '+ e.Message);