ASN1C C/C++ Common Runtime  ASN1C v7.7.x
rtxMemBuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2023 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
24 
41 /* memory buffer */
42 
43 #ifndef _RTXMEMBUF_H_
44 #define _RTXMEMBUF_H_
45 
46 #include "rtxsrc/rtxContext.h"
47 
48 typedef struct OSRTMEMBUF {
49  OSCTXT* pctxt;
50  OSSIZE segsize; /* segment size */
51  OSSIZE startidx; /* start index of useful info */
52  OSSIZE usedcnt; /* used byte count */
53  OSSIZE bufsize; /* buffer size */
54  OSSIZE bitOffset; /* bit offset */
55  OSUINT32 userState; /* user state - any value, 0 is initial */
56  OSOCTET* buffer; /* memory buffer */
57  OSBOOL isDynamic; /* is buffer allocated dynamically? */
58  OSBOOL isExpandable; /* is buffer expandable? */
59  OSBOOL useSysMem; /* use system memory management */
60 } OSRTMEMBUF;
61 
62 #define OSMBDFLTSEGSIZE 1024
63 
64 #define OSMEMBUFPTR(pmb) ((pmb)->buffer + (pmb)->startidx)
65 #define OSMEMBUFENDPTR(pmb) ((pmb)->buffer + (pmb)->startidx + (pmb)->usedcnt)
66 #define OSMEMBUFUSEDSIZE(pmb) ((OSSIZE)(pmb)->usedcnt)
67 
68 /* These macros do not null-terminate the appended string */
69 #define OSMBAPPENDSTR(pmb,str) if (0 != str) \
70 rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str))
71 
72 #define OSMBAPPENDSTRL(pmb,str) \
73 rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str))
74 
75 #define OSMBAPPENDUTF8(pmb,str) if (0 != str) \
76 rtxMemBufAppend(pmb,(OSOCTET*)str,rtxUTF8LenBytes(str))
77 
78 /* This macro will null-terminate the appended string */
79 #define OSMBAPPENDSTRZ(pmb,str) \
80 rtxMemBufAppend(pmb,(OSOCTET*)str,OSCRTLSTRLEN(str)+1)
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
86 /* Memory buffer functions */
87 
102 EXTERNRT int rtxMemBufAppend
103 (OSRTMEMBUF* pMemBuf, const OSOCTET* pdata, OSSIZE nbytes);
104 
119 EXTERNRT int rtxMemBufCut
120 (OSRTMEMBUF* pMemBuf, OSSIZE fromOffset, OSSIZE nbytes);
121 
129 EXTERNRT void rtxMemBufFree (OSRTMEMBUF* pMemBuf);
130 
139 EXTERNRT OSOCTET* rtxMemBufGetData (const OSRTMEMBUF* pMemBuf, int* length);
140 
151 EXTERNRT OSOCTET* rtxMemBufGetDataExt
152 (const OSRTMEMBUF* pMemBuf, OSSIZE* length);
153 
160 EXTERNRT OSSIZE rtxMemBufGetDataLen (const OSRTMEMBUF* pMemBuf);
161 
174 EXTERNRT void rtxMemBufInit
175 (OSCTXT* pCtxt, OSRTMEMBUF* pMemBuf, OSSIZE segsize);
176 
196 EXTERNRT void rtxMemBufInitBuffer (OSCTXT* pCtxt, OSRTMEMBUF* pMemBuf,
197  OSOCTET* buf, OSSIZE bufsize,
198  OSSIZE segsize);
199 
209 EXTERNRT int rtxMemBufPreAllocate (OSRTMEMBUF* pMemBuf, OSSIZE nbytes);
210 
217 EXTERNRT void rtxMemBufReset (OSRTMEMBUF* pMemBuf);
218 
234 EXTERNRT int rtxMemBufSet (OSRTMEMBUF* pMemBuf, OSOCTET value, OSSIZE nbytes);
235 
247 EXTERNRT OSBOOL rtxMemBufSetExpandable
248 (OSRTMEMBUF* pMemBuf, OSBOOL isExpandable);
249 
260 EXTERNRT OSBOOL rtxMemBufSetUseSysMem (OSRTMEMBUF* pMemBuf, OSBOOL value);
261 
268 EXTERNRT OSSIZE rtxMemBufTrimW (OSRTMEMBUF* pMemBuf);
269 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif
OSSIZE rtxMemBufTrimW(OSRTMEMBUF *pMemBuf)
int rtxMemBufSet(OSRTMEMBUF *pMemBuf, OSOCTET value, OSSIZE nbytes)
void rtxMemBufInit(OSCTXT *pCtxt, OSRTMEMBUF *pMemBuf, OSSIZE segsize)
OSOCTET * rtxMemBufGetData(const OSRTMEMBUF *pMemBuf, int *length)
void rtxMemBufReset(OSRTMEMBUF *pMemBuf)
int rtxMemBufPreAllocate(OSRTMEMBUF *pMemBuf, OSSIZE nbytes)
Definition: rtxMemBuf.h:48
OSSIZE rtxMemBufGetDataLen(const OSRTMEMBUF *pMemBuf)
OSBOOL rtxMemBufSetUseSysMem(OSRTMEMBUF *pMemBuf, OSBOOL value)
OSOCTET * rtxMemBufGetDataExt(const OSRTMEMBUF *pMemBuf, OSSIZE *length)
Definition: rtxContext.h:198
void rtxMemBufFree(OSRTMEMBUF *pMemBuf)
void rtxMemBufInitBuffer(OSCTXT *pCtxt, OSRTMEMBUF *pMemBuf, OSOCTET *buf, OSSIZE bufsize, OSSIZE segsize)
int rtxMemBufCut(OSRTMEMBUF *pMemBuf, OSSIZE fromOffset, OSSIZE nbytes)
int rtxMemBufAppend(OSRTMEMBUF *pMemBuf, const OSOCTET *pdata, OSSIZE nbytes)
OSBOOL rtxMemBufSetExpandable(OSRTMEMBUF *pMemBuf, OSBOOL isExpandable)