Write out to the supplied buffer, from the current position, upto maxBytes. Do not increment the iterator.
| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | hzXbuf::Iter::Write | (void*,uint32_t,) |
Declared in file: hzXbuf.h
Defined in file : hzXbuf.cpp
Function Logic:
Function body:
uint32_t hzXbuf::Iter::Write (void* pBuf)uint32_t maxBytes,
{
// Write out to the supplied buffer, from the current position, upto maxBytes. Do not increment the iterator.
//
// Arguments: 1) pBuf The output buffer
// 2) maxBytes The maximum number to write (size of buffer)
//
// Returns: Number of bytes written to the buffer
_hzfunc("hzXbuf::Iter::Write") ;
_xblk* zp ; // Working block pointer
uchar* i ; // Input iterator
uint32_t nOset ; // Current offset
uint32_t nAvail ; // Max number of bytes that can be written from current block
uint32_t nWritten = 0; // Limiter
if (maxBytes < 0)
return -1;
zp = (_xblk*) m_block ;
if (!zp)
return -1;
nOset = m_nOset ;
i = (uchar*) pBuf ;
for (; nWritten < maxBytes ;)
{
if (nOset == zp->xize)
{
// At end of current block, move to next
zp = zp->Next() ;
if (!zp)
break ;
nOset = 0;
}
nAvail = zp->xize - nOset ;
if ((nWritten + nAvail) > maxBytes)
nAvail = maxBytes - nWritten ;
// Add bytes to current block
memcpy(i, zp->m_Data + nOset, nAvail) ;
nOset += nAvail ;
i += nAvail ;
nWritten += nAvail ;
}
return nWritten ;
}