Examples of Fixed Buffer Encoding

The following section provides an example of how to use a fixed-buffer style, serializing handle for procedure encoding.

/*This is a fragment of the IDL file defining FooProc */

...
void __RPC_USER
FooProc( [in] handle_t Handle,     [in,out] FooType * pFooObject,
               [in, out] BarType * pBarObject);
...

/*This is an ACF file. FooProc is defined in the IDL file */

[    explicit_handle
]
interface regress
{
[ encode,decode ]    FooProc();
}
 

The following excerpt represents a part of an application.

if (MesEncodeFixedBufferHandleCreate (Buffer, BufferSize, 
        pEncodedSize, &Handle) == RPC_S_OK)
{
...
/* Manufacture a FooObject and a BarObject */
...
/* The serialize works from the beginning of the buffer because the 
    handle is in the initial state. The FooProc does the following 
    when called with an encoding handle:
     - sizes all the parameters for marshalling,
     - marshalls into the buffer (and sets the internal state 
    appropriately) 
*/

FooProc ( Handle, pFooObject, pBarObject );
...
MesHandleFree ();
}
if (MesDecodeBufferHandleCreate (Buffer, BufferSize, &Handle) ==
    RPC_S_OK)
{

/* The FooProc does the following for you when called with a decoding 
    handle:
     - unmarshalls the objects from the buffer into *pFooObject and 
        *pBarObject
*/

FooProc ( Handle, pFooObject, pBarObject);
...
MesHandleFree ( Handle );
}
 

The following section provides an example of how to use a fixed-buffer 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 (MesEncodeFixedBufferHandleCreate (Buffer, BufferSize, 
    pEncodedSize, &Handle) == RPC_S_OK)
{
...
/* Manufacture a FooObject and a pFooObject */
...
FooType_Encode ( Handle, pFooObject );
...
MesHandleFree ();
}
if (MesDecodeBufferHandleCreate (Buffer, BufferSize, &Handle) ==
    RPC_S_OK )
{
FooType_Decode (Handle, pFooObject);
...
MesHandleFree ( Handle );
}