THRIFT-1485 Performance: pass large and/or refcounted arguments as "const"

Patch: Jens Geyer

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1228965 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roger Meier 2012-01-08 21:51:08 +00:00
parent 77e1e62913
commit 333bbf3d88
10 changed files with 273 additions and 223 deletions

View File

@ -131,6 +131,7 @@ class t_delphi_generator : public t_oop_generator
std::string type_name( t_type* ttype, bool b_cls=false, bool b_no_postfix=false, bool b_exception_factory=false, bool b_full_exception_factory = false); std::string type_name( t_type* ttype, bool b_cls=false, bool b_no_postfix=false, bool b_exception_factory=false, bool b_full_exception_factory = false);
std::string normalize_clsnm(std::string name, std::string prefix, bool b_no_check_keyword = false); std::string normalize_clsnm(std::string name, std::string prefix, bool b_no_check_keyword = false);
std::string input_arg_prefix( t_type* ttype);
std::string base_type_name(t_base_type* tbase); std::string base_type_name(t_base_type* tbase);
std::string declare_field(t_field* tfield, bool init=false, std::string prefix="", bool is_xception_class = false); std::string declare_field(t_field* tfield, bool init=false, std::string prefix="", bool is_xception_class = false);
@ -1072,8 +1073,8 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream &out, t_struc
if ((! is_exception) || is_x_factory) { if ((! is_exception) || is_x_factory) {
out << endl; out << endl;
indent(out) << "// IBase" << endl; indent(out) << "// IBase" << endl;
indent(out) << "procedure Read( iprot: IProtocol);" << endl; indent(out) << "procedure Read( const iprot: IProtocol);" << endl;
indent(out) << "procedure Write( oprot: IProtocol);" << endl; indent(out) << "procedure Write( const oprot: IProtocol);" << endl;
} }
if (is_exception && is_x_factory) { if (is_exception && is_x_factory) {
@ -1193,9 +1194,11 @@ void t_delphi_generator::generate_service_client(t_service* tservice) {
indent_down_impl(); indent_down_impl();
indent_impl(s_service_impl) << "end;" << endl << endl; indent_impl(s_service_impl) << "end;" << endl << endl;
indent(s_service) << "constructor Create( iprot: IProtocol; oprot: IProtocol); overload;" << endl; indent(s_service) << "constructor Create( const iprot: IProtocol; const oprot: IProtocol); overload;" << endl;
indent_impl(s_service_impl) << "constructor " << normalize_clsnm( service_name_, "T") << ".TClient.Create( iprot: IProtocol; oprot: IProtocol);" << endl; indent_impl(s_service_impl) <<
"constructor " << normalize_clsnm( service_name_, "T") <<
".TClient.Create( const iprot: IProtocol; const oprot: IProtocol);" << endl;
indent_impl(s_service_impl) << "begin" << endl; indent_impl(s_service_impl) << "begin" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(s_service_impl) << "iprot_ := iprot;" << endl; indent_impl(s_service_impl) << "iprot_ := iprot;" << endl;
@ -1446,7 +1449,7 @@ void t_delphi_generator::generate_service_server(t_service* tservice) {
indent_up(); indent_up();
indent(s_service) << "type" << endl; indent(s_service) << "type" << endl;
indent_up(); indent_up();
indent(s_service) << "TProcessFunction = reference to procedure( seqid: Integer; iprot: IProtocol; oprot: IProtocol);" << endl; indent(s_service) << "TProcessFunction = reference to procedure( seqid: Integer; const iprot: IProtocol; const oprot: IProtocol);" << endl;
indent_down(); indent_down();
indent_down(); indent_down();
@ -1461,12 +1464,12 @@ void t_delphi_generator::generate_service_server(t_service* tservice) {
indent(s_service) << "public" << endl; indent(s_service) << "public" << endl;
indent_up(); indent_up();
if (extends.empty()) { if (extends.empty()) {
indent(s_service) << "function Process( iprot: IProtocol; oprot: IProtocol): Boolean;" << endl; indent(s_service) << "function Process( const iprot: IProtocol; const oprot: IProtocol): Boolean;" << endl;
} else { } else {
indent(s_service) << "function Process( iprot: IProtocol; oprot: IProtocol): Boolean; reintroduce;" << endl; indent(s_service) << "function Process( const iprot: IProtocol; const oprot: IProtocol): Boolean; reintroduce;" << endl;
} }
indent_impl(s_service_impl) << "function " << full_cls << ".Process( iprot: IProtocol; oprot: IProtocol): Boolean;" << endl;; indent_impl(s_service_impl) << "function " << full_cls << ".Process( const iprot: IProtocol; const oprot: IProtocol): Boolean;" << endl;;
indent_impl(s_service_impl) << "var" << endl; indent_impl(s_service_impl) << "var" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(s_service_impl) << "msg : IMessage;" << endl; indent_impl(s_service_impl) << "msg : IMessage;" << endl;
@ -1552,7 +1555,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi
string result_intfnm = normalize_clsnm(org_resultname, "I"); string result_intfnm = normalize_clsnm(org_resultname, "I");
indent(s_service) << indent(s_service) <<
"procedure " << funcname << "_Process( seqid: Integer; iprot: IProtocol; oprot: IProtocol);" << endl; "procedure " << funcname << "_Process( seqid: Integer; const iprot: IProtocol; const oprot: IProtocol);" << endl;
if (tfunction->is_oneway()) { if (tfunction->is_oneway()) {
indent_impl(s_service_impl) << "// one way processor" << endl; indent_impl(s_service_impl) << "// one way processor" << endl;
@ -1561,7 +1564,7 @@ void t_delphi_generator::generate_process_function(t_service* tservice, t_functi
} }
indent_impl(s_service_impl) << indent_impl(s_service_impl) <<
"procedure " << full_cls << "." << funcname << "_Process( seqid: Integer; iprot: IProtocol; oprot: IProtocol);" << endl; "procedure " << full_cls << "." << funcname << "_Process( seqid: Integer; const iprot: IProtocol; const oprot: IProtocol);" << endl;
indent_impl(s_service_impl) << "var" << endl; indent_impl(s_service_impl) << "var" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(s_service_impl) << "args: " << args_intfnm << ";" << endl; indent_impl(s_service_impl) << "args: " << args_intfnm << ";" << endl;
@ -2104,6 +2107,52 @@ string t_delphi_generator::type_name( t_type* ttype, bool b_cls, bool b_no_postf
return nm; return nm;
} }
// returns "const " for some argument types
string t_delphi_generator::input_arg_prefix( t_type* ttype) {
// base types
if (ttype->is_base_type()) {
switch (((t_base_type*)ttype)->get_base()) {
// these should be const'ed for optimal performamce
case t_base_type::TYPE_STRING: // refcounted pointer
case t_base_type::TYPE_I64: // larger than 32 bit
case t_base_type::TYPE_DOUBLE: // larger than 32 bit
return "const ";
// all others don't need to be
case t_base_type::TYPE_BYTE:
case t_base_type::TYPE_I16:
case t_base_type::TYPE_I32:
case t_base_type::TYPE_BOOL:
case t_base_type::TYPE_VOID:
return "";
// we better always report any unknown types
default:
throw "compiler error: no input_arg_prefix() for base type " + (((t_base_type*)ttype)->get_base());
}
// enums
} else if (ttype->is_enum()) {
return ""; // usually <= 32 bit
// containers
} else if (ttype->is_map()) {
return "const "; // refcounted pointer
} else if (ttype->is_set()) {
return "const "; // refcounted pointer
} else if (ttype->is_list()) {
return "const "; // refcounted pointer
}
// any other type, either TSomething or ISomething
return "const "; // possibly refcounted pointer
}
string t_delphi_generator::base_type_name(t_base_type* tbase) { string t_delphi_generator::base_type_name(t_base_type* tbase) {
switch (tbase->get_base()) { switch (tbase->get_base()) {
case t_base_type::TYPE_VOID: case t_base_type::TYPE_VOID:
@ -2176,6 +2225,7 @@ string t_delphi_generator::argument_list(t_struct* tstruct) {
} }
tt = (*f_iter)->get_type(); tt = (*f_iter)->get_type();
result += input_arg_prefix(tt); // const?
result += normalize_name((*f_iter)->get_name()) + ": " + type_name( tt, false, true, tt->is_xception(), true); result += normalize_name((*f_iter)->get_name()) + ": " + type_name( tt, false, true, tt->is_xception(), true);
} }
return result; return result;
@ -2211,6 +2261,7 @@ string t_delphi_generator::constructor_argument_list(t_struct* tstruct, string c
} }
tt = (*f_iter)->get_type(); tt = (*f_iter)->get_type();
line += input_arg_prefix(tt); // const?
line += constructor_param_name((*f_iter)->get_name()) + ": " + type_name( tt, false, true, tt->is_xception(), true); line += constructor_param_name((*f_iter)->get_name()) + ": " + type_name( tt, false, true, tt->is_xception(), true);
} }
@ -2514,7 +2565,7 @@ void t_delphi_generator::generate_delphi_struct_reader_impl(ostream& out, string
cls_nm = type_name(tstruct,true,false,is_exception,is_exception); cls_nm = type_name(tstruct,true,false,is_exception,is_exception);
indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( iprot: IProtocol);" << endl; indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Read( const iprot: IProtocol);" << endl;
indent_impl(out) << "var" << endl; indent_impl(out) << "var" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(out) << "field_ : IField;" << endl; indent_impl(out) << "field_ : IField;" << endl;
@ -2582,7 +2633,7 @@ void t_delphi_generator::generate_delphi_struct_result_writer_impl(ostream& out,
cls_nm = type_name(tstruct,true,false,is_exception,is_exception); cls_nm = type_name(tstruct,true,false,is_exception,is_exception);
indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Write( oprot: IProtocol);" << endl; indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Write( const oprot: IProtocol);" << endl;
indent_impl(out) << "var" << endl; indent_impl(out) << "var" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(out) << "struc : IStruct;" << endl; indent_impl(out) << "struc : IStruct;" << endl;
@ -2654,7 +2705,7 @@ void t_delphi_generator::generate_delphi_struct_writer_impl(ostream& out, string
cls_nm = type_name(tstruct,true,false,is_exception,is_exception); cls_nm = type_name(tstruct,true,false,is_exception,is_exception);
indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Write( oprot: IProtocol);" << endl; indent_impl(out) << "procedure " << cls_prefix << cls_nm << ".Write( const oprot: IProtocol);" << endl;
indent_impl(out) << "var" << endl; indent_impl(out) << "var" << endl;
indent_up_impl(); indent_up_impl();
indent_impl(out) << "struc : IStruct;" << endl; indent_impl(out) << "struc : IStruct;" << endl;

View File

@ -195,11 +195,11 @@ type
function GetCount: Integer; function GetCount: Integer;
property Count: Integer read GetCount; property Count: Integer read GetCount;
property IsReadOnly: Boolean read GetIsReadOnly; property IsReadOnly: Boolean read GetIsReadOnly;
procedure Add( item: TValue); procedure Add( const item: TValue);
procedure Clear; procedure Clear;
function Contains( item: TValue): Boolean; function Contains( const item: TValue): Boolean;
procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer); procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
function Remove( item: TValue ): Boolean; function Remove( const item: TValue ): Boolean;
end; end;
THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>) THashSetImpl<TValue> = class( TInterfacedObject, IHashSet<TValue>)
@ -212,11 +212,11 @@ type
function GetCount: Integer; function GetCount: Integer;
property Count: Integer read GetCount; property Count: Integer read GetCount;
property IsReadOnly: Boolean read FIsReadOnly; property IsReadOnly: Boolean read FIsReadOnly;
procedure Add( item: TValue); procedure Add( const item: TValue);
procedure Clear; procedure Clear;
function Contains( item: TValue): Boolean; function Contains( const item: TValue): Boolean;
procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer); procedure CopyTo(var A: TArray<TValue>; arrayIndex: Integer);
function Remove( item: TValue ): Boolean; function Remove( const item: TValue ): Boolean;
public public
constructor Create; constructor Create;
end; end;
@ -225,7 +225,7 @@ implementation
{ THashSetImpl<TValue> } { THashSetImpl<TValue> }
procedure THashSetImpl<TValue>.Add(item: TValue); procedure THashSetImpl<TValue>.Add( const item: TValue);
begin begin
if not FDictionary.ContainsKey(item) then if not FDictionary.ContainsKey(item) then
begin begin
@ -238,7 +238,7 @@ begin
FDictionary.Clear; FDictionary.Clear;
end; end;
function THashSetImpl<TValue>.Contains(item: TValue): Boolean; function THashSetImpl<TValue>.Contains( const item: TValue): Boolean;
begin begin
Result := FDictionary.ContainsKey(item); Result := FDictionary.ContainsKey(item);
end; end;
@ -277,7 +277,7 @@ begin
Result := FIsReadOnly; Result := FIsReadOnly;
end; end;
function THashSetImpl<TValue>.Remove(item: TValue): Boolean; function THashSetImpl<TValue>.Remove( const item: TValue): Boolean;
begin begin
Result := False; Result := False;
if FDictionary.ContainsKey( item ) then if FDictionary.ContainsKey( item ) then
@ -330,8 +330,7 @@ begin
end; end;
{$IF CompilerVersion >= 21.0} {$IF CompilerVersion >= 21.0}
function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( function TThriftDictionaryImpl<TKey, TValue>.ExtractPair( const Key: TKey): TPair<TKey, TValue>;
const Key: TKey): TPair<TKey, TValue>;
begin begin
Result := FDictionaly.ExtractPair( Key); Result := FDictionaly.ExtractPair( Key);
end; end;

View File

@ -48,7 +48,7 @@ type
type type
TFactory = class( TInterfacedObject, IProtocolFactory) TFactory = class( TInterfacedObject, IProtocolFactory)
public public
function GetProtocol( trans: ITransport): IProtocol; function GetProtocol( const trans: ITransport): IProtocol;
end; end;
private private
@ -126,12 +126,12 @@ type
// Push/pop a new JSON context onto/from the stack. // Push/pop a new JSON context onto/from the stack.
procedure ResetContextStack; procedure ResetContextStack;
procedure PushContext( aCtx : TJSONBaseContext); procedure PushContext( const aCtx : TJSONBaseContext);
procedure PopContext; procedure PopContext;
public public
// TJSONProtocolImpl Constructor // TJSONProtocolImpl Constructor
constructor Create( aTrans : ITransport); constructor Create( const aTrans : ITransport);
destructor Destroy; override; destructor Destroy; override;
protected protected
@ -148,11 +148,11 @@ type
// Write the bytes in array buf as a JSON characters, escaping as needed // Write the bytes in array buf as a JSON characters, escaping as needed
procedure WriteJSONString( const b : TBytes); overload; procedure WriteJSONString( const b : TBytes); overload;
procedure WriteJSONString( str : string); overload; procedure WriteJSONString( const str : string); overload;
// Write out number as a JSON value. If the context dictates so, it will be // Write out number as a JSON value. If the context dictates so, it will be
// wrapped in quotes to output as a JSON string. // wrapped in quotes to output as a JSON string.
procedure WriteJSONInteger( num : Int64); procedure WriteJSONInteger( const num : Int64);
// Write out a double as a JSON value. If it is NaN or infinity or if the // Write out a double as a JSON value. If it is NaN or infinity or if the
// context dictates escaping, Write out as JSON string. // context dictates escaping, Write out as JSON string.
@ -168,25 +168,25 @@ type
public public
// IProtocol // IProtocol
procedure WriteMessageBegin( aMsg : IMessage); override; procedure WriteMessageBegin( const aMsg : IMessage); override;
procedure WriteMessageEnd; override; procedure WriteMessageEnd; override;
procedure WriteStructBegin(struc: IStruct); override; procedure WriteStructBegin( const struc: IStruct); override;
procedure WriteStructEnd; override; procedure WriteStructEnd; override;
procedure WriteFieldBegin(field: IField); override; procedure WriteFieldBegin( const field: IField); override;
procedure WriteFieldEnd; override; procedure WriteFieldEnd; override;
procedure WriteFieldStop; override; procedure WriteFieldStop; override;
procedure WriteMapBegin(map: IMap); override; procedure WriteMapBegin( const map: IMap); override;
procedure WriteMapEnd; override; procedure WriteMapEnd; override;
procedure WriteListBegin( list: IList); override; procedure WriteListBegin( const list: IList); override;
procedure WriteListEnd(); override; procedure WriteListEnd(); override;
procedure WriteSetBegin( set_: ISet ); override; procedure WriteSetBegin( const set_: ISet ); override;
procedure WriteSetEnd(); override; procedure WriteSetEnd(); override;
procedure WriteBool( b: Boolean); override; procedure WriteBool( b: Boolean); override;
procedure WriteByte( b: ShortInt); override; procedure WriteByte( b: ShortInt); override;
procedure WriteI16( i16: SmallInt); override; procedure WriteI16( i16: SmallInt); override;
procedure WriteI32( i32: Integer); override; procedure WriteI32( i32: Integer); override;
procedure WriteI64( i64: Int64); override; procedure WriteI64( const i64: Int64); override;
procedure WriteDouble( d: Double); override; procedure WriteDouble( const d: Double); override;
procedure WriteString( const s: string ); override; procedure WriteString( const s: string ); override;
procedure WriteBinary( const b: TBytes); override; procedure WriteBinary( const b: TBytes); override;
// //
@ -290,7 +290,7 @@ const
//--- TJSONProtocolImpl ---------------------- //--- TJSONProtocolImpl ----------------------
function TJSONProtocolImpl.TFactory.GetProtocol( trans: ITransport): IProtocol; function TJSONProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
begin begin
result := TJSONProtocolImpl.Create(trans); result := TJSONProtocolImpl.Create(trans);
end; end;
@ -455,7 +455,7 @@ begin
end; end;
constructor TJSONProtocolImpl.Create( aTrans : ITransport); constructor TJSONProtocolImpl.Create( const aTrans : ITransport);
begin begin
inherited Create( aTrans); inherited Create( aTrans);
@ -487,7 +487,7 @@ begin
end; end;
procedure TJSONProtocolImpl.PushContext( aCtx : TJSONBaseContext); procedure TJSONProtocolImpl.PushContext( const aCtx : TJSONBaseContext);
begin begin
FContextStack.Push( FContext); FContextStack.Push( FContext);
FContext := aCtx; FContext := aCtx;
@ -528,7 +528,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteJSONString( str : string); procedure TJSONProtocolImpl.WriteJSONString( const str : string);
begin begin
WriteJSONString( SysUtils.TEncoding.UTF8.GetBytes( str)); WriteJSONString( SysUtils.TEncoding.UTF8.GetBytes( str));
end; end;
@ -575,7 +575,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteJSONInteger( num : Int64); procedure TJSONProtocolImpl.WriteJSONInteger( const num : Int64);
var str : String; var str : String;
escapeNum : Boolean; escapeNum : Boolean;
begin begin
@ -676,7 +676,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteMessageBegin( aMsg : IMessage); procedure TJSONProtocolImpl.WriteMessageBegin( const aMsg : IMessage);
begin begin
ResetContextStack; // THRIFT-1473 ResetContextStack; // THRIFT-1473
@ -695,7 +695,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteStructBegin( struc: IStruct); procedure TJSONProtocolImpl.WriteStructBegin( const struc: IStruct);
begin begin
WriteJSONObjectStart; WriteJSONObjectStart;
end; end;
@ -707,7 +707,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteFieldBegin( field : IField); procedure TJSONProtocolImpl.WriteFieldBegin( const field : IField);
begin begin
WriteJSONInteger(field.ID); WriteJSONInteger(field.ID);
WriteJSONObjectStart; WriteJSONObjectStart;
@ -726,7 +726,7 @@ begin
// nothing to do // nothing to do
end; end;
procedure TJSONProtocolImpl.WriteMapBegin( map: IMap); procedure TJSONProtocolImpl.WriteMapBegin( const map: IMap);
begin begin
WriteJSONArrayStart; WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( map.KeyType)); WriteJSONString( GetTypeNameForTypeID( map.KeyType));
@ -743,7 +743,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteListBegin( list: IList); procedure TJSONProtocolImpl.WriteListBegin( const list: IList);
begin begin
WriteJSONArrayStart; WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( list.ElementType)); WriteJSONString( GetTypeNameForTypeID( list.ElementType));
@ -757,7 +757,7 @@ begin
end; end;
procedure TJSONProtocolImpl.WriteSetBegin( set_: ISet); procedure TJSONProtocolImpl.WriteSetBegin( const set_: ISet);
begin begin
WriteJSONArrayStart; WriteJSONArrayStart;
WriteJSONString( GetTypeNameForTypeID( set_.ElementType)); WriteJSONString( GetTypeNameForTypeID( set_.ElementType));
@ -792,12 +792,12 @@ begin
WriteJSONInteger( i32); WriteJSONInteger( i32);
end; end;
procedure TJSONProtocolImpl.WriteI64( i64: Int64); procedure TJSONProtocolImpl.WriteI64( const i64: Int64);
begin begin
WriteJSONInteger(i64); WriteJSONInteger(i64);
end; end;
procedure TJSONProtocolImpl.WriteDouble( d: Double); procedure TJSONProtocolImpl.WriteDouble( const d: Double);
begin begin
WriteJSONDouble( d); WriteJSONDouble( d);
end; end;

View File

@ -61,7 +61,7 @@ type
IProtocolFactory = interface IProtocolFactory = interface
['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}'] ['{7CD64A10-4E9F-4E99-93BF-708A31F4A67B}']
function GetProtocol( trans: ITransport): IProtocol; function GetProtocol( const trans: ITransport): IProtocol;
end; end;
TThriftStringBuilder = class( TStringBuilder) TThriftStringBuilder = class( TStringBuilder)
@ -236,25 +236,25 @@ type
IProtocol = interface IProtocol = interface
['{FD95C151-1527-4C96-8134-B902BFC4B4FC}'] ['{FD95C151-1527-4C96-8134-B902BFC4B4FC}']
function GetTransport: ITransport; function GetTransport: ITransport;
procedure WriteMessageBegin( message: IMessage); procedure WriteMessageBegin( const msg: IMessage);
procedure WriteMessageEnd; procedure WriteMessageEnd;
procedure WriteStructBegin(struc: IStruct); procedure WriteStructBegin( const struc: IStruct);
procedure WriteStructEnd; procedure WriteStructEnd;
procedure WriteFieldBegin(field: IField); procedure WriteFieldBegin( const field: IField);
procedure WriteFieldEnd; procedure WriteFieldEnd;
procedure WriteFieldStop; procedure WriteFieldStop;
procedure WriteMapBegin(map: IMap); procedure WriteMapBegin( const map: IMap);
procedure WriteMapEnd; procedure WriteMapEnd;
procedure WriteListBegin( list: IList); procedure WriteListBegin( const list: IList);
procedure WriteListEnd(); procedure WriteListEnd();
procedure WriteSetBegin( set_: ISet ); procedure WriteSetBegin( const set_: ISet );
procedure WriteSetEnd(); procedure WriteSetEnd();
procedure WriteBool( b: Boolean); procedure WriteBool( b: Boolean);
procedure WriteByte( b: ShortInt); procedure WriteByte( b: ShortInt);
procedure WriteI16( i16: SmallInt); procedure WriteI16( i16: SmallInt);
procedure WriteI32( i32: Integer); procedure WriteI32( i32: Integer);
procedure WriteI64( i64: Int64); procedure WriteI64( const i64: Int64);
procedure WriteDouble( d: Double); procedure WriteDouble( const d: Double);
procedure WriteString( const s: string ); procedure WriteString( const s: string );
procedure WriteAnsiString( const s: AnsiString); procedure WriteAnsiString( const s: AnsiString);
procedure WriteBinary( const b: TBytes); procedure WriteBinary( const b: TBytes);
@ -288,25 +288,25 @@ type
FTrans : ITransport; FTrans : ITransport;
function GetTransport: ITransport; function GetTransport: ITransport;
public public
procedure WriteMessageBegin( message: IMessage); virtual; abstract; procedure WriteMessageBegin( const msg: IMessage); virtual; abstract;
procedure WriteMessageEnd; virtual; abstract; procedure WriteMessageEnd; virtual; abstract;
procedure WriteStructBegin(struc: IStruct); virtual; abstract; procedure WriteStructBegin( const struc: IStruct); virtual; abstract;
procedure WriteStructEnd; virtual; abstract; procedure WriteStructEnd; virtual; abstract;
procedure WriteFieldBegin(field: IField); virtual; abstract; procedure WriteFieldBegin( const field: IField); virtual; abstract;
procedure WriteFieldEnd; virtual; abstract; procedure WriteFieldEnd; virtual; abstract;
procedure WriteFieldStop; virtual; abstract; procedure WriteFieldStop; virtual; abstract;
procedure WriteMapBegin(map: IMap); virtual; abstract; procedure WriteMapBegin( const map: IMap); virtual; abstract;
procedure WriteMapEnd; virtual; abstract; procedure WriteMapEnd; virtual; abstract;
procedure WriteListBegin( list: IList); virtual; abstract; procedure WriteListBegin( const list: IList); virtual; abstract;
procedure WriteListEnd(); virtual; abstract; procedure WriteListEnd(); virtual; abstract;
procedure WriteSetBegin( set_: ISet ); virtual; abstract; procedure WriteSetBegin( const set_: ISet ); virtual; abstract;
procedure WriteSetEnd(); virtual; abstract; procedure WriteSetEnd(); virtual; abstract;
procedure WriteBool( b: Boolean); virtual; abstract; procedure WriteBool( b: Boolean); virtual; abstract;
procedure WriteByte( b: ShortInt); virtual; abstract; procedure WriteByte( b: ShortInt); virtual; abstract;
procedure WriteI16( i16: SmallInt); virtual; abstract; procedure WriteI16( i16: SmallInt); virtual; abstract;
procedure WriteI32( i32: Integer); virtual; abstract; procedure WriteI32( i32: Integer); virtual; abstract;
procedure WriteI64( i64: Int64); virtual; abstract; procedure WriteI64( const i64: Int64); virtual; abstract;
procedure WriteDouble( d: Double); virtual; abstract; procedure WriteDouble( const d: Double); virtual; abstract;
procedure WriteString( const s: string ); virtual; procedure WriteString( const s: string ); virtual;
procedure WriteAnsiString( const s: AnsiString); virtual; procedure WriteAnsiString( const s: AnsiString); virtual;
procedure WriteBinary( const b: TBytes); virtual; abstract; procedure WriteBinary( const b: TBytes); virtual; abstract;
@ -341,8 +341,8 @@ type
IBase = interface IBase = interface
['{08D9BAA8-5EAA-410F-B50B-AC2E6E5E4155}'] ['{08D9BAA8-5EAA-410F-B50B-AC2E6E5E4155}']
function ToString: string; function ToString: string;
procedure Read( iprot: IProtocol); procedure Read( const iprot: IProtocol);
procedure Write( iprot: IProtocol); procedure Write( const iprot: IProtocol);
end; end;
IStruct = interface IStruct = interface
@ -385,33 +385,33 @@ type
FStrictRead : Boolean; FStrictRead : Boolean;
FStrictWrite : Boolean; FStrictWrite : Boolean;
public public
function GetProtocol(trans: ITransport): IProtocol; function GetProtocol( const trans: ITransport): IProtocol;
constructor Create( AStrictRead, AStrictWrite: Boolean ); overload; constructor Create( AStrictRead, AStrictWrite: Boolean ); overload;
constructor Create; overload; constructor Create; overload;
end; end;
constructor Create( trans: ITransport); overload; constructor Create( const trans: ITransport); overload;
constructor Create( trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload; constructor Create( const trans: ITransport; strictRead: Boolean; strictWrite: Boolean); overload;
procedure WriteMessageBegin( message: IMessage); override; procedure WriteMessageBegin( const msg: IMessage); override;
procedure WriteMessageEnd; override; procedure WriteMessageEnd; override;
procedure WriteStructBegin(struc: IStruct); override; procedure WriteStructBegin( const struc: IStruct); override;
procedure WriteStructEnd; override; procedure WriteStructEnd; override;
procedure WriteFieldBegin(field: IField); override; procedure WriteFieldBegin( const field: IField); override;
procedure WriteFieldEnd; override; procedure WriteFieldEnd; override;
procedure WriteFieldStop; override; procedure WriteFieldStop; override;
procedure WriteMapBegin(map: IMap); override; procedure WriteMapBegin( const map: IMap); override;
procedure WriteMapEnd; override; procedure WriteMapEnd; override;
procedure WriteListBegin( list: IList); override; procedure WriteListBegin( const list: IList); override;
procedure WriteListEnd(); override; procedure WriteListEnd(); override;
procedure WriteSetBegin( set_: ISet ); override; procedure WriteSetBegin( const set_: ISet ); override;
procedure WriteSetEnd(); override; procedure WriteSetEnd(); override;
procedure WriteBool( b: Boolean); override; procedure WriteBool( b: Boolean); override;
procedure WriteByte( b: ShortInt); override; procedure WriteByte( b: ShortInt); override;
procedure WriteI16( i16: SmallInt); override; procedure WriteI16( i16: SmallInt); override;
procedure WriteI32( i32: Integer); override; procedure WriteI32( i32: Integer); override;
procedure WriteI64( i64: Int64); override; procedure WriteI64( const i64: Int64); override;
procedure WriteDouble( d: Double); override; procedure WriteDouble( const d: Double); override;
procedure WriteBinary( const b: TBytes); override; procedure WriteBinary( const b: TBytes); override;
function ReadMessageBegin: IMessage; override; function ReadMessageBegin: IMessage; override;
@ -439,13 +439,13 @@ type
implementation implementation
function ConvertInt64ToDouble( n: Int64): Double; function ConvertInt64ToDouble( const n: Int64): Double;
begin begin
ASSERT( SizeOf(n) = SizeOf(Result)); ASSERT( SizeOf(n) = SizeOf(Result));
System.Move( n, Result, SizeOf(Result)); System.Move( n, Result, SizeOf(Result));
end; end;
function ConvertDoubleToInt64( d: Double): Int64; function ConvertDoubleToInt64( const d: Double): Int64;
begin begin
ASSERT( SizeOf(d) = SizeOf(Result)); ASSERT( SizeOf(d) = SizeOf(Result));
System.Move( d, Result, SizeOf(Result)); System.Move( d, Result, SizeOf(Result));
@ -739,7 +739,7 @@ end;
{ TBinaryProtocolImpl } { TBinaryProtocolImpl }
constructor TBinaryProtocolImpl.Create( trans: ITransport); constructor TBinaryProtocolImpl.Create( const trans: ITransport);
begin begin
Create( trans, False, True); Create( trans, False, True);
end; end;
@ -756,7 +756,7 @@ begin
end; end;
end; end;
constructor TBinaryProtocolImpl.Create(trans: ITransport; strictRead, constructor TBinaryProtocolImpl.Create( const trans: ITransport; strictRead,
strictWrite: Boolean); strictWrite: Boolean);
begin begin
inherited Create( trans ); inherited Create( trans );
@ -997,12 +997,12 @@ begin
FTrans.Write( a, 0, 1 ); FTrans.Write( a, 0, 1 );
end; end;
procedure TBinaryProtocolImpl.WriteDouble(d: Double); procedure TBinaryProtocolImpl.WriteDouble( const d: Double);
begin begin
WriteI64(ConvertDoubleToInt64(d)); WriteI64(ConvertDoubleToInt64(d));
end; end;
procedure TBinaryProtocolImpl.WriteFieldBegin(field: IField); procedure TBinaryProtocolImpl.WriteFieldBegin( const field: IField);
begin begin
WriteByte(ShortInt(field.Type_)); WriteByte(ShortInt(field.Type_));
WriteI16(field.ID); WriteI16(field.ID);
@ -1040,7 +1040,7 @@ begin
FTrans.Write( i32out, 0, 4); FTrans.Write( i32out, 0, 4);
end; end;
procedure TBinaryProtocolImpl.WriteI64(i64: Int64); procedure TBinaryProtocolImpl.WriteI64( const i64: Int64);
var var
i64out : TBytes; i64out : TBytes;
begin begin
@ -1056,7 +1056,7 @@ begin
FTrans.Write( i64out, 0, 8); FTrans.Write( i64out, 0, 8);
end; end;
procedure TBinaryProtocolImpl.WriteListBegin(list: IList); procedure TBinaryProtocolImpl.WriteListBegin( const list: IList);
begin begin
WriteByte(ShortInt(list.ElementType)); WriteByte(ShortInt(list.ElementType));
WriteI32(list.Count); WriteI32(list.Count);
@ -1067,7 +1067,7 @@ begin
end; end;
procedure TBinaryProtocolImpl.WriteMapBegin(map: IMap); procedure TBinaryProtocolImpl.WriteMapBegin( const map: IMap);
begin begin
WriteByte(ShortInt(map.KeyType)); WriteByte(ShortInt(map.KeyType));
WriteByte(ShortInt(map.ValueType)); WriteByte(ShortInt(map.ValueType));
@ -1079,21 +1079,21 @@ begin
end; end;
procedure TBinaryProtocolImpl.WriteMessageBegin( message: IMessage); procedure TBinaryProtocolImpl.WriteMessageBegin( const msg: IMessage);
var var
version : Cardinal; version : Cardinal;
begin begin
if FStrictWrite then if FStrictWrite then
begin begin
version := VERSION_1 or Cardinal( message.Type_); version := VERSION_1 or Cardinal( msg.Type_);
WriteI32( Integer( version) ); WriteI32( Integer( version) );
WriteString( message.Name); WriteString( msg.Name);
WriteI32(message.SeqID); WriteI32( msg.SeqID);
end else end else
begin begin
WriteString(message.Name); WriteString( msg.Name);
WriteByte(ShortInt(message.Type_)); WriteByte(ShortInt( msg.Type_));
WriteI32(message.SeqID); WriteI32( msg.SeqID);
end; end;
end; end;
@ -1102,7 +1102,7 @@ begin
end; end;
procedure TBinaryProtocolImpl.WriteSetBegin(set_: ISet); procedure TBinaryProtocolImpl.WriteSetBegin( const set_: ISet);
begin begin
WriteByte(ShortInt(set_.ElementType)); WriteByte(ShortInt(set_.ElementType));
WriteI32(set_.Count); WriteI32(set_.Count);
@ -1113,7 +1113,7 @@ begin
end; end;
procedure TBinaryProtocolImpl.WriteStructBegin(struc: IStruct); procedure TBinaryProtocolImpl.WriteStructBegin( const struc: IStruct);
begin begin
end; end;
@ -1169,7 +1169,7 @@ begin
Create( False, True ) Create( False, True )
end; end;
function TBinaryProtocolImpl.TFactory.GetProtocol(trans: ITransport): IProtocol; function TBinaryProtocolImpl.TFactory.GetProtocol( const trans: ITransport): IProtocol;
begin begin
Result := TBinaryProtocolImpl.Create( trans ); Result := TBinaryProtocolImpl.Create( trans );
end; end;

View File

@ -37,7 +37,7 @@ type
TServerImpl = class abstract( TInterfacedObject, IServer ) TServerImpl = class abstract( TInterfacedObject, IServer )
public public
type type
TLogDelegate = reference to procedure( str: string); TLogDelegate = reference to procedure( const str: string);
protected protected
FProcessor : IProcessor; FProcessor : IProcessor;
FServerTransport : IServerTransport; FServerTransport : IServerTransport;
@ -47,41 +47,43 @@ type
FOutputProtocolFactory : IProtocolFactory; FOutputProtocolFactory : IProtocolFactory;
FLogDelegate : TLogDelegate; FLogDelegate : TLogDelegate;
class procedure DefaultLogDelegate( str: string); class procedure DefaultLogDelegate( const str: string);
procedure Serve; virtual; abstract; procedure Serve; virtual; abstract;
procedure Stop; virtual; abstract; procedure Stop; virtual; abstract;
public public
constructor Create( constructor Create(
AProcessor :IProcessor; const AProcessor :IProcessor;
AServerTransport: IServerTransport; const AServerTransport: IServerTransport;
AInputTransportFactory : ITransportFactory; const AInputTransportFactory : ITransportFactory;
AOutputTransportFactory : ITransportFactory; const AOutputTransportFactory : ITransportFactory;
AInputProtocolFactory : IProtocolFactory; const AInputProtocolFactory : IProtocolFactory;
AOutputProtocolFactory : IProtocolFactory; const AOutputProtocolFactory : IProtocolFactory;
ALogDelegate : TLogDelegate const ALogDelegate : TLogDelegate
); overload;
constructor Create( AProcessor :IProcessor;
AServerTransport: IServerTransport); overload;
constructor Create(
AProcessor :IProcessor;
AServerTransport: IServerTransport;
ALogDelegate: TLogDelegate
); overload; ); overload;
constructor Create( constructor Create(
AProcessor :IProcessor; const AProcessor :IProcessor;
AServerTransport: IServerTransport; const AServerTransport: IServerTransport
ATransportFactory : ITransportFactory
); overload; ); overload;
constructor Create( constructor Create(
AProcessor :IProcessor; const AProcessor :IProcessor;
AServerTransport: IServerTransport; const AServerTransport: IServerTransport;
ATransportFactory : ITransportFactory; const ALogDelegate: TLogDelegate
AProtocolFactory : IProtocolFactory ); overload;
constructor Create(
const AProcessor :IProcessor;
const AServerTransport: IServerTransport;
const ATransportFactory : ITransportFactory
); overload;
constructor Create(
const AProcessor :IProcessor;
const AServerTransport: IServerTransport;
const ATransportFactory : ITransportFactory;
const AProtocolFactory : IProtocolFactory
); overload; ); overload;
end; end;
@ -89,13 +91,13 @@ type
private private
FStop : Boolean; FStop : Boolean;
public public
constructor Create( AProcessor: IProcessor; AServerTransport: IServerTransport); overload; constructor Create( const AProcessor: IProcessor; const AServerTransport: IServerTransport); overload;
constructor Create( AProcessor: IProcessor; AServerTransport: IServerTransport; constructor Create( const AProcessor: IProcessor; const AServerTransport: IServerTransport;
ALogDel: TServerImpl.TLogDelegate); overload; ALogDel: TServerImpl.TLogDelegate); overload;
constructor Create( AProcessor: IProcessor; AServerTransport: IServerTransport; constructor Create( const AProcessor: IProcessor; const AServerTransport: IServerTransport;
ATransportFactory: ITransportFactory); overload; const ATransportFactory: ITransportFactory); overload;
constructor Create( AProcessor: IProcessor; AServerTransport: IServerTransport; constructor Create( const AProcessor: IProcessor; const AServerTransport: IServerTransport;
ATransportFactory: ITransportFactory; AProtocolFactory: IProtocolFactory); overload; const ATransportFactory: ITransportFactory; const AProtocolFactory: IProtocolFactory); overload;
procedure Serve; override; procedure Serve; override;
procedure Stop; override; procedure Stop; override;
@ -106,8 +108,8 @@ implementation
{ TServerImpl } { TServerImpl }
constructor TServerImpl.Create(AProcessor: IProcessor; constructor TServerImpl.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport; ALogDelegate: TLogDelegate); const AServerTransport: IServerTransport; const ALogDelegate: TLogDelegate);
var var
InputFactory, OutputFactory : IProtocolFactory; InputFactory, OutputFactory : IProtocolFactory;
InputTransFactory, OutputTransFactory : ITransportFactory; InputTransFactory, OutputTransFactory : ITransportFactory;
@ -129,8 +131,8 @@ begin
); );
end; end;
constructor TServerImpl.Create(AProcessor: IProcessor; constructor TServerImpl.Create(const AProcessor: IProcessor;
AServerTransport: IServerTransport); const AServerTransport: IServerTransport);
var var
InputFactory, OutputFactory : IProtocolFactory; InputFactory, OutputFactory : IProtocolFactory;
InputTransFactory, OutputTransFactory : ITransportFactory; InputTransFactory, OutputTransFactory : ITransportFactory;
@ -152,8 +154,8 @@ begin
); );
end; end;
constructor TServerImpl.Create(AProcessor: IProcessor; constructor TServerImpl.Create(const AProcessor: IProcessor;
AServerTransport: IServerTransport; ATransportFactory: ITransportFactory); const AServerTransport: IServerTransport; const ATransportFactory: ITransportFactory);
var var
InputProtocolFactory : IProtocolFactory; InputProtocolFactory : IProtocolFactory;
OutputProtocolFactory : IProtocolFactory; OutputProtocolFactory : IProtocolFactory;
@ -165,11 +167,11 @@ begin
InputProtocolFactory, OutputProtocolFactory, DefaultLogDelegate); InputProtocolFactory, OutputProtocolFactory, DefaultLogDelegate);
end; end;
constructor TServerImpl.Create(AProcessor: IProcessor; constructor TServerImpl.Create(const AProcessor: IProcessor;
AServerTransport: IServerTransport; AInputTransportFactory, const AServerTransport: IServerTransport;
AOutputTransportFactory: ITransportFactory; AInputProtocolFactory, const AInputTransportFactory, AOutputTransportFactory: ITransportFactory;
AOutputProtocolFactory: IProtocolFactory; const AInputProtocolFactory, AOutputProtocolFactory: IProtocolFactory;
ALogDelegate : TLogDelegate); const ALogDelegate : TLogDelegate);
begin begin
FProcessor := AProcessor; FProcessor := AProcessor;
FServerTransport := AServerTransport; FServerTransport := AServerTransport;
@ -180,14 +182,14 @@ begin
FLogDelegate := ALogDelegate; FLogDelegate := ALogDelegate;
end; end;
class procedure TServerImpl.DefaultLogDelegate( str: string); class procedure TServerImpl.DefaultLogDelegate( const str: string);
begin begin
Writeln( str ); Writeln( str );
end; end;
constructor TServerImpl.Create(AProcessor: IProcessor; constructor TServerImpl.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport; ATransportFactory: ITransportFactory; const AServerTransport: IServerTransport; const ATransportFactory: ITransportFactory;
AProtocolFactory: IProtocolFactory); const AProtocolFactory: IProtocolFactory);
begin begin
Create( AProcessor, AServerTransport, Create( AProcessor, AServerTransport,
ATransportFactory, ATransportFactory, ATransportFactory, ATransportFactory,
@ -197,8 +199,8 @@ end;
{ TSimpleServer } { TSimpleServer }
constructor TSimpleServer.Create(AProcessor: IProcessor; constructor TSimpleServer.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport); const AServerTransport: IServerTransport);
var var
InputProtocolFactory : IProtocolFactory; InputProtocolFactory : IProtocolFactory;
OutputProtocolFactory : IProtocolFactory; OutputProtocolFactory : IProtocolFactory;
@ -214,8 +216,8 @@ begin
OutputTransportFactory, InputProtocolFactory, OutputProtocolFactory, DefaultLogDelegate); OutputTransportFactory, InputProtocolFactory, OutputProtocolFactory, DefaultLogDelegate);
end; end;
constructor TSimpleServer.Create(AProcessor: IProcessor; constructor TSimpleServer.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport; ALogDel: TServerImpl.TLogDelegate); const AServerTransport: IServerTransport; ALogDel: TServerImpl.TLogDelegate);
var var
InputProtocolFactory : IProtocolFactory; InputProtocolFactory : IProtocolFactory;
OutputProtocolFactory : IProtocolFactory; OutputProtocolFactory : IProtocolFactory;
@ -231,16 +233,16 @@ begin
OutputTransportFactory, InputProtocolFactory, OutputProtocolFactory, ALogDel); OutputTransportFactory, InputProtocolFactory, OutputProtocolFactory, ALogDel);
end; end;
constructor TSimpleServer.Create(AProcessor: IProcessor; constructor TSimpleServer.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport; ATransportFactory: ITransportFactory); const AServerTransport: IServerTransport; const ATransportFactory: ITransportFactory);
begin begin
inherited Create( AProcessor, AServerTransport, ATransportFactory, inherited Create( AProcessor, AServerTransport, ATransportFactory,
ATransportFactory, TBinaryProtocolImpl.TFactory.Create, TBinaryProtocolImpl.TFactory.Create, DefaultLogDelegate); ATransportFactory, TBinaryProtocolImpl.TFactory.Create, TBinaryProtocolImpl.TFactory.Create, DefaultLogDelegate);
end; end;
constructor TSimpleServer.Create(AProcessor: IProcessor; constructor TSimpleServer.Create( const AProcessor: IProcessor;
AServerTransport: IServerTransport; ATransportFactory: ITransportFactory; const AServerTransport: IServerTransport; const ATransportFactory: ITransportFactory;
AProtocolFactory: IProtocolFactory); const AProtocolFactory: IProtocolFactory);
begin begin
inherited Create( AProcessor, AServerTransport, ATransportFactory, inherited Create( AProcessor, AServerTransport, ATransportFactory,
ATransportFactory, AProtocolFactory, AProtocolFactory, DefaultLogDelegate); ATransportFactory, AProtocolFactory, AProtocolFactory, DefaultLogDelegate);

View File

@ -68,7 +68,7 @@ type
function IsOpen: Boolean; override; function IsOpen: Boolean; override;
function ToArray: TBytes; override; function ToArray: TBytes; override;
public public
constructor Create( AStream: TStream; AOwnsStream : Boolean); constructor Create( const AStream: TStream; AOwnsStream : Boolean);
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -84,7 +84,7 @@ type
function IsOpen: Boolean; override; function IsOpen: Boolean; override;
function ToArray: TBytes; override; function ToArray: TBytes; override;
public public
constructor Create( AStream: IStream); constructor Create( const AStream: IStream);
end; end;
implementation implementation
@ -96,7 +96,7 @@ begin
FStream := nil; FStream := nil;
end; end;
constructor TThriftStreamAdapterCOM.Create(AStream: IStream); constructor TThriftStreamAdapterCOM.Create( const AStream: IStream);
begin begin
FStream := AStream; FStream := AStream;
end; end;
@ -219,7 +219,7 @@ begin
FOwnsStream := False; FOwnsStream := False;
end; end;
constructor TThriftStreamAdapterDelphi.Create(AStream: TStream; AOwnsStream: Boolean); constructor TThriftStreamAdapterDelphi.Create( const AStream: TStream; AOwnsStream: Boolean);
begin begin
FStream := AStream; FStream := AStream;
FOwnsStream := AOwnsStream; FOwnsStream := AOwnsStream;

View File

@ -145,11 +145,11 @@ type
ITransportFactory = interface ITransportFactory = interface
['{DD809446-000F-49E1-9BFF-E0D0DC76A9D7}'] ['{DD809446-000F-49E1-9BFF-E0D0DC76A9D7}']
function GetTransport( ATrans: ITransport): ITransport; function GetTransport( const ATrans: ITransport): ITransport;
end; end;
TTransportFactoryImpl = class( TInterfacedObject, ITransportFactory) TTransportFactoryImpl = class( TInterfacedObject, ITransportFactory)
function GetTransport( ATrans: ITransport): ITransport; virtual; function GetTransport( const ATrans: ITransport): ITransport; virtual;
end; end;
TTcpSocketStreamImpl = class( TThriftStreamImpl ) TTcpSocketStreamImpl = class( TThriftStreamImpl )
@ -165,7 +165,7 @@ type
function IsOpen: Boolean; override; function IsOpen: Boolean; override;
function ToArray: TBytes; override; function ToArray: TBytes; override;
public public
constructor Create( ATcpClient: TCustomIpClient); constructor Create( const ATcpClient: TCustomIpClient);
end; end;
IStreamTransport = interface( ITransport ) IStreamTransport = interface( ITransport )
@ -194,7 +194,7 @@ type
procedure Flush; override; procedure Flush; override;
function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override; function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
procedure Write( const buf: TBytes; off: Integer; len: Integer); override; procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
constructor Create( AInputStream : IThriftStream; AOutputStream : IThriftStream); constructor Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -212,7 +212,7 @@ type
function IsOpen: Boolean; override; function IsOpen: Boolean; override;
function ToArray: TBytes; override; function ToArray: TBytes; override;
public public
constructor Create( AStream: IThriftStream; ABufSize: Integer); constructor Create( const AStream: IThriftStream; ABufSize: Integer);
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -226,8 +226,8 @@ type
protected protected
function AcceptImpl: ITransport; override; function AcceptImpl: ITransport; override;
public public
constructor Create( AServer: TTcpServer ); overload; constructor Create( const AServer: TTcpServer ); overload;
constructor Create( AServer: TTcpServer; AClientTimeout: Integer); overload; constructor Create( const AServer: TTcpServer; AClientTimeout: Integer); overload;
constructor Create( APort: Integer); overload; constructor Create( APort: Integer); overload;
constructor Create( APort: Integer; AClientTimeout: Integer); overload; constructor Create( APort: Integer; AClientTimeout: Integer); overload;
constructor Create( APort: Integer; AClientTimeout: Integer; constructor Create( APort: Integer; AClientTimeout: Integer;
@ -254,8 +254,8 @@ type
procedure Close(); override; procedure Close(); override;
function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override; function Read(var buf: TBytes; off: Integer; len: Integer): Integer; override;
procedure Write( const buf: TBytes; off: Integer; len: Integer); override; procedure Write( const buf: TBytes; off: Integer; len: Integer); override;
constructor Create( ATransport : IStreamTransport ); overload; constructor Create( const ATransport : IStreamTransport ); overload;
constructor Create( ATransport : IStreamTransport; ABufSize: Integer); overload; constructor Create( const ATransport : IStreamTransport; ABufSize: Integer); overload;
property UnderlyingTransport: ITransport read GetUnderlyingTransport; property UnderlyingTransport: ITransport read GetUnderlyingTransport;
property IsOpen: Boolean read GetIsOpen; property IsOpen: Boolean read GetIsOpen;
end; end;
@ -273,7 +273,7 @@ type
function GetIsOpen: Boolean; override; function GetIsOpen: Boolean; override;
public public
procedure Open; override; procedure Open; override;
constructor Create( AClient : TCustomIpClient); overload; constructor Create( const AClient : TCustomIpClient); overload;
constructor Create( const AHost: string; APort: Integer); overload; constructor Create( const AHost: string; APort: Integer); overload;
constructor Create( const AHost: string; APort: Integer; ATimeout: Integer); overload; constructor Create( const AHost: string; APort: Integer; ATimeout: Integer); overload;
destructor Destroy; override; destructor Destroy; override;
@ -299,14 +299,14 @@ type
type type
TFactory = class( TTransportFactoryImpl ) TFactory = class( TTransportFactoryImpl )
public public
function GetTransport( ATrans: ITransport): ITransport; override; function GetTransport( const ATrans: ITransport): ITransport; override;
end; end;
{$IF CompilerVersion >= 21.0} {$IF CompilerVersion >= 21.0}
class constructor Create; class constructor Create;
{$IFEND} {$IFEND}
constructor Create; overload; constructor Create; overload;
constructor Create( ATrans: ITransport); overload; constructor Create( const ATrans: ITransport); overload;
destructor Destroy; override; destructor Destroy; override;
procedure Open(); override; procedure Open(); override;
@ -528,20 +528,20 @@ end;
{ TTransportFactoryImpl } { TTransportFactoryImpl }
function TTransportFactoryImpl.GetTransport(ATrans: ITransport): ITransport; function TTransportFactoryImpl.GetTransport( const ATrans: ITransport): ITransport;
begin begin
Result := ATrans; Result := ATrans;
end; end;
{ TServerSocket } { TServerSocket }
constructor TServerSocketImpl.Create(AServer: TTcpServer; AClientTimeout: Integer); constructor TServerSocketImpl.Create( const AServer: TTcpServer; AClientTimeout: Integer);
begin begin
FServer := AServer; FServer := AServer;
FClientTimeout := AClientTimeout; FClientTimeout := AClientTimeout;
end; end;
constructor TServerSocketImpl.Create(AServer: TTcpServer); constructor TServerSocketImpl.Create( const AServer: TTcpServer);
begin begin
Create( AServer, 0 ); Create( AServer, 0 );
end; end;
@ -658,7 +658,7 @@ end;
{ TSocket } { TSocket }
constructor TSocketImpl.Create(AClient : TCustomIpClient); constructor TSocketImpl.Create( const AClient : TCustomIpClient);
var var
stream : IThriftStream; stream : IThriftStream;
begin begin
@ -773,7 +773,7 @@ begin
FBuffer := nil; FBuffer := nil;
end; end;
constructor TBufferedStreamImpl.Create(AStream: IThriftStream; ABufSize: Integer); constructor TBufferedStreamImpl.Create( const AStream: IThriftStream; ABufSize: Integer);
begin begin
FStream := AStream; FStream := AStream;
FBufSize := ABufSize; FBufSize := ABufSize;
@ -903,7 +903,7 @@ begin
end; end;
end; end;
constructor TStreamTransportImpl.Create( AInputStream : IThriftStream; AOutputStream : IThriftStream); constructor TStreamTransportImpl.Create( const AInputStream : IThriftStream; const AOutputStream : IThriftStream);
begin begin
FInputStream := AInputStream; FInputStream := AInputStream;
FOutputStream := AOutputStream; FOutputStream := AOutputStream;
@ -967,7 +967,7 @@ end;
{ TBufferedTransportImpl } { TBufferedTransportImpl }
constructor TBufferedTransportImpl.Create(ATransport: IStreamTransport); constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport);
begin begin
Create( ATransport, 1024 ); Create( ATransport, 1024 );
end; end;
@ -977,7 +977,7 @@ begin
FTransport.Close; FTransport.Close;
end; end;
constructor TBufferedTransportImpl.Create(ATransport: IStreamTransport; constructor TBufferedTransportImpl.Create( const ATransport: IStreamTransport;
ABufSize: Integer); ABufSize: Integer);
begin begin
FTransport := ATransport; FTransport := ATransport;
@ -1064,7 +1064,7 @@ begin
FTransport.Close; FTransport.Close;
end; end;
constructor TFramedTransportImpl.Create(ATrans: ITransport); constructor TFramedTransportImpl.Create( const ATrans: ITransport);
begin begin
InitWriteBuffer; InitWriteBuffer;
FTransport := ATrans; FTransport := ATrans;
@ -1176,7 +1176,7 @@ end;
{ TFramedTransport.TFactory } { TFramedTransport.TFactory }
function TFramedTransportImpl.TFactory.GetTransport(ATrans: ITransport): ITransport; function TFramedTransportImpl.TFactory.GetTransport( const ATrans: ITransport): ITransport;
begin begin
Result := TFramedTransportImpl.Create( ATrans ); Result := TFramedTransportImpl.Create( ATrans );
end; end;
@ -1188,7 +1188,7 @@ begin
FTcpClient.Close; FTcpClient.Close;
end; end;
constructor TTcpSocketStreamImpl.Create(ATcpClient: TCustomIpClient); constructor TTcpSocketStreamImpl.Create( const ATcpClient: TCustomIpClient);
begin begin
FTcpClient := ATcpClient; FTcpClient := ATcpClient;
end; end;

View File

@ -30,7 +30,7 @@ const
type type
IProcessor = interface IProcessor = interface
['{B1538A07-6CAC-4406-8A4C-AFED07C70A89}'] ['{B1538A07-6CAC-4406-8A4C-AFED07C70A89}']
function Process( iprot :IProtocol; oprot: IProtocol): Boolean; function Process( const iprot :IProtocol; const oprot: IProtocol): Boolean;
end; end;
TApplicationException = class( SysUtils.Exception ) TApplicationException = class( SysUtils.Exception )
@ -53,8 +53,8 @@ type
constructor Create( AType: TExceptionType); overload; constructor Create( AType: TExceptionType); overload;
constructor Create( AType: TExceptionType; const msg: string); overload; constructor Create( AType: TExceptionType; const msg: string); overload;
class function Read( iprot: IProtocol): TApplicationException; class function Read( const iprot: IProtocol): TApplicationException;
procedure Write( oprot: IProtocol ); procedure Write( const oprot: IProtocol );
end; end;
// base class for IDL-generated exceptions // base class for IDL-generated exceptions
@ -102,8 +102,7 @@ begin
FType := AType; FType := AType;
end; end;
class function TApplicationException.Read( class function TApplicationException.Read( const iprot: IProtocol): TApplicationException;
iprot: IProtocol): TApplicationException;
var var
field : IField; field : IField;
msg : string; msg : string;
@ -149,7 +148,7 @@ begin
Result := TApplicationException.Create( typ, msg ); Result := TApplicationException.Create( typ, msg );
end; end;
procedure TApplicationException.Write(oprot: IProtocol); procedure TApplicationException.Write( const oprot: IProtocol);
var var
struc : IStruct; struc : IStruct;
field : IField; field : IField;

View File

@ -65,7 +65,7 @@ type
protected protected
procedure Execute; override; procedure Execute; override;
public public
constructor Create(ATransport: ITransport; AProtocol : IProtocol; ANumIteration: Integer); constructor Create( const ATransport: ITransport; const AProtocol : IProtocol; ANumIteration: Integer);
destructor Destroy; override; destructor Destroy; override;
end; end;
@ -880,7 +880,7 @@ begin
end; end;
constructor TClientThread.Create(ATransport: ITransport; AProtocol : IProtocol; ANumIteration: Integer); constructor TClientThread.Create( const ATransport: ITransport; const AProtocol : IProtocol; ANumIteration: Integer);
begin begin
inherited Create( True ); inherited Create( True );
FNumIteration := ANumIteration; FNumIteration := ANumIteration;

View File

@ -42,7 +42,7 @@ type
type type
ITestHandler = interface( TThriftTest.Iface ) ITestHandler = interface( TThriftTest.Iface )
procedure SetServer( AServer : IServer ); procedure SetServer( const AServer : IServer );
end; end;
TTestHandlerImpl = class( TInterfacedObject, ITestHandler ) TTestHandlerImpl = class( TInterfacedObject, ITestHandler )
@ -50,39 +50,39 @@ type
FServer : IServer; FServer : IServer;
protected protected
procedure testVoid(); procedure testVoid();
function testString(thing: string): string; function testString(const thing: string): string;
function testByte(thing: ShortInt): ShortInt; function testByte(thing: ShortInt): ShortInt;
function testI32(thing: Integer): Integer; function testI32(thing: Integer): Integer;
function testI64(thing: Int64): Int64; function testI64(const thing: Int64): Int64;
function testDouble(thing: Double): Double; function testDouble(const thing: Double): Double;
function testStruct(thing: IXtruct): IXtruct; function testStruct(const thing: IXtruct): IXtruct;
function testNest(thing: IXtruct2): IXtruct2; function testNest(const thing: IXtruct2): IXtruct2;
function testMap(thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>; function testMap(const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>;
function testStringMap(thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>; function testStringMap(const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>;
function testSet(thing: IHashSet<Integer>): IHashSet<Integer>; function testSet(const thing: IHashSet<Integer>): IHashSet<Integer>;
function testList(thing: IThriftList<Integer>): IThriftList<Integer>; function testList(const thing: IThriftList<Integer>): IThriftList<Integer>;
function testEnum(thing: TNumberz): TNumberz; function testEnum(thing: TNumberz): TNumberz;
function testTypedef(thing: Int64): Int64; function testTypedef(const thing: Int64): Int64;
function testMapMap(hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>; function testMapMap(hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>;
function testInsanity(argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; function testInsanity(const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
function testMulti(arg0: ShortInt; arg1: Integer; arg2: Int64; arg3: IThriftDictionary<SmallInt, string>; arg4: TNumberz; arg5: Int64): IXtruct; function testMulti(arg0: ShortInt; arg1: Integer; const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>; arg4: TNumberz; const arg5: Int64): IXtruct;
procedure testException(arg: string); procedure testException(const arg: string);
function testMultiException(arg0: string; arg1: string): IXtruct; function testMultiException(const arg0: string; const arg1: string): IXtruct;
procedure testOneway(secondsToSleep: Integer); procedure testOneway(secondsToSleep: Integer);
procedure testStop; procedure testStop;
procedure SetServer( AServer : IServer ); procedure SetServer( const AServer : IServer );
end; end;
class procedure Execute( args: array of string); class procedure Execute( const args: array of string);
end; end;
implementation implementation
{ TTestServer.TTestHandlerImpl } { TTestServer.TTestHandlerImpl }
procedure TTestServer.TTestHandlerImpl.SetServer(AServer: IServer); procedure TTestServer.TTestHandlerImpl.SetServer( const AServer: IServer);
begin begin
FServer := AServer; FServer := AServer;
end; end;
@ -93,7 +93,7 @@ begin
Result := thing; Result := thing;
end; end;
function TTestServer.TTestHandlerImpl.testDouble(thing: Double): Double; function TTestServer.TTestHandlerImpl.testDouble( const thing: Double): Double;
begin begin
Console.WriteLine('testDouble("' + FloatToStr( thing ) + '")'); Console.WriteLine('testDouble("' + FloatToStr( thing ) + '")');
Result := thing; Result := thing;
@ -105,7 +105,7 @@ begin
Result := thing; Result := thing;
end; end;
procedure TTestServer.TTestHandlerImpl.testException(arg: string); procedure TTestServer.TTestHandlerImpl.testException(const arg: string);
begin begin
Console.WriteLine('testException(' + arg + ')'); Console.WriteLine('testException(' + arg + ')');
if ( arg = 'Xception') then if ( arg = 'Xception') then
@ -120,14 +120,14 @@ begin
Result := thing; Result := thing;
end; end;
function TTestServer.TTestHandlerImpl.testI64(thing: Int64): Int64; function TTestServer.TTestHandlerImpl.testI64( const thing: Int64): Int64;
begin begin
Console.WriteLine('testI64("' + IntToStr( thing) + '")'); Console.WriteLine('testI64("' + IntToStr( thing) + '")');
Result := thing; Result := thing;
end; end;
function TTestServer.TTestHandlerImpl.testInsanity( function TTestServer.TTestHandlerImpl.testInsanity(
argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
var var
hello, goodbye : IXtruct; hello, goodbye : IXtruct;
crazy : IInsanity; crazy : IInsanity;
@ -178,7 +178,7 @@ begin
end; end;
function TTestServer.TTestHandlerImpl.testList( function TTestServer.TTestHandlerImpl.testList(
thing: IThriftList<Integer>): IThriftList<Integer>; const thing: IThriftList<Integer>): IThriftList<Integer>;
var var
first : Boolean; first : Boolean;
elem : Integer; elem : Integer;
@ -201,7 +201,7 @@ begin
end; end;
function TTestServer.TTestHandlerImpl.testMap( function TTestServer.TTestHandlerImpl.testMap(
thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>; const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>;
var var
first : Boolean; first : Boolean;
key : Integer; key : Integer;
@ -249,8 +249,8 @@ begin
end; end;
function TTestServer.TTestHandlerImpl.testMulti(arg0: ShortInt; arg1: Integer; function TTestServer.TTestHandlerImpl.testMulti(arg0: ShortInt; arg1: Integer;
arg2: Int64; arg3: IThriftDictionary<SmallInt, string>; arg4: TNumberz; const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>;
arg5: Int64): IXtruct; arg4: TNumberz; const arg5: Int64): IXtruct;
var var
hello : IXtruct; hello : IXtruct;
begin begin
@ -263,8 +263,7 @@ begin
Result := hello; Result := hello;
end; end;
function TTestServer.TTestHandlerImpl.testMultiException(arg0, function TTestServer.TTestHandlerImpl.testMultiException( const arg0, arg1: string): IXtruct;
arg1: string): IXtruct;
var var
x2 : TXception2; x2 : TXception2;
begin begin
@ -287,7 +286,7 @@ begin
Result.String_thing := arg1; Result.String_thing := arg1;
end; end;
function TTestServer.TTestHandlerImpl.testNest(thing: IXtruct2): IXtruct2; function TTestServer.TTestHandlerImpl.testNest( const thing: IXtruct2): IXtruct2;
var var
temp : IXtruct; temp : IXtruct;
begin begin
@ -310,7 +309,7 @@ begin
end; end;
function TTestServer.TTestHandlerImpl.testSet( function TTestServer.TTestHandlerImpl.testSet(
thing: IHashSet<Integer>):IHashSet<Integer>; const thing: IHashSet<Integer>):IHashSet<Integer>;
var var
first : Boolean; first : Boolean;
elem : Integer; elem : Integer;
@ -341,19 +340,19 @@ begin
end; end;
end; end;
function TTestServer.TTestHandlerImpl.testString(thing: string): string; function TTestServer.TTestHandlerImpl.testString( const thing: string): string;
begin begin
Console.WriteLine('teststring("' + thing + '")'); Console.WriteLine('teststring("' + thing + '")');
Result := thing; Result := thing;
end; end;
function TTestServer.TTestHandlerImpl.testStringMap( function TTestServer.TTestHandlerImpl.testStringMap(
thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>; const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>;
begin begin
end; end;
function TTestServer.TTestHandlerImpl.testTypedef(thing: Int64): Int64; function TTestServer.TTestHandlerImpl.testTypedef( const thing: Int64): Int64;
begin begin
Console.WriteLine('testTypedef(' + IntToStr( thing) + ')'); Console.WriteLine('testTypedef(' + IntToStr( thing) + ')');
Result := thing; Result := thing;
@ -364,7 +363,7 @@ begin
Console.WriteLine('testVoid()'); Console.WriteLine('testVoid()');
end; end;
function TTestServer.TTestHandlerImpl.testStruct(thing: IXtruct): IXtruct; function TTestServer.TTestHandlerImpl.testStruct( const thing: IXtruct): IXtruct;
begin begin
Console.WriteLine('testStruct({' + Console.WriteLine('testStruct({' +
'"' + thing.String_thing + '", ' + '"' + thing.String_thing + '", ' +
@ -376,7 +375,7 @@ end;
{ TTestServer } { TTestServer }
class procedure TTestServer.Execute(args: array of string); class procedure TTestServer.Execute( const args: array of string);
var var
UseBufferedSockets : Boolean; UseBufferedSockets : Boolean;
UseFramed : Boolean; UseFramed : Boolean;