ASN1C C/C++ Common Runtime  ASN1C v7.2.x
Classes | Macros | Typedefs | Functions
Memory Buffer Management Functions

Classes

struct  OSRTMEMBUF
 

Macros

#define OSMBDFLTSEGSIZE   1024
 
#define OSMEMBUFPTR(pmb)   ((pmb)->buffer + (pmb)->startidx)
 
#define OSMEMBUFENDPTR(pmb)   ((pmb)->buffer + (pmb)->startidx + (pmb)->usedcnt)
 
#define OSMEMBUFUSEDSIZE(pmb)   ((OSSIZE)(pmb)->usedcnt)
 
#define OSMBAPPENDSTR(pmb, str)
 
#define OSMBAPPENDSTRL(pmb, str)   rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str))
 
#define OSMBAPPENDUTF8(pmb, str)
 

Typedefs

typedef struct OSRTMEMBUF OSRTMEMBUF
 

Functions

int rtxMemBufAppend (OSRTMEMBUF *pMemBuf, const OSOCTET *pdata, OSSIZE nbytes)
 
int rtxMemBufCut (OSRTMEMBUF *pMemBuf, OSSIZE fromOffset, OSSIZE nbytes)
 
void rtxMemBufFree (OSRTMEMBUF *pMemBuf)
 
OSOCTET * rtxMemBufGetData (const OSRTMEMBUF *pMemBuf, int *length)
 
OSOCTET * rtxMemBufGetDataExt (const OSRTMEMBUF *pMemBuf, OSSIZE *length)
 
OSSIZE rtxMemBufGetDataLen (const OSRTMEMBUF *pMemBuf)
 
void rtxMemBufInit (OSCTXT *pCtxt, OSRTMEMBUF *pMemBuf, OSSIZE segsize)
 
void rtxMemBufInitBuffer (OSCTXT *pCtxt, OSRTMEMBUF *pMemBuf, OSOCTET *buf, OSSIZE bufsize, OSSIZE segsize)
 
int rtxMemBufPreAllocate (OSRTMEMBUF *pMemBuf, OSSIZE nbytes)
 
void rtxMemBufReset (OSRTMEMBUF *pMemBuf)
 
int rtxMemBufSet (OSRTMEMBUF *pMemBuf, OSOCTET value, OSSIZE nbytes)
 
OSBOOL rtxMemBufSetExpandable (OSRTMEMBUF *pMemBuf, OSBOOL isExpandable)
 
OSBOOL rtxMemBufSetUseSysMem (OSRTMEMBUF *pMemBuf, OSBOOL value)
 
OSSIZE rtxMemBufTrimW (OSRTMEMBUF *pMemBuf)
 

Detailed Description

Memory buffer management functions handle the allocation, expansion, and deallocation of dynamic memory buffers used by some encode/decode functions. Dynamic memory buffers are buffers that can grow or shrink to hold variable sized amounts of data. This group of functions allows data to be appended to buffers, to be set within buffers, and to be retrieved from buffers. Currently, these functions are used within the generated SAX decode routines to collect data as it is parsed by an XML parser.

Macro Definition Documentation

◆ OSMBAPPENDSTR

#define OSMBAPPENDSTR (   pmb,
  str 
)
Value:
if (0 != str) \
rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str))

◆ OSMBAPPENDUTF8

#define OSMBAPPENDUTF8 (   pmb,
  str 
)
Value:
if (0 != str) \
rtxMemBufAppend(pmb,(OSOCTET*)str,rtxUTF8LenBytes(str))
size_t rtxUTF8LenBytes(const OSUTF8CHAR *inbuf)

Function Documentation

◆ rtxMemBufAppend()

int rtxMemBufAppend ( OSRTMEMBUF pMemBuf,
const OSOCTET *  pdata,
OSSIZE  nbytes 
)

This function appends the data to the end of a memory buffer. If the buffer was dynamic and full then the buffer will be reallocated. If it is static (the static buffer was assigned by a call to rtxMemBufInitBuffer) or it is empty (no memory previously allocated) then a new buffer will be allocated.

Parameters
pMemBufA pointer to a memory buffer structure.
pdataThe pointer to the buffer to be appended. The data will be copied at the end of the memory buffer.
nbytesThe number of bytes to be copied from pData.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.

◆ rtxMemBufCut()

int rtxMemBufCut ( OSRTMEMBUF pMemBuf,
OSSIZE  fromOffset,
OSSIZE  nbytes 
)

This function cuts off the part of memory buffer. The beginning of the cutting area is specified by offset "fromOffset" and the length is specified by "nbytes". All data in this part will be lost. The data from the offset "fromOffset + nbytes" will be moved to "fromOffset" offset.

Parameters
pMemBufA pointer to a memory buffer structure.
fromOffsetThe offset of the beginning part, being cut off.
nbytesThe number of bytes to be cut off from the memory buffer.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.

◆ rtxMemBufFree()

void rtxMemBufFree ( OSRTMEMBUF pMemBuf)

This function frees the memory buffer. If memory was allocated then it will be freed. Do not use the memory buffer structure after this function is called.

Parameters
pMemBufA pointer to a memory buffer structure.

◆ rtxMemBufGetData()

OSOCTET* rtxMemBufGetData ( const OSRTMEMBUF pMemBuf,
int *  length 
)

This function returns the pointer to the used part of a memory buffer.

Parameters
pMemBufA pointer to a memory buffer structure.
lengthThe pointer to the length of the used part of the memory buffer.
Returns
The pointer to the used part of the memory buffer.

◆ rtxMemBufGetDataExt()

OSOCTET* rtxMemBufGetDataExt ( const OSRTMEMBUF pMemBuf,
OSSIZE *  length 
)

This function returns the pointer to the used part of a memory buffer. The extended version returns length in a size-typed argument which is a 64-bit value on many systems.

Parameters
pMemBufA pointer to a memory buffer structure.
lengthThe pointer to the length of the used part of the memory buffer.
Returns
The pointer to the used part of the memory buffer.

◆ rtxMemBufGetDataLen()

OSSIZE rtxMemBufGetDataLen ( const OSRTMEMBUF pMemBuf)

This function returns the length of the used part of a memory buffer.

Parameters
pMemBufA pointer to a memory buffer structure.
Returns
The length of the used part of the buffer.

◆ rtxMemBufInit()

void rtxMemBufInit ( OSCTXT pCtxt,
OSRTMEMBUF pMemBuf,
OSSIZE  segsize 
)

This function initializes a memory buffer structure. It does not allocate memory; it sets the fields of the structure to the proper states. This function must be called before any operations with the memory buffer.

Parameters
pCtxtA provides a storage area for the function to store all working variables that must be maintained between function calls.
pMemBufA pointer to the initialized memory buffer structure.
segsizeThe number of bytes in which the memory buffer will be expanded incase it is full.

◆ rtxMemBufInitBuffer()

void rtxMemBufInitBuffer ( OSCTXT pCtxt,
OSRTMEMBUF pMemBuf,
OSOCTET *  buf,
OSSIZE  bufsize,
OSSIZE  segsize 
)

This function assigns a static buffer to the memory buffer structure. It does not allocate memory; it sets the pointer to the passed buffer. If additional memory is required (for example, additional data is appended to the buffer using rtxMemBufAppend), a dynamic buffer will be allocated and all data copied to the new buffer.

Parameters
pCtxtA pointer to a context structure. This provides a storage area for the function t store all working variables that must be maintained between function calls.
pMemBufA pointer to a memory buffer structure.
bufA pointer to the buffer to be assigned.
bufsizeThe size of the buffer.
segsizeThe number of bytes on which the memory buffer will be expanded in case it is full.

◆ rtxMemBufPreAllocate()

int rtxMemBufPreAllocate ( OSRTMEMBUF pMemBuf,
OSSIZE  nbytes 
)

This function allocates a buffer with a predetermined amount of space.

Parameters
pMemBufA pointer to a memory buffer structure.
nbytesThe number of bytes to be copied from pData.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.

◆ rtxMemBufReset()

void rtxMemBufReset ( OSRTMEMBUF pMemBuf)

This function resets the memory buffer structure. It does not free memory, just sets the pointer to the beginning and the used length to zero.

Parameters
pMemBufA pointer to a memory buffer structure.

◆ rtxMemBufSet()

int rtxMemBufSet ( OSRTMEMBUF pMemBuf,
OSOCTET  value,
OSSIZE  nbytes 
)

This function sets part of a memory buffer to a specified octet value. The filling is started from the end of the memory buffer. If the buffer is dynamic and full, then the buffer will be reallocated. If it is static (a static buffer was assigned by a call to rtxMemBufInitBuffer) or it is empty (no memory previously was allocated) then a new buffer will be allocated.

Parameters
pMemBufA pointer to a memory buffer structure.
valueThe pointer to the buffer to be appended. The data will be copied at the end of the memory buffer.
nbytesThe number of bytes to be copied from pData.
Returns
Completion status of operation:
  • 0 = success,
  • negative return value is error.

◆ rtxMemBufSetExpandable()

OSBOOL rtxMemBufSetExpandable ( OSRTMEMBUF pMemBuf,
OSBOOL  isExpandable 
)

This function sets "isExpandable" flag for the memory buffer object. By default, this flag is set to TRUE, thus, memory buffer could be expanded, even if it was initialized by static buffer (see rtMemBufInitBuffer). If flag is cleared and buffer is full the rtMemBufAppend/rtMemBufPreAllocate functions will return error status.

Parameters
pMemBufA pointer to a memory buffer structure.
isExpandableTRUE, if buffer should be expandable.
Returns
Previous state of "isExpandable" flag.

◆ rtxMemBufSetUseSysMem()

OSBOOL rtxMemBufSetUseSysMem ( OSRTMEMBUF pMemBuf,
OSBOOL  value 
)

This function sets a flag to indicate that system memory management should be used instead of the custom memory manager. This should be used if the allocated buffer must be preserved after calls to rtxMemFree or rtxMemReset.

Parameters
pMemBufA pointer to a memory buffer structure.
valueBoolean indicating system memory management to be used.
Returns
Previous state of "useSysMem" flag.

◆ rtxMemBufTrimW()

OSSIZE rtxMemBufTrimW ( OSRTMEMBUF pMemBuf)

This function trims white space of the memory buffer.

Parameters
pMemBufA pointer to a memory buffer structure.
Returns
Length of trimmed buffer.