00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #ifndef _RTXBUFFER_H_
00030 #define _RTXBUFFER_H_
00031
00032 #include "rtxsrc/rtxContext.h"
00033
00034
00035 #define MIN_STREAM_BACKOFF 1
00036
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040
00041 EXTERNRT int rtxCheckBuffer (OSCTXT* pctxt, size_t nbytes);
00042
00043 EXTERNRT int rtxCheckOutputBuffer (OSCTXT* pctxt, size_t nbytes);
00044
00045 EXTERNRT int rtxCheckInputBuffer (OSCTXT* pctxt, size_t nbytes);
00046
00047 EXTERNRT int rtxCopyAsciiText (OSCTXT* pctxt, const char* text);
00048
00049 EXTERNRT int rtxCopyUTF8Text (OSCTXT* pctxt, const OSUTF8CHAR* text);
00050
00051 EXTERNRT int rtxCopyUnicodeText (OSCTXT* pctxt, const OSUNICHAR* text);
00052
00065 EXTERNRT int rtxReadBytesSafe
00066 (OSCTXT* pctxt, OSOCTET* buffer, size_t bufsize, size_t nocts);
00067
00077 EXTERNRT int rtxReadBytes (OSCTXT* pctxt, OSOCTET* pdata, size_t nocts);
00078
00095 EXTERNRT int rtxReadBytesDynamic
00096 (OSCTXT* pctxt, OSOCTET** ppdata, size_t nocts, OSBOOL* pMemAlloc);
00097
00106 EXTERNRT int rtxWriteBytes
00107 (OSCTXT* pctxt, const OSOCTET* pdata, size_t nocts);
00108
00109
00110
00111 #define OSRTPUTCHAR(pctxt,ch) rtxWriteBytes (pctxt, (OSOCTET*)&ch, 1)
00112
00113 #define OSRTPUTCHARREV(pctxt,ch) \
00114 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex]=(OSOCTET)ch;
00115
00116 #define OSRTZTERM(pctxt) \
00117 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0;
00118
00119 #define OSRTSAFEZTERM(pctxt) \
00120 do { \
00121 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00122 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex]=(OSOCTET)0; \
00123 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00124 } while (0)
00125
00126 #define OSRTSAFEPUTCHAR(pctxt,ch) \
00127 do { \
00128 if (rtxCheckOutputBuffer (pctxt, 1) == 0) \
00129 (pctxt)->lastChar= \
00130 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00131 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00132 } while (0)
00133
00134 #define OSRTSAFEPUTCHAR1(pctxt,ch,stat) \
00135 do { \
00136 OSOCTET b = (OSOCTET)ch; \
00137 rtxWriteBytes (pctxt, &b, 1); \
00138 } while (0)
00139
00140 #if 0
00141 #define OSRTSAFEPUTCHAR2(pctxt,ch,prealloc) \
00142 do { \
00143 if (rtxCheckOutputBuffer (pctxt, ((prealloc > 1)?prealloc:1)) == 0) \
00144 (pctxt)->lastChar= \
00145 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex++]=(OSOCTET)ch; \
00146 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00147 } while (0)
00148 #endif
00149
00150 #define OSRTMEMCPY(pctxt,bdata,len) \
00151 do { \
00152 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00153 (pctxt)->buffer.byteIndex += len; \
00154 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00155 } while (0)
00156
00157 #define OSRTMEMCPYREV(pctxt,bdata,len) \
00158 do { \
00159 (pctxt)->buffer.byteIndex -= len; \
00160 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00161 } while (0)
00162
00163 #define OSRTSAFEMEMCPY(pctxt,bdata,len) \
00164 do { \
00165 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00166 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00167 (pctxt)->buffer.byteIndex += len; \
00168 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; } \
00169 else return LOG_RTERRNEW (pctxt, RTERR_BUFOVFLW); \
00170 } while (0)
00171
00172 #define OSRTSAFEMEMCPY1(pctxt,bdata,len,stat) \
00173 do { \
00174 if (rtxCheckOutputBuffer (pctxt, len) == 0) { \
00175 OSCRTLMEMCPY (&(pctxt)->buffer.data[(pctxt)->buffer.byteIndex], bdata, len); \
00176 (pctxt)->buffer.byteIndex += len; \
00177 (pctxt)->lastChar = (pctxt)->buffer.data[(pctxt)->buffer.byteIndex-1]; \
00178 stat = 0; } \
00179 else stat = RTERR_BUFOVFLW; \
00180 } while (0)
00181
00182 #define OSRTGETBUFUTF8LEN(pctxt) \
00183 rtxCalcUTF8Len (OSRTBUFPTR (pctxt), OSRTBUFSIZE (pctxt))
00184
00185 #define OSRTCHKBUFUTF8LEN(pctxt,lower,upper,stat) \
00186 do { size_t nchars = OSRTGETBUFUTF8LEN (pctxt); \
00187 stat = (nchars >= lower && nchars <= upper) ? 0 : RTERR_CONSVIO; } while(0)
00188
00189 #define OSRTENDOFBUF(pctxt) ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)
00190
00191 #ifdef __cplusplus
00192 }
00193 #endif
00194
00195 #endif