固定缓冲区序列化

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

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

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 );
}