共用方式為


固定緩衝區串行化

使用固定緩衝區樣式時,請指定足以容納使用句柄所執行之編碼(封送處理)作業的緩衝區。 取消分割時,您會提供包含要譯碼之所有數據的緩衝區。

序列化的固定緩衝區樣式會使用下列例程:

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