ASN1C C/C++ Common Runtime  ASN1C v7.6.x
rtxBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2022 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  *****************************************************************************/
29 #ifndef _RTXBUFFER_H_
30 #define _RTXBUFFER_H_
31 
32 #include "rtxsrc/rtxContext.h"
33 #include "rtxsrc/rtxSList.h"
34 
35 /* reserve octets to enable short backoffs */
36 #define MIN_STREAM_BACKOFF 0
37 
38 
50 typedef struct _OSRTBufLocDescr {
51  OSSIZE numocts;
52  OSSIZE offset;
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 
60 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
61 
74 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
75 
76 
86 EXTERNRT OSBOOL rtxIsOutputBufferFlushable(OSCTXT* pctxt);
87 
88 
101 EXTERNRT int rtxFlushOutputBuffer(OSCTXT* pctxt);
102 
103 
116 EXTERNRT int rtxExpandOutputBuffer (OSCTXT* pctxt, size_t nbytes);
117 
131 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
132 
133 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
134 
135 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
136 
137 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
138 
157 EXTERNRT int rtxLoadInputBuffer(OSCTXT* pctxt, OSSIZE nbytes);
158 
168 EXTERNRT int rtxPeekByte(OSCTXT* pctxt, OSOCTET* pbyte);
169 
184 EXTERNRT int rtxPeekBytes(OSCTXT* pctxt, OSOCTET* pdata, OSSIZE bufsize,
185  OSSIZE nocts, OSSIZE* pactual);
186 
199 EXTERNRT int rtxReadBytesSafe
200 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
201 
211 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
212 
229 EXTERNRT int rtxReadBytesDynamic
230 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
231 
240 EXTERNRT int rtxWriteBytes
241 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
242 
243 
256 EXTERNRT int rtxWriteIndent(OSCTXT* pctxt);
257 
266 EXTERNRT void rtxIndentDecr(OSCTXT* pctxt);
267 
276 EXTERNRT void rtxIndentIncr(OSCTXT* pctxt);
277 
285 EXTERNRT void rtxIndentReset(OSCTXT* pctxt);
286 
287 
297 EXTERNRT size_t rtxGetIndentLevels(OSCTXT* pctxt);
298 
299 
328 EXTERNRT OSBOOL rtxCanonicalSort (OSOCTET* refPoint, OSRTSList* pList,
329  OSBOOL normal);
330 
331 
332 #ifndef _NO_STREAM
333 
345 EXTERNRT int rtxEncCanonicalSort (OSCTXT* pctxt,
346  OSCTXT* pMemCtxt,
347  OSRTSList* pList);
348 
353 EXTERNRT void rtxGetBufLocDescr (OSCTXT *pctxt, OSRTBufLocDescr* pDescr);
354 
367 EXTERNRT void rtxAddBufLocDescr (OSCTXT *pctxt, OSRTSList* pElemList,
368  OSRTBufLocDescr* pDescr);
369 #endif /* _NO_STREAM */
370 
371 /* Macros */
372 
373 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
374 
375 #define OSRTPUTCHARREV(pctxt,ch) \
376 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
377 
378 #define OSRTZTERM(pctxt) \
379 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
380 
381 #define OSRTSAFEZTERM(pctxt) \
382 do { \
383 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
384 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
385 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
386 } while (0)
387 
388 #define OSRTSAFEPUTCHAR(pctxt,ch) \
389 do { \
390 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
391 (pctxt)->lastChar= \
392 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
393 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
394 } while (0)
395 
396 /* Put character into buffer and terminate buffer with null character.
397  Execute return LOG_RTERRNEW if there is not room in the buffer and
398  the buffer cannot be expanded to make room.
399 */
400 #define OSRTSAFEPUTCHAR_ZTERM(pctxt,ch) \
401 do { \
402 if (rtxCheckOutputBuffer (pctxt, 2) == 0) { \
403 (pctxt)->lastChar= \
404 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
405 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; } \
406 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
407 } while (0)
408 
409 
410 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
411 do { \
412 OSOCTET b = (OSOCTET)ch; \
413 rtxWriteBytes (pctxt, &b, 1); \
414 } while (0)
415 
416 #if 0
417 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
418 do { \
419 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
420 (pctxt)->lastChar= \
421 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
422 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
423 } while (0)
424 #endif
425 
426 #define OSRTMEMCPY(pctxt,bdata,len) \
427 do { \
428 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
429  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
430 (pctxt)->buffer.byteIndex += len; \
431 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
432 } while (0)
433 
434 #define OSRTMEMCPYREV(pctxt,bdata,len) \
435 do { \
436 (pctxt)->buffer.byteIndex -= len; \
437 OSCRTLSAFEMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], \
438  (pctxt)->buffer.size-(pctxt)->buffer.byteIndex, bdata, len); \
439 } while (0)
440 
441 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
442 do { \
443 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
444 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
445 (pctxt)->buffer.byteIndex += len; \
446 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
447 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
448 } while (0)
449 
450 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
451 do { \
452 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
453 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
454 (pctxt)->buffer.byteIndex += len; \
455 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
456 stat = 0; } \
457 else stat = RTERR_BUFOVFLW; \
458 } while (0)
459 
460 #define OSRTGETBUFUTF8LEN(pctxt) \
461 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
462 
463 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
464 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
465 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
466 
467 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
468 
469 #define OSRTByteAlign(pctxt) \
470 if ((pctxt)->buffer.bitOffset != 8) { \
471  (pctxt)->buffer.byteIndex++; \
472  (pctxt)->buffer.bitOffset = 8; } \
473 
474 
479 #ifdef __cplusplus
480 }
481 #endif
482 
483 #endif
int rtxWriteBytes(OSCTXT *pctxt, const OSOCTET *pdata, size_t nocts)
int rtxReadBytes(OSCTXT *pctxt, OSOCTET *pdata, size_t nocts)
void rtxGetBufLocDescr(OSCTXT *pctxt, OSRTBufLocDescr *pDescr)
void rtxIndentIncr(OSCTXT *pctxt)
int rtxCheckOutputBuffer(OSCTXT *pctxt, size_t nbytes)
struct _OSRTBufLocDescr OSRTBufLocDescr
Definition: rtxSList.h:68
Definition: rtxBuffer.h:50
int rtxCheckInputBuffer(OSCTXT *pctxt, size_t nbytes)
int rtxWriteIndent(OSCTXT *pctxt)
int rtxFlushOutputBuffer(OSCTXT *pctxt)
int rtxLoadInputBuffer(OSCTXT *pctxt, OSSIZE nbytes)
void rtxIndentReset(OSCTXT *pctxt)
void rtxAddBufLocDescr(OSCTXT *pctxt, OSRTSList *pElemList, OSRTBufLocDescr *pDescr)
int rtxReadBytesDynamic(OSCTXT *pctxt, OSOCTET **ppdata, size_t nocts, OSBOOL *pMemAlloc)
OSBOOL rtxCanonicalSort(OSOCTET *refPoint, OSRTSList *pList, OSBOOL normal)
int rtxEncCanonicalSort(OSCTXT *pctxt, OSCTXT *pMemCtxt, OSRTSList *pList)
void rtxIndentDecr(OSCTXT *pctxt)
OSBOOL rtxIsOutputBufferFlushable(OSCTXT *pctxt)
int rtxExpandOutputBuffer(OSCTXT *pctxt, size_t nbytes)
int rtxReadBytesSafe(OSCTXT *pctxt, OSOCTET *buffer, size_t bufsize, size_t nocts)
size_t rtxGetIndentLevels(OSCTXT *pctxt)
Definition: rtxContext.h:198
int rtxPeekBytes(OSCTXT *pctxt, OSOCTET *pdata, OSSIZE bufsize, OSSIZE nocts, OSSIZE *pactual)
int rtxPeekByte(OSCTXT *pctxt, OSOCTET *pbyte)