XRootD
Loading...
Searching...
No Matches
XrdCl::Buffer Class Reference

Binary blob representation. More...

#include <XrdClBuffer.hh>

+ Inheritance diagram for XrdCl::Buffer:
+ Collaboration diagram for XrdCl::Buffer:

Public Member Functions

 Buffer (Buffer &&buffer)
 Move Constructor.
 
 Buffer (uint32_t size=0)
 Constructor.
 
virtual ~Buffer ()
 Destructor.
 
void AdvanceCursor (uint32_t delta)
 Advance the cursor.
 
void Allocate (uint32_t size)
 Allocate the buffer.
 
void Append (const char *buffer, uint32_t size)
 Append data at the position pointed to by the append cursor.
 
void Append (const char *buffer, uint32_t size, uint32_t offset)
 Append data at the given offset.
 
void Free ()
 Free the buffer.
 
void FromString (const std::string str)
 Fill the buffer from a string.
 
char * GetBuffer (uint32_t offset=0)
 Get the message buffer.
 
const char * GetBuffer (uint32_t offset=0) const
 Get the message buffer.
 
char * GetBufferAtCursor ()
 Get the buffer pointer at the append cursor.
 
const char * GetBufferAtCursor () const
 Get the buffer pointer at the append cursor.
 
uint32_t GetCursor () const
 Get append cursor.
 
uint32_t GetSize () const
 Get the size of the message.
 
void Grab (char *buffer, uint32_t size)
 Grab a buffer allocated outside.
 
Bufferoperator= (Buffer &&buffer)
 Move assignment operator.
 
void ReAllocate (uint32_t size)
 Reallocate the buffer to a new location of a given size.
 
char * Release ()
 Release the buffer.
 
void SetCursor (uint32_t cursor)
 Set the cursor.
 
std::string ToString () const
 Convert the buffer to a string.
 
void Zero ()
 Zero.
 

Protected Member Functions

void Steal (Buffer &&buffer)
 

Detailed Description

Binary blob representation.

Definition at line 33 of file XrdClBuffer.hh.

Constructor & Destructor Documentation

◆ Buffer() [1/2]

XrdCl::Buffer::Buffer ( uint32_t size = 0)
inline

Constructor.

Definition at line 39 of file XrdClBuffer.hh.

39 : pBuffer(0), pSize(0), pCursor(0)
40 {
41 if( size )
42 {
43 Allocate( size );
44 }
45 }
void Allocate(uint32_t size)
Allocate the buffer.

References Allocate().

+ Here is the call graph for this function:

◆ Buffer() [2/2]

XrdCl::Buffer::Buffer ( Buffer && buffer)
inline

Move Constructor.

Definition at line 50 of file XrdClBuffer.hh.

51 {
52 Steal( std::move( buffer ) );
53 }
void Steal(Buffer &&buffer)

References Steal().

+ Here is the call graph for this function:

◆ ~Buffer()

virtual XrdCl::Buffer::~Buffer ( )
inlinevirtual

Destructor.

Definition at line 67 of file XrdClBuffer.hh.

67{ Free(); }
void Free()
Free the buffer.

References Free().

+ Here is the call graph for this function:

Member Function Documentation

◆ AdvanceCursor()

void XrdCl::Buffer::AdvanceCursor ( uint32_t delta)
inline

Advance the cursor.

Definition at line 156 of file XrdClBuffer.hh.

157 {
158 pCursor += delta;
159 }

Referenced by XrdCl::XRootDTransport::GetBody(), XrdCl::XRootDTransport::GetHeader(), XrdCl::XRootDTransport::GetMore(), XrdEc::WrtBuff::Pad(), XrdCl::Socket::Send(), XrdEc::WrtBuff::Write(), and XrdCl::XRootDMsgHandler::WriteMessageBody().

+ Here is the caller graph for this function:

◆ Allocate()

void XrdCl::Buffer::Allocate ( uint32_t size)
inline

Allocate the buffer.

Definition at line 110 of file XrdClBuffer.hh.

111 {
112 if( !size )
113 return;
114
115 pBuffer = (char *)malloc( size );
116 if( !pBuffer )
117 throw std::bad_alloc();
118 pSize = size;
119 }

Referenced by Buffer(), XrdCl::XRootDTransport::GetHeader(), and XrdEc::WrtBuff::Pad().

+ Here is the caller graph for this function:

◆ Append() [1/2]

void XrdCl::Buffer::Append ( const char * buffer,
uint32_t size )
inline

Append data at the position pointed to by the append cursor.

Definition at line 164 of file XrdClBuffer.hh.

165 {
166 uint32_t remaining = pSize-pCursor;
167 if( remaining < size )
168 ReAllocate( pCursor+size );
169
170 memcpy( pBuffer+pCursor, buffer, size );
171 pCursor += size;
172 }
void ReAllocate(uint32_t size)
Reallocate the buffer to a new location of a given size.

References ReAllocate().

Referenced by XrdCl::FileSystem::ChMod(), XrdCl::MessageUtils::CreateXAttrBody(), XrdCl::FileSystem::DirList(), XrdCl::FileStateHandler::Fcntl(), XrdCl::FileSystem::Locate(), XrdCl::FileSystem::MkDir(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::Open(), XrdCl::FileSystem::Prepare(), XrdCl::FileSystem::Query(), XrdCl::FileSystem::Rm(), XrdCl::FileSystem::RmDir(), XrdCl::FileSystem::Stat(), XrdCl::FileSystem::StatVFS(), and XrdCl::FileSystem::Truncate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Append() [2/2]

void XrdCl::Buffer::Append ( const char * buffer,
uint32_t size,
uint32_t offset )
inline

Append data at the given offset.

Definition at line 177 of file XrdClBuffer.hh.

178 {
179 uint32_t remaining = pSize-offset;
180 if( remaining < size )
181 ReAllocate( offset+size );
182
183 memcpy( pBuffer+offset, buffer, size );
184 }

References ReAllocate().

+ Here is the call graph for this function:

◆ Free()

void XrdCl::Buffer::Free ( )
inline

Free the buffer.

Definition at line 99 of file XrdClBuffer.hh.

100 {
101 free( pBuffer );
102 pBuffer = 0;
103 pSize = 0;
104 pCursor = 0;
105 }

Referenced by ~Buffer(), and Grab().

+ Here is the caller graph for this function:

◆ FromString()

void XrdCl::Buffer::FromString ( const std::string str)
inline

Fill the buffer from a string.

Definition at line 205 of file XrdClBuffer.hh.

206 {
207 ReAllocate( str.length()+1 );
208 memcpy( pBuffer, str.c_str(), str.length() );
209 pBuffer[str.length()] = 0;
210 }

References ReAllocate().

Referenced by XrdCl::Utils::CheckTPC(), XrdCl::Utils::CheckTPCLite(), XrdCl::EcHandler::Close(), DoQuery(), XrdCl::Utils::GetRemoteCheckSum(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdCl::Utils::GetSupportedCheckSums(), main(), and XrdPosixAdmin::Query().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBuffer() [1/2]

char * XrdCl::Buffer::GetBuffer ( uint32_t offset = 0)
inline

Get the message buffer.

Definition at line 80 of file XrdClBuffer.hh.

81 {
82 return pBuffer+offset;
83 }

◆ GetBuffer() [2/2]

const char * XrdCl::Buffer::GetBuffer ( uint32_t offset = 0) const
inline

Get the message buffer.

Definition at line 72 of file XrdClBuffer.hh.

73 {
74 return pBuffer+offset;
75 }

Referenced by XrdEc::WrtBuff::WrtBuff(), XrdCl::XRootDMsgHandler::XRootDMsgHandler(), XrdCl::Utils::CheckEC(), XrdCl::FileStateHandler::ChkptWrt(), XrdCl::FileStateHandler::ChkptWrtV(), XrdCl::MessageUtils::CreateRequest(), XrdCl::MessageUtils::CreateXAttrBody(), XrdEc::WrtBuff::Encode(), XrdCl::XRootDMsgHandler::Examine(), XrdCl::LocalFileHandler::ExecRequest(), XrdCl::FileStateHandler::Fcntl(), XrdCl::XRootDTransport::GetBody(), GetBufferAtCursor(), GetBufferAtCursor(), XrdCl::XRootDTransport::GetHeader(), XrdCl::XRootDTransport::GetMore(), XrdCl::XRootDMsgHandler::GetSid(), XrdCl::XRootDTransport::GetSignature(), XrdCl::AsyncSocketHandler::HandleWaitRsp(), XrdCl::XRootDMsgHandler::InspectStatusRsp(), XrdCl::XRootDMsgHandler::IsRaw(), XrdCl::XRootDTransport::LogErrorResponse(), main(), main(), XrdCl::XRootDTransport::MarshallRequest(), XrdCl::XRootDTransport::MessageReceived(), XrdCl::XRootDTransport::MessageSent(), XrdCl::XRootDTransport::MultiplexSubStream(), XrdCl::FileSystem::Mv(), XrdCl::FileStateHandler::OnStateError(), XrdCl::FileStateHandler::OnStateResponse(), XrdCl::LocalFileHandler::Open(), XrdEc::WrtBuff::Pad(), XrdCl::FileStateHandler::PgReadImpl(), XrdCl::XRootDMsgHandler::Process(), XrdCl::FileSystem::Query(), XrdPosixAdmin::Query(), XrdCl::XRootDMsgHandler::ReadMessageBody(), XrdCl::MessageUtils::RewriteCGIAndPath(), XrdCl::MessageUtils::SendMessage(), XrdCl::XRootDTransport::SetDescription(), XrdCl::XRootDTransport::UnMarchalStatusMore(), XrdCl::XRootDTransport::UnMarshallBody(), XrdCl::XRootDTransport::UnMarshallHeader(), XrdCl::XRootDTransport::UnMarshallRequest(), XrdCl::XRootDTransport::UnMarshalStatusBody(), XrdCl::FileStateHandler::VectorRead(), XrdCl::FileStateHandler::VectorWrite(), and XrdCl::XRootDMsgHandler::WriteMessageBody().

+ Here is the caller graph for this function:

◆ GetBufferAtCursor() [1/2]

char * XrdCl::Buffer::GetBufferAtCursor ( )
inline

Get the buffer pointer at the append cursor.

Definition at line 189 of file XrdClBuffer.hh.

190 {
191 return GetBuffer( pCursor );
192 }
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.

References GetBuffer().

Referenced by XrdCl::XRootDTransport::GetBody(), XrdCl::XRootDTransport::GetHeader(), XrdCl::XRootDTransport::GetMore(), XrdCl::Socket::Send(), XrdEc::WrtBuff::Write(), and XrdCl::XRootDMsgHandler::WriteMessageBody().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBufferAtCursor() [2/2]

const char * XrdCl::Buffer::GetBufferAtCursor ( ) const
inline

Get the buffer pointer at the append cursor.

Definition at line 197 of file XrdClBuffer.hh.

198 {
199 return GetBuffer( pCursor );
200 }

References GetBuffer().

+ Here is the call graph for this function:

◆ GetCursor()

uint32_t XrdCl::Buffer::GetCursor ( ) const
inline

Get append cursor.

Definition at line 140 of file XrdClBuffer.hh.

141 {
142 return pCursor;
143 }

Referenced by XrdEc::WrtBuff::Complete(), XrdEc::WrtBuff::Empty(), XrdEc::WrtBuff::GetBlkSize(), XrdCl::XRootDTransport::GetBody(), XrdCl::XRootDTransport::GetHeader(), XrdCl::XRootDTransport::GetMore(), XrdEc::WrtBuff::GetStrpSize(), XrdCl::Socket::Send(), XrdEc::WrtBuff::Write(), and XrdCl::XRootDMsgHandler::WriteMessageBody().

+ Here is the caller graph for this function:

◆ GetSize()

uint32_t XrdCl::Buffer::GetSize ( ) const
inline

◆ Grab()

void XrdCl::Buffer::Grab ( char * buffer,
uint32_t size )
inline

Grab a buffer allocated outside.

Definition at line 228 of file XrdClBuffer.hh.

229 {
230 Free();
231 pBuffer = buffer;
232 pSize = size;
233 }

References Free().

Referenced by XrdCl::XRootDTransport::GetSignature().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

Buffer & XrdCl::Buffer::operator= ( Buffer && buffer)
inline

Move assignment operator.

Definition at line 58 of file XrdClBuffer.hh.

59 {
60 Steal( std::move( buffer ) );
61 return *this;
62 }

References Steal().

+ Here is the call graph for this function:

◆ ReAllocate()

void XrdCl::Buffer::ReAllocate ( uint32_t size)
inline

Reallocate the buffer to a new location of a given size.

Definition at line 88 of file XrdClBuffer.hh.

89 {
90 pBuffer = (char *)realloc( pBuffer, size );
91 if( !pBuffer )
92 throw std::bad_alloc();
93 pSize = size;
94 }

Referenced by Append(), Append(), FromString(), XrdCl::XRootDTransport::GetBody(), XrdCl::XRootDTransport::GetMore(), XrdCl::XRootDTransport::MultiplexSubStream(), and XrdCl::MessageUtils::RewriteCGIAndPath().

+ Here is the caller graph for this function:

◆ Release()

char * XrdCl::Buffer::Release ( )
inline

Release the buffer.

Definition at line 238 of file XrdClBuffer.hh.

239 {
240 char *buffer = pBuffer;
241 pBuffer = 0;
242 pSize = 0;
243 pCursor = 0;
244 return buffer;
245 }

◆ SetCursor()

void XrdCl::Buffer::SetCursor ( uint32_t cursor)
inline

Set the cursor.

Definition at line 148 of file XrdClBuffer.hh.

149 {
150 pCursor = cursor;
151 }

Referenced by XrdEc::WrtBuff::Pad(), XrdCl::Socket::Send(), XrdCl::AsyncMsgWriter::Write(), and XrdCl::XRootDMsgHandler::WriteMessageBody().

+ Here is the caller graph for this function:

◆ Steal()

void XrdCl::Buffer::Steal ( Buffer && buffer)
inlineprotected

Definition at line 249 of file XrdClBuffer.hh.

250 {
251 pBuffer = buffer.pBuffer;
252 buffer.pBuffer = 0;
253
254 pSize = buffer.pSize;
255 buffer.pSize = 0;
256
257 pCursor = buffer.pCursor;
258 buffer.pCursor = 0;
259 }

Referenced by Buffer(), operator=(), and XrdCl::Message::operator=().

+ Here is the caller graph for this function:

◆ ToString()

std::string XrdCl::Buffer::ToString ( ) const
inline

Convert the buffer to a string.

Definition at line 215 of file XrdClBuffer.hh.

216 {
217 char *bf = new char[pSize+1];
218 bf[pSize] = 0;
219 memcpy( bf, pBuffer, pSize );
220 std::string tmp = bf;
221 delete [] bf;
222 return tmp;
223 }

Referenced by XrdCl::Utils::CheckTPC(), XrdCl::Utils::CheckTPCLite(), DoCache(), DoPrepare(), DoQuery(), XrdCl::Utils::GetRemoteCheckSum(), XrdCl::FileSystemUtils::GetSpaceInfo(), XrdCl::Utils::GetSupportedCheckSums(), and main().

+ Here is the caller graph for this function:

◆ Zero()

void XrdCl::Buffer::Zero ( )
inline

Zero.

Definition at line 124 of file XrdClBuffer.hh.

125 {
126 memset( pBuffer, 0, pSize );
127 }

Referenced by XrdCl::Message::Message(), and XrdCl::MessageUtils::CreateRequest().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: