Dela via


Fast buffertserialisering

När du använder det fasta buffertformatet anger du en buffert som är tillräckligt stor för att hantera de kodningsåtgärder (marshalling) som utförs med handtaget. När du avmarkerar ska du ange bufferten som innehåller alla data som ska avkodas.

Det fasta buffertformatet för serialisering använder följande rutiner:

Funktionen MesEncodeFixedBufferHandleCreate allokerar det minne som behövs för kodningshandtaget och initierar det sedan. Programmet kan anropa MesBufferHandleReset för att initiera om handtaget, eller anropa MesHandleFree- för att frigöra handtagets minne. Om du vill skapa ett avkodningshandtag som motsvarar det fasta formatkodningshandtaget måste du använda MesDecodeBufferHandleSkapa.

Programmet anropar MesHandleFree- för att frigöra bufferthandtaget för kodning eller avkodning.

Exempel på kodning av fast buffert

Följande avsnitt innehåller ett exempel på hur du använder ett fast buffertformat – serialiserande handtag för procedurkodning.

/*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();
}

Följande utdrag representerar en del av ett program.

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

Följande avsnitt innehåller ett exempel på hur du använder ett fast buffertformat – serialiserande handtag för typkodning.

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

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

Följande utdrag representerar relevanta programfragment.

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