Create a user-defined stream class

You can provide a stream I/O interface to create your own protocol for reciprocal reading and writing of SQL data and other data streams.

The DataBlade® API stream I/O interface provides a consistent interface for accessing data; that is, each stream I/O function has a fixed function name and argument list, regardless of the actual stream that it accesses. This fixed syntax provides the main benefits of stream access:
  • The calling code can use the exact same syntax to access different kinds of data.
  • The underlying data can be transparent to the calling code.
Important: Enterprise Replication does not support user-defined stream classes.
To create a user-defined stream class, you need to write the following stream I/O functions:
  • A type-specific stream-open function

    Each type of data to which a stream provides access usually has a unique way of being opened. Its stream-open function must accept as arguments the information required to open the data so that the mi_stream_init() function can initialize the stream.

  • Type-specific implementations for the generic stream I/O functions

    You must implement the generic stream I/O functions that your stream supports so that they correctly handle the format of your stream data.

The mi_stream_init() function initializes the stream descriptor with the arguments it receives. The following code fragment of a stream-open function calls mi_stream_init() with the stream-operations structure in A sample stream-operations structure, the internal structure for the mytype opaque type, and a NULL-valued pointer:
MI_STREAM *mi_stream_open_mytype(void *mydata)
{
   MI_STREAM *strm_desc; /* can be passed in as input to open()
                        * also.
                        */
/* Code to process any stream-open arguments */
...
/* Call to mi_stream_init() to allocate and initialize
 * the stream descriptor 
 */
   strm_desc = mi_stream_init(stream_ops_mytype, mydata, NULL);

/* Return pointer to newly allocated stream descriptor */
   return strm_desc;
}

Because mi_stream_init() receives a NULL-valued pointer as its stream descriptor, it allocates the stream descriptor in the current memory duration. The mi_stream_init() function then returns a pointer to this newly allocated structure, which the mi_stream_open_mytype() function also returns.