固定缓冲区序列化

使用固定缓冲区样式时,请指定一个足以容纳编码 (封送处理) 句柄执行的操作的缓冲区。 取消封送时,提供包含要解码的所有数据的缓冲区。

序列化的固定缓冲区样式使用以下例程:

MesEncodeFixedBufferHandleCreate 函数分配编码句柄所需的内存,然后对其进行初始化。 应用程序可以调用 MesBufferHandleReset 以重新初始化句柄,也可以调用 MesHandleFree 来释放句柄的内存。 若要创建与固定样式编码句柄对应的解码句柄,必须使用 MesDecodeBufferHandleCreate

应用程序调用 MesHandleFree 以释放编码或解码缓冲区句柄。

固定缓冲区编码的示例

以下部分提供了一个示例,说明如何使用固定缓冲区样式序列化句柄进行过程编码。

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

...
void __RPC_USER
MyProc( [in] handle_t Handle, [in,out] MyType * pMyObject,
        [in, out] ThisType * pThisObject);
...

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

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

以下摘录表示应用程序的一部分。

if (MesEncodeFixedBufferHandleCreate (
        Buffer, BufferSize, 
        pEncodedSize, &Handle) == RPC_S_OK)
{
    ...
    /* Manufacture a MyObject and a ThisObject */
    ...
    /* The serialization works from the beginning of the buffer because 
   the handle is in the initial state. The function MyProc 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) 
    */

    MyProc ( Handle, pMyObject, pThisObject );
    ...
    MesHandleFree ();
}
if (MesDecodeBufferHandleCreate (Buffer, BufferSize, &Handle) ==
    RPC_S_OK)
{

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

MyProc ( Handle, pMyObject, pThisObject);
...
MesHandleFree ( Handle );
}

以下部分提供了一个示例,说明如何使用固定缓冲区样式序列化句柄进行类型编码。

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

[    
    explicit_handle
]
interface regress
{
    typedef [ encode,decode ] MyType;
}

以下摘录表示相关的应用程序片段。

if (MesEncodeFixedBufferHandleCreate (Buffer, BufferSize, 
    pEncodedSize, &Handle) == RPC_S_OK)
{
    //...
    /* Manufacture a MyObject and a pMyObject */
    //...
    MyType_Encode ( Handle, pMyObject );
    //...
    MesHandleFree ();
}
if (MesDecodeBufferHandleCreate (Buffer, BufferSize, &Handle) ==
    RPC_S_OK )
{
    MooType_Decode (Handle, pMooObject);
    //...
    MesHandleFree ( Handle );
}