ASN1C C/C++ Common Runtime  ASN1C v7.8.x
Classes | Macros | Typedefs | Functions
Input/Output Data Stream Utility Functions

Classes

struct  OSRTSTREAM
 

Macros

#define OSRTSTRMF_INPUT   0x0001
 
#define OSRTSTRMF_OUTPUT   0x0002
 
#define OSRTSTRMF_BUFFERED   0x8000 /* direct-buffer stream */
 
#define OSRTSTRMF_UNBUFFERED   0x4000 /* force unbuffered stream */
 
#define OSRTSTRMF_POSMARKED   0x2000 /* stream has marked position */
 
#define OSRTSTRMF_FIXINMEM   0x1000 /* disable flushing */
 
#define OSRTSTRMF_HEXTEXT   0x0800 /* do hex text / binary conversion */
 
#define OSRTSTRMF_BUF_INPUT   (OSRTSTRMF_INPUT|OSRTSTRMF_BUFFERED)
 
#define OSRTSTRMF_BUF_OUTPUT   (OSRTSTRMF_OUTPUT|OSRTSTRMF_BUFFERED)
 
#define OSRTSTRMID_FILE   1
 
#define OSRTSTRMID_SOCKET   2
 
#define OSRTSTRMID_MEMORY   3
 
#define OSRTSTRMID_BUFFERED   4
 
#define OSRTSTRMID_DIRECTBUF   5
 
#define OSRTSTRMID_CTXTBUF   6
 
#define OSRTSTRMID_ZLIB   7
 
#define OSRTSTRMID_USER   1000
 
#define OSRTSTRM_K_BUFSIZE   1024
 
#define OSRTSTRM_K_INVALIDMARK   ((size_t)-1)
 
#define OSRTSTREAM_BYTEINDEX(pctxt)
 
#define OSRTSTREAM_ID(pctxt)   ((pctxt)->pStream->id)
 
#define OSRTSTREAM_FLAGS(pctxt)   ((pctxt)->pStream->flags)
 
#define rtxStreamBlockingRead   rtxStreamRead
 

Typedefs

typedef long(* OSRTStreamReadProc) (struct OSRTSTREAM *pStream, OSOCTET *pbuffer, size_t nocts)
 
typedef OSRTStreamReadProc OSRTStreamBlockingReadProc
 
typedef long(* OSRTStreamWriteProc) (struct OSRTSTREAM *pStream, const OSOCTET *data, size_t numocts)
 
typedef int(* OSRTStreamFlushProc) (struct OSRTSTREAM *pStream)
 
typedef int(* OSRTStreamCloseProc) (struct OSRTSTREAM *pStream)
 
typedef int(* OSRTStreamSkipProc) (struct OSRTSTREAM *pStream, size_t skipBytes)
 
typedef int(* OSRTStreamMarkProc) (struct OSRTSTREAM *pStream, size_t readAheadLimit)
 
typedef int(* OSRTStreamResetProc) (struct OSRTSTREAM *pStream)
 
typedef int(* OSRTStreamGetPosProc) (struct OSRTSTREAM *pStream, size_t *ppos)
 
typedef int(* OSRTStreamSetPosProc) (struct OSRTSTREAM *pStream, size_t pos)
 
typedef struct OSRTSTREAM OSRTSTREAM
 

Functions

int rtxStreamClose (OSCTXT *pctxt)
 
int rtxStreamFlush (OSCTXT *pctxt)
 
int rtxStreamLoadInputBuffer (OSCTXT *pctxt, OSSIZE nbytes)
 
int rtxStreamInit (OSCTXT *pctxt)
 
int rtxStreamInitCtxtBuf (OSCTXT *pctxt)
 
int rtxStreamRemoveCtxtBuf (OSCTXT *pctxt)
 
long rtxStreamRead (OSCTXT *pctxt, OSOCTET *pbuffer, size_t nocts)
 
long rtxStreamRead2 (OSCTXT *pctxt, OSOCTET *pbuffer, size_t nocts, size_t bufSize)
 
long rtxStreamReadDirect (OSCTXT *pctxt, OSOCTET *pbuffer, OSSIZE bufSize)
 
int rtxStreamSkip (OSCTXT *pctxt, size_t skipBytes)
 
long rtxStreamWrite (OSCTXT *pctxt, const OSOCTET *data, size_t numocts)
 
int rtxStreamGetIOBytes (OSCTXT *pctxt, size_t *pPos)
 
int rtxStreamMark (OSCTXT *pctxt, size_t readAheadLimit)
 
int rtxStreamReset (OSCTXT *pctxt)
 
OSBOOL rtxStreamMarkSupported (OSCTXT *pctxt)
 
OSBOOL rtxStreamIsOpened (OSCTXT *pctxt)
 
OSBOOL rtxStreamIsReadable (OSCTXT *pctxt)
 
OSBOOL rtxStreamIsWritable (OSCTXT *pctxt)
 
int rtxStreamRelease (OSCTXT *pctxt)
 
void rtxStreamSetCapture (OSCTXT *pctxt, OSRTMEMBUF *pmembuf)
 
OSRTMEMBUFrtxStreamGetCapture (OSCTXT *pctxt)
 
int rtxStreamGetPos (OSCTXT *pctxt, size_t *ppos)
 
int rtxStreamSetPos (OSCTXT *pctxt, size_t pos)
 

Detailed Description

Stream functions are used for unbuffered stream operations. All of the operations with streams are performed using a context block to maintain state information.

These functions may be used for any input/output operations with streams. Each stream should be initialized first by call to the rtxStreamInit function. After initialization, the stream may be opened for reading or writing by calling one of the following functions:

Macro Definition Documentation

◆ OSRTSTREAM_BYTEINDEX

#define OSRTSTREAM_BYTEINDEX (   pctxt)
Value:
(((pctxt)->pStream->flags & OSRTSTRMF_BUFFERED) ? \
((pctxt)->pStream->bytesProcessed + (pctxt)->buffer.byteIndex) : \
((pctxt)->pStream->bytesProcessed /* was ioBytes */ ))

◆ rtxStreamBlockingRead

#define rtxStreamBlockingRead   rtxStreamRead

rtxStreamBlockingRead is deprecated. Use rtxStreamRead.

Typedef Documentation

◆ OSRTSTREAM

typedef struct OSRTSTREAM OSRTSTREAM

The stream control block. A user may implement a customized stream by defining read, skip, close functions for input streams and write, flush, close for output streams.

◆ OSRTStreamBlockingReadProc

OSRTStreamBlockingReadProc is deprecated. Use OSRTStreamReadProc.

◆ OSRTStreamCloseProc

typedef int(* OSRTStreamCloseProc) (struct OSRTSTREAM *pStream)

Stream close function pointer type. A user may implement a customized close function for any specific input or output streams. The close function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamFlushProc

typedef int(* OSRTStreamFlushProc) (struct OSRTSTREAM *pStream)

Stream flush function pointer type. A user may implement a customized flush function for any specific output streams. The flush function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamGetPosProc

typedef int(* OSRTStreamGetPosProc) (struct OSRTSTREAM *pStream, size_t *ppos)

Stream get position function pointer type. A user may implement a customized function for a specific input stream type. The mark function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamMarkProc

typedef int(* OSRTStreamMarkProc) (struct OSRTSTREAM *pStream, size_t readAheadLimit)

Stream mark function pointer type. A user may implement a customized function for a specific input stream type. The mark function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamReadProc

typedef long(* OSRTStreamReadProc) (struct OSRTSTREAM *pStream, OSOCTET *pbuffer, size_t nocts)

Stream read function pointer type. A user may implement a customized read function for specific input streams. The read function is defined in the OSRTSTREAM control structure.

The read function may read fewer bytes than requested, but it will read at least one byte (assuming nocts > 0) unless EOF is reached or there is an error. Thus, if nocts > 0, this will return 0 only if EOF is reached. Reaching EOF shall not be considered an error.

Parameters
pStreamIdentifies the stream control structure.
pbufferis the buffer into which bytes shall be read.
noctsis the number of bytes to be read; the buffer must be at least this large.
Returns
The number of bytes read (possibly 0), or a negative error code.

◆ OSRTStreamResetProc

typedef int(* OSRTStreamResetProc) (struct OSRTSTREAM *pStream)

Stream reset function pointer type. A user may implement a customized function for a specific input stream type. The reset function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamSetPosProc

typedef int(* OSRTStreamSetPosProc) (struct OSRTSTREAM *pStream, size_t pos)

Stream set position function pointer type. A user may implement a customized function for a specific input stream type. The mark function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamSkipProc

typedef int(* OSRTStreamSkipProc) (struct OSRTSTREAM *pStream, size_t skipBytes)

Stream skip function pointer type. A user may implement a customized function for a specific input stream type. The skip function is defined in the OSRTSTREAM control structure.

◆ OSRTStreamWriteProc

typedef long(* OSRTStreamWriteProc) (struct OSRTSTREAM *pStream, const OSOCTET *data, size_t numocts)

Stream write function pointer type. A user may implement a customized write function for any specific output streams. The write function is defined in the OSRTSTREAM control structure.

Function Documentation

◆ rtxStreamClose()

int rtxStreamClose ( OSCTXT pctxt)

This function closes the input or output stream and releases any system resources associated with the stream. For output streams this function also flushes all internal buffers to the stream.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.

◆ rtxStreamFlush()

int rtxStreamFlush ( OSCTXT pctxt)

This function flushes the output stream and forces any buffered output octets to be written out.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamGetCapture()

OSRTMEMBUF* rtxStreamGetCapture ( OSCTXT pctxt)

This function returns the capture buffer currently assigned to the stream.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
Pointer to memory buffer that was previously assigned as a capture buffer to the stream.

◆ rtxStreamGetIOBytes()

int rtxStreamGetIOBytes ( OSCTXT pctxt,
size_t *  pPos 
)

This function returns the number of processed octets. If the stream was opened as an input stream, then it returns the total number of read octets. If the stream was opened as an output stream, then it returns the total number of written octets. Otherwise, this function returns an error code.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
pPosPointer to argument to receive total number of processed octets.
Returns
The total number of processed octets or error code (negative value).

◆ rtxStreamGetPos()

int rtxStreamGetPos ( OSCTXT pctxt,
size_t *  ppos 
)

Get the current position in input stream.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
pposPointer to a variable to receive position.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamInit()

int rtxStreamInit ( OSCTXT pctxt)

This function initializes a stream part of the context block. This function should be called first before any operation with a stream.

Parameters
pctxtPointer to context structure variable, for which stream to be initialized.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamInitCtxtBuf()

int rtxStreamInitCtxtBuf ( OSCTXT pctxt)

This function initializes a stream to use the context memory buffer for stream buffering.

Parameters
pctxtPointer to context structure variable, for which stream to be initialized.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamIsOpened()

OSBOOL rtxStreamIsOpened ( OSCTXT pctxt)

Tests if this stream opened (for reading or writing).

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
TRUE if this stream is opened for reading or writing; FALSE otherwise.

◆ rtxStreamIsReadable()

OSBOOL rtxStreamIsReadable ( OSCTXT pctxt)

Tests if this stream opened for reading.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
TRUE if this stream is opened for reading; FALSE otherwise.

◆ rtxStreamIsWritable()

OSBOOL rtxStreamIsWritable ( OSCTXT pctxt)

Tests if this stream opened for writing.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
TRUE if this stream is opened for writing; FALSE otherwise.

◆ rtxStreamLoadInputBuffer()

int rtxStreamLoadInputBuffer ( OSCTXT pctxt,
OSSIZE  nbytes 
)

This is for meant for internal use by the runtime.

Read at least as many bytes, from the context's input stream into the context buffer, as necessary to make nbytes of data available in the context buffer.

Upon return, pctxt.buffer.byteIndex + nbytes <= pctxt.buffer.size OR EOF has been reached OR an error has been logged and is being returned.

If the context buffer has not been created, this will create it. If the context buffer needs to be made larger, this will enlarge it or else log, and return, an error.

Any bytes read from the stream will be sent to the capture buffer, if there is one.

Parameters
pctxtA context with an attached stream using the context's buffer as a buffer for the stream.
Returns
0 or or negative error. EOF is not considered an error.

◆ rtxStreamMark()

int rtxStreamMark ( OSCTXT pctxt,
size_t  readAheadLimit 
)

Marks the current position in this input stream. A subsequent call to the rtxStreamReset function repositions this stream at the last marked position so that subsequent reads re-read the same bytes. The readAheadLimit argument tells this input stream to allow many bytes to be read before the mark position gets invalidated.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
readAheadLimitThe maximum limit of bytes that can be read before the mark position becomes invalid.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamMarkSupported()

OSBOOL rtxStreamMarkSupported ( OSCTXT pctxt)

Tests if this input stream supports the mark and reset methods. Whether or not mark and reset are supported is an invariant property of a particular input stream instance. By default, it returns FALSE.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
TRUE if this stream instance supports the mark and reset methods; FALSE otherwise.

◆ rtxStreamRead()

long rtxStreamRead ( OSCTXT pctxt,
OSOCTET *  pbuffer,
size_t  nocts 
)

Read up to nocts bytes of data from the input stream into an array of octets.

This function blocks until nocts of data are read, end of file is detected, or an error occurs. EOF is not treated as an error.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
pbufferPointer to a buffer to receive data.
noctsNumber of bytes to read.
Returns
The total number of octets read into pbuffer, or negative value with error code if an error occurs.

◆ rtxStreamRead2()

long rtxStreamRead2 ( OSCTXT pctxt,
OSOCTET *  pbuffer,
size_t  nocts,
size_t  bufSize 
)

Attempt to read nocts bytes from the input stream into an array of octets. It may read more bytes (as many as bufSize). It may read fewer bytes if end of file is detected or an error occurs. EOF is not treated as an error.

This function blocks until nocts of data are read, end of file is detected, or an error occurs. EOF is not treated as an error.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
pbufferPointer to a buffer to receive data.
noctsNumber of octets to read; nocts >= 1
bufSizeSize of the buffer.
Returns
The total number of octets read into pbuffer, or negative value with error code if an error occurs.

◆ rtxStreamRelease()

int rtxStreamRelease ( OSCTXT pctxt)

This function releases the stream's resources. If it is opened for reading or writing it will be closed.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamRemoveCtxtBuf()

int rtxStreamRemoveCtxtBuf ( OSCTXT pctxt)

This function removes the use of a context memory buffer from a stream.

Parameters
pctxtPointer to context structure variable which is assumed to contain an initialized stream with context buffering enabled.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamReset()

int rtxStreamReset ( OSCTXT pctxt)

Repositions this stream to the position recorded by the last call to the rtxStreamMark function.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamSetCapture()

void rtxStreamSetCapture ( OSCTXT pctxt,
OSRTMEMBUF pmembuf 
)

This function sets a capture buffer for the stream. This is used to record all data read from the stream.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
pmembufPointer to an initialized memory buffer structure. This argument may be set to NULL to disable capture if previously set.

◆ rtxStreamSetPos()

int rtxStreamSetPos ( OSCTXT pctxt,
size_t  pos 
)

Set the current position in input stream.

Parameters
pctxtPointer to a context structure variable that has been initialized for stream operations.
posStream position.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamSkip()

int rtxStreamSkip ( OSCTXT pctxt,
size_t  skipBytes 
)

This function skips over and discards the specified amount of data octets from this input stream. An attempt to skip past the end of the input is an error. (This skips bytes of input, which may be held in a buffer, so it does not necessarily skip bytes in the underlying stream. Also, pctxt->buffer.bitOffset is irrelevant to this function.)

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
skipBytesThe number of octets to be skipped.
Returns
Completion status of operation: 0 = success, negative return value is error.

◆ rtxStreamWrite()

long rtxStreamWrite ( OSCTXT pctxt,
const OSOCTET *  data,
size_t  numocts 
)

This function writes the specified amount of octets from the specified array to the output stream.

Parameters
pctxtPointer to a context structure variable which has been initialized for stream operations via a call to rtxStreamInit.
dataThe pointer to data to be written.
numoctsThe number of octets to write.
Returns
Completion status of operation: 0 = success, negative return value is error.