Skip to content

Commit

Permalink
THRIFT-5750 Remove "ansistr_binary_" option
Browse files Browse the repository at this point in the history
Client: delphi
Patch: Jens Geyer
  • Loading branch information
Jens-G committed Apr 2, 2024
1 parent fcddf08 commit 2adfd14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
33 changes: 4 additions & 29 deletions compiler/cpp/src/thrift/generate/t_delphi_generator.cc
Expand Up @@ -68,7 +68,6 @@ class t_delphi_generator : public t_oop_generator {
has_const = false;
std::map<std::string, std::string>::const_iterator iter;

ansistr_binary_ = false;
register_types_ = false;
constprefix_ = false;
old_names_ = false;
Expand All @@ -78,10 +77,7 @@ class t_delphi_generator : public t_oop_generator {
com_types_ = false;
rtti_ = false;
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
if( iter->first.compare("ansistr_binary") == 0) {
ansistr_binary_ = true;
pwarning(0, "The 'ansistr_binary' option is deprecated.");
} else if( iter->first.compare("register_types") == 0) {
if( iter->first.compare("register_types") == 0) {
register_types_ = true;
} else if( iter->first.compare("old_names") == 0) {
old_names_ = true;
Expand All @@ -102,10 +98,6 @@ class t_delphi_generator : public t_oop_generator {
}
}

if(com_types_ && ansistr_binary_) {
throw "com_types and ansistr_binary are mutually exclusive";
}

out_dir_base_ = "gen-delphi";
escape_.clear();
escape_['\''] = "''";
Expand Down Expand Up @@ -468,7 +460,6 @@ class t_delphi_generator : public t_oop_generator {
void init_known_types_list();
bool is_void(t_type* type);
int indent_impl_;
bool ansistr_binary_;
bool register_types_;
bool constprefix_;
bool old_names_;
Expand Down Expand Up @@ -760,7 +751,6 @@ void t_delphi_generator::close_generator() {

f_all << "const" << endl;
indent_up();
indent(f_all) << "c" << tmp_unit << "_Option_AnsiStr_Binary = " << (ansistr_binary_ ? "True" : "False") << ";" << endl;
indent(f_all) << "c" << tmp_unit << "_Option_Register_Types = " << (register_types_ ? "True" : "False") << ";" << endl;
indent(f_all) << "c" << tmp_unit << "_Option_ConstPrefix = " << (constprefix_ ? "True" : "False") << ";" << endl;
indent(f_all) << "c" << tmp_unit << "_Option_Events = " << (events_ ? "True" : "False") << ";" << endl;
Expand Down Expand Up @@ -2634,11 +2624,7 @@ void t_delphi_generator::generate_deserialize_field(ostream& out,
break;
case t_base_type::TYPE_STRING:
if (type->is_binary()) {
if (ansistr_binary_) {
out << "ReadAnsiString();";
} else {
out << (com_types_ ? "ReadBinaryCOM();" : "ReadBinary();");
}
out << (com_types_ ? "ReadBinaryCOM();" : "ReadBinary();");
} else {
out << "ReadString();";
}
Expand Down Expand Up @@ -2837,11 +2823,7 @@ void t_delphi_generator::generate_serialize_field(ostream& out,
break;
case t_base_type::TYPE_STRING:
if (type->is_binary()) {
if (ansistr_binary_) {
out << "WriteAnsiString(";
} else {
out << "WriteBinary(";
}
out << "WriteBinary(";
} else {
out << "WriteString(";
}
Expand Down Expand Up @@ -3180,8 +3162,6 @@ string t_delphi_generator::base_type_name(t_base_type* tbase) {
return "";
case t_base_type::TYPE_STRING:
if (tbase->is_binary()) {
if (ansistr_binary_)
return "System.AnsiString";
if( com_types_)
return "IThriftBytes";
if( rtti_)
Expand Down Expand Up @@ -3400,11 +3380,7 @@ string t_delphi_generator::empty_value(t_type* type) {
return "0";
case t_base_type::TYPE_STRING:
if (type->is_binary()) {
if (ansistr_binary_) {
return "''";
} else {
return "nil";
}
return "nil";
} else {
return "''";
}
Expand Down Expand Up @@ -4072,7 +4048,6 @@ std::string t_delphi_generator::display_name() const {
THRIFT_REGISTER_GENERATOR(
delphi,
"Delphi",
" ansistr_binary: Use AnsiString for binary datatype (default is TBytes).\n"
" register_types: Enable TypeRegistry, allows for creation of struct, union\n"
" and container instances by interface or TypeInfo()\n"
" constprefix: Name TConstants classes after IDL to reduce ambiguities\n"
Expand Down
28 changes: 22 additions & 6 deletions lib/delphi/src/Thrift.Protocol.pas
Expand Up @@ -232,7 +232,7 @@ TProtocolRecursionTrackerImpl = class abstract( TInterfacedObject, IProtocolRe
procedure WriteI64( const i64: Int64);
procedure WriteDouble( const d: Double);
procedure WriteString( const s: string );
procedure WriteAnsiString( const s: AnsiString);
procedure WriteAnsiString( const s: AnsiString); deprecated 'AnsiString routines are deprecated, see THRIFT-5750';
procedure WriteBinary( const b: TBytes); overload;
procedure WriteBinary( const b: IThriftBytes); overload;
procedure WriteUuid( const uuid: TGuid);
Expand All @@ -259,7 +259,7 @@ TProtocolRecursionTrackerImpl = class abstract( TInterfacedObject, IProtocolRe
function ReadBinaryCOM : IThriftBytes;
function ReadUuid: TGuid;
function ReadString: string;
function ReadAnsiString: AnsiString;
function ReadAnsiString: AnsiString; deprecated 'AnsiString routines are deprecated, see THRIFT-5750';

function NextRecursionLevel : IProtocolRecursionTracker;
procedure IncrementRecursionDepth;
Expand Down Expand Up @@ -311,7 +311,6 @@ TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
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); overload; virtual; abstract;
procedure WriteUuid( const b: TGuid); virtual; abstract;

Expand All @@ -336,14 +335,20 @@ TProtocolImpl = class abstract( TInterfacedObject, IProtocol)
function ReadBinary: TBytes; virtual; abstract;
function ReadUuid: TGuid; virtual; abstract;
function ReadString: string; virtual;
function ReadAnsiString: AnsiString; virtual;

// provide generic implementation for all derived classes
procedure WriteBinary( const bytes : IThriftBytes); overload; virtual;
function ReadBinaryCOM : IThriftBytes; virtual;

property Transport: ITransport read GetTransport;

private
// THRIFT-5750 unit visible, but no longer protected - awaiting final removal
// - Note that you can implement whavetever you want in your derived class, but no longer inherit
// - The function can still be called via IProtocol until final removal
function ReadAnsiString: AnsiString; virtual; //deprecated;
procedure WriteAnsiString( const s: AnsiString); virtual; //deprecated;

public
constructor Create( const aTransport : ITransport); virtual;
end;
Expand Down Expand Up @@ -508,7 +513,6 @@ TProtocolDecorator = class( TProtocolImpl)
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;
procedure WriteBinary( const bytes : IThriftBytes); overload; override;
procedure WriteUuid( const uuid: TGuid); override;
Expand All @@ -534,7 +538,15 @@ TProtocolDecorator = class( TProtocolImpl)
function ReadBinary: TBytes; override;
function ReadUuid: TGuid; override;
function ReadString: string; override;
function ReadAnsiString: AnsiString; override;

private
// THRIFT-5750 unit visible, but no longer protected - awaiting final removal
// - Note that you can implement whavetever you want in your derived class, but no longer inherit
// - The function can still be called via IProtocol until final removal
{$WARN SYMBOL_DEPRECATED OFF}
function ReadAnsiString: AnsiString; override; deprecated;
procedure WriteAnsiString( const s: AnsiString); override; deprecated;
{$WARN SYMBOL_DEPRECATED DEFAULT}
end;


Expand Down Expand Up @@ -1520,7 +1532,9 @@ procedure TProtocolDecorator.WriteString( const s: string );

procedure TProtocolDecorator.WriteAnsiString( const s: AnsiString);
begin
{$WARN SYMBOL_DEPRECATED OFF}
FWrappedProtocol.WriteAnsiString( s);
{$WARN SYMBOL_DEPRECATED DEFAULT}
end;


Expand Down Expand Up @@ -1670,7 +1684,9 @@ function TProtocolDecorator.ReadString: string;

function TProtocolDecorator.ReadAnsiString: AnsiString;
begin
{$WARN SYMBOL_DEPRECATED OFF}
result := FWrappedProtocol.ReadAnsiString;
{$WARN SYMBOL_DEPRECATED DEFAULT}
end;


Expand Down

0 comments on commit 2adfd14

Please sign in to comment.