📄 rvdatabuffer.c
字号:
/************************************************************************
File Name : rvdatabuffer.c
Description :
*************************************************************************
Copyright (c) 2000 , RADVision, Inc. All rights reserved.
*************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision Inc.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVision Inc.
RADVision Inc. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
*************************************************************************
$Revision: $
$Date: 12/08/2000 $
$Author: Scott K. Eaton $
************************************************************************/
#include "rvdatabuffer.h"
#ifdef _DEBUG
#include "stdio.h"
#endif
/******************************************************************
* RvDataBuffer
******************************************************************/
/*$
{function:
{name: rvDataBufferConstruct }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: Constructs a RvDataBuffer object with the specified capacity using
the supplied allocator.}
}
{proto: RvDataBuffer* rvDataBufferConstruct(RvDataBuffer* thisPtr, RvUint32 frontCapacity, RvUint32 backCapacity, RvAlloc* allocatorPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:frontCapacity} {d:The maximum amount of data that can be added to the front of the buffer.}}
{param: {n:backCapacity} {d:The maximum amount of data that can be added to the back of the buffer.}}
{param: {n:allocatorPtr} {d:A pointer to the allocator to use for the buffer.}}
}
{returns: RvDataBuffer *, A pointer to the RvDataBuffer object, if the object
constructs sucessfully, NULL otherwise. }
}
$*/
RvDataBuffer* rvDataBufferConstruct(RvDataBuffer* thisPtr, RvUint32 frontCapacity, RvUint32 backCapacity, RvAlloc* allocatorPtr)
{
thisPtr->allocatorPtr = allocatorPtr;
thisPtr->buffer = (RvUint8 *)rvAllocAllocate(thisPtr->allocatorPtr,frontCapacity + backCapacity);
if(thisPtr->buffer == 0)
return 0;
thisPtr->bufferEnd = thisPtr->buffer + frontCapacity + backCapacity;
thisPtr->data = thisPtr->bufferEnd - backCapacity;
thisPtr->dataEnd = thisPtr->bufferEnd - backCapacity;
return thisPtr;
}
/*$
{function:
{name: rvDataBufferConstructImport }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: Constructs a RvDataBuffer object with a user supplied data buffer.}
}
{proto: RvDataBuffer* rvDataBufferConstructImport(RvDataBuffer* thisPtr, RvUint8* bufferPtr, RvUint32 bufferLength, RvUint32 dataOffset, RvUint32 dataLength, RvAlloc* allocatorPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:bufferPtr} {d:The buffer to use in the RvDataBuffer for storing data.}}
{param: {n:bufferLength} {d:The length of the buffer in bytes.}}
{param: {n:dataOffset} {d:The offset to the data from the pubberPtr in bytes.}}
{param: {n:dataLength} {d:The length of the data in bytes.}}
{param: {n:allocatorPtr} {d:A pointer to the allocator to use to deallocate the buffer on destruction. If
a NULL pointer is suppled the RvDataBuffer will not de-allocate the buffer
on destruction.}}
}
{returns: RvDataBuffer *, A pointer to the RvDataBuffer object, if the object
constructs sucessfully, NULL otherwise. }
}
$*/
RvDataBuffer* rvDataBufferConstructImport(RvDataBuffer* thisPtr, RvUint8* bufferPtr, RvUint32 bufferLength, RvUint32 dataOffset, RvUint32 dataLength, RvAlloc* allocatorPtr)
{
thisPtr->allocatorPtr = allocatorPtr;
thisPtr->buffer = bufferPtr;
thisPtr->bufferEnd = thisPtr->buffer + bufferLength;
thisPtr->data = thisPtr->buffer + dataOffset;
thisPtr->dataEnd = thisPtr->buffer + dataOffset + dataLength;
return thisPtr;
}
/*$
{function:
{name: rvDataBufferDestruct }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: Destructs a RvDataBuffer object. This frees the buffer the object is
using to store data in.}
}
{proto: void rvDataBufferDestruct(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
}
$*/
void rvDataBufferDestruct(RvDataBuffer *thisPtr)
{
if(thisPtr->allocatorPtr != NULL)
rvAllocDeallocate(thisPtr->allocatorPtr,0,thisPtr->buffer);
thisPtr->buffer = 0;
thisPtr->bufferEnd = 0;
thisPtr->data = 0;
thisPtr->dataEnd = 0;
}
#ifdef _DEBUG
/*$
{function:
{name: rvDataBufferToString }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: Puts the current state of the buffer into a string. The state of
the pointers are outputted, as well as the buffer in hex and ASCII
format.}
}
{proto: int rvDataBufferToString(const RvDataBuffer* thisPtr, char* buffer, size_t bufferSize, const char* prefix);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:buffer} {d:The buffer to write the information to.}}
{param: {n:bufferSize} {d:The size of the buffer.}}
{param: {n:prefix} {d:A string to append to the begining of any new
line.}}
}
}
$*/
int rvDataBufferToString(const RvDataBuffer *thisPtr,
char *buffer, size_t bufferSize,
const char *prefix)
{
int offset = 0;
RvUint8 *dataPtr = thisPtr->data;
RvUint8 *linePtr;
int x;
offset += sprintf(&buffer[offset],"%sBuffer : 0x%08X Capacity : %ld\n",prefix,thisPtr->buffer,rvDataBufferGetCapacity(thisPtr));
offset += sprintf(&buffer[offset],"%sBuffer End : 0x%08X Length : %ld\n",prefix,thisPtr->bufferEnd,rvDataBufferGetLength(thisPtr));
offset += sprintf(&buffer[offset],"%sData : 0x%08X Available Front Capacity : %ld\n",prefix,thisPtr->data,(thisPtr->data - thisPtr->buffer));
offset += sprintf(&buffer[offset],"%sData End : 0x%08X Available Back Capacity : %ld\n",prefix,thisPtr->dataEnd,(thisPtr->bufferEnd - thisPtr->dataEnd));
while(dataPtr != thisPtr->dataEnd)
{
linePtr = dataPtr;
offset += sprintf(&buffer[offset],"%s ",prefix);
/* Print Binary */
for(x = 0; x < 16; x++)
{
offset += sprintf(&buffer[offset],"%02X", *dataPtr++);
if(x%4 == 3)
offset += sprintf(&buffer[offset]," ");
if(dataPtr == thisPtr->dataEnd)
break;
}
/* Pad out the line */
for(x++; x < 16; x++)
{
if(x%4 == 3)
offset += sprintf(&buffer[offset]," ");
offset += sprintf(&buffer[offset]," ");
}
/* Print Seperator */
offset += sprintf(&buffer[offset]," | ");
dataPtr = linePtr;
/* Print ASCII */
for(x = 0; x < 16; x++)
{
if(isprint(*dataPtr))
offset += sprintf(&buffer[offset],"%c", *dataPtr);
else
offset += sprintf(&buffer[offset],".", *dataPtr);
dataPtr++;
if(dataPtr == thisPtr->dataEnd)
break;
}
offset += sprintf(&buffer[offset],"\n");
}
return offset;
}
#endif
/*$
{function:
{name: rvDataBufferGetData }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns a pointer to the begining of the buffer's data.}
}
{proto: RvUint8* rvDataBufferGetData(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: A pointer to the begining of the buffer's data. }
}
$*/
/*$
{function:
{name: rvDataBufferGetLength }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns the length of the buffer's data in bytes.}
}
{proto: RvUint32 rvDataBufferGetLength(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: The length of the buffer's data in bytes. }
}
$*/
/*$
{function:
{name: rvDataBufferSetLength }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method set the length of the buffer's data in bytes. This moves the
head of the data to 'length' bytes before the current end of the buffer.
Caution should be used when using this method to not set the length
beyond the front of the buffer.}
}
{proto: void rvDataBufferSetLength(RvDataBuffer* thisPtr, RvUint32 length);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:length} {d:The RvDataBuffer object.}}
}
}
$*/
/*$
{function:
{name: rvDataBufferGetBuffer }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns a pointer to the begining of the buffer.}
}
{proto: RvUint8* rvDataBufferGetBuffer(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: A pointer to the begining of the buffer. }
}
$*/
/*$
{function:
{name: rvDataBufferGetCapacity }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns the maximum number of bytes that the
buffer can hold.}
}
{proto: RvUint32 rvDataBufferGetCapacity(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: The maximum number of bytes that the buffer can hold. }
}
$*/
/*$
{function:
{name: rvDataBufferGetAvailableFrontCapacity }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns the number of bytes still available at the front
of the buffer.}
}
{proto: RvUint32 rvDataBufferGetAvailableFrontCapacity(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: The number of bytes still available at the front of the buffer.}
}
$*/
/*$
{function:
{name: rvDataBufferGetAvailableBackCapacity }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method returns the number of bytes still available at the back
of the buffer.}
}
{proto: RvUint32 rvDataBufferGetAvailableBackCapacity(RvDataBuffer* thisPtr);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
}
{returns: The number of bytes still available at the back of the buffer.}
}
$*/
/*$
{function:
{name: rvDataBufferSetDataPosition }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method sets the position of the data within the buffer. This only
moves the internal pointers within the buffer, it does not move the data
values in the buffer. If you have manually inserted data into the buffer
using the buffer returned from rvDataBufferGetBuffer, you can use this
method to let the RvDataBuffer know were the data has been placed.}
}
{proto: void rvDataBufferSetDataPosition(RvDataBuffer* thisPtr, RvUint32 offset, RvUint32 length);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:offset} {d:The offset into the buffer, in bytes, where the data begins.}}
{param: {n:length} {d:The length of the data in bytes.}}
}
}
$*/
/*$
{function:
{name: rvDataBufferRewind }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method moves the front reading pointer backwords by n bytes to allow
older data to be read again.}
}
{proto: void rvDataBufferRewind(RvDataBuffer* thisPtr, RvUint32 size);}
{params:
{param: {n:thisPtr} {d:The RvDataBuffer object.}}
{param: {n:size} {d:The number of bytes to rewind.}}
}
}
$*/
/*$
{function:
{name: rvDataBufferSkip }
{class: RvDataBuffer}
{include: rvdatabuffer.h}
{description:
{p: This method moves the front reading pointer forwords by a variable number
of bytes without reading the value.}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -