共用方式為


固定緩衝區序列化

使用固定緩衝區樣式時,請指定足以容納使用控制碼執行之編碼 (封送處理) 作業的緩衝區。 解除封存時,您會提供包含要解碼之所有資料的緩衝區。

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

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