Converting from Indy 9 to Indy 10

Giganews Newsgroups
Subject: Converting from Indy 9 to Indy 10
Posted by:  Malcolm Smith (malco…@mjfreelancing.com)
Date: Sat, 25 Aug 2007

I have a library that I need to port over to C++Builder 2007 (with Indy 10).

I have several read/write functions (used by some meta-programming template
code) such as shown below:

Indy 9 version
===========
void __fastcall Nmjfindy::ReadBuffer( TIdTCPConnection *AConnection,
void *ADest, unsigned int ASize )
{
AConnection->ReadBuffer( ADest, ASize );
}

void __fastcall Nmjfindy::WriteBuffer( TIdTCPConnection *AConnection,
const Nmjfindy::TDynamicBuffer &ASource, int AByteCOunt )
{

// Nmjfindy::TDynamicBuffer  is a typedef for std::vector<byte>

int SourceSize = ( AByteCOunt > 0 ? AByteCOunt : ASource.size() );

Nmjfindy::WriteInt( AConnection, SourceSize );

if( SourceSize > 0 )
AConnection->WriteBuffer( (&ASource[0]), SourceSize, false );
}

Is the following code the best conversion that can be achieved.  I don't
like
having to create temporary objects all the time in each function as my code
is time critical.

Indy 10 version
===========

void __fastcall Nmjfindy::ReadBuffer( TIdTCPConnection *AConnection,
void *ADest, unsigned int ASize )
{
Idglobal::TBytes ABytes;
AConnection->Socket->ReadBytes( ABytes, ASize, true );
Idglobal::BytesToRaw( ABytes, ADest, ASize );
}

void __fastcall Nmjfindy::WriteBuffer( TIdTCPConnection *AConnection,
const Nmjfindy::TDynamicBuffer &ASource, int AByteCOunt )
{

// Nmjfindy::TDynamicBuffer  is a typedef for std::vector<byte>

int SourceSize = ( AByteCOunt > 0 ? AByteCOunt : ASource.size() );

Nmjfindy::WriteInt( AConnection, SourceSize );

if( SourceSize > 0 )
{
Idglobal::TBytes ABytes = Idglobal::RawToBytes( (&ASource[0]),
SourceSize );
AConnection->Socket->Write( ABytes );
}
}

--
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com

Replies