The following section provides an example of how to use the incremental style serializing handle for type encoding.
/* This is an acf file. FooType is defined in the idl file */
[ explicit_handle
]
interface regress
{
typedef [ encode,decode ] FooType;
}
The following excerpt represents the relevant application fragments.
if (MesEncodeIncrementalHandleCreate (State, AllocFn, WriteFn,
&Handle) == RPC_S_OK)
{
...
/* The serialize works from the beginning of the buffer because
the handle is in the initial state. The Foo_Encode does the
following:
- sizes *pFooObject for marshalling,
- calls AllocFn with the size obtained,
- marshalls into the buffer returned by Alloc, and
- calls WriteFn with the filled buffer
*/
Foo_Encode ( Handle, pFooObject );
...
}
if (MesIncrementalHandleReset (Handle, NULL, NULL, NULL, ReadFn,
MES_DECODE ) == RPC_OK)
{
/*The ReadFn is needed to reset the handle. The arguments
that are NULL do not change. You can also call
MesDecodeIncrementalHandleCreate (State, ReadFn, &Handle);
The Foo_Decode does the following:
- calls Read with the appropriate size of data to read and
receives a buffer with the data
- unmarshalls the object from the buffer into *pFooObject
*/
Foo_Decode ( Handle, pFooObject );
...
MesHandleFree ( Handle );
}