Condividi tramite


Serializzazione del buffer fisso

Quando si usa lo stile del buffer fisso, specificare un buffer sufficientemente grande per supportare le operazioni di codifica (marshalling) eseguite con l'handle. Quando si annulla ilmarshaling, si specifica il buffer che contiene tutti i dati da decodificare.

Lo stile di serializzazione del buffer fisso usa le routine seguenti:

La funzione MesEncodeFixedBufferHandleCreate alloca la memoria necessaria per l'handle di codifica e quindi la inizializza. L'applicazione può chiamare MesBufferHandleReset per reinizializzare l'handle oppure può chiamare MesHandleFree per liberare la memoria dell'handle. Per creare un handle di decodifica corrispondente all'handle di codifica con stile fisso, è necessario usare MesDecodeBufferHandleCreare.

L'applicazione chiama MesHandleFree per liberare l'handle del buffer di codifica o decodifica.

Esempi di codifica del buffer fisso

La sezione seguente fornisce un esempio di come usare un handle di serializzazione dello stile del buffer fisso per la codifica delle procedure.

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

L'estratto seguente rappresenta una parte di un'applicazione.

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

Nella sezione seguente viene fornito un esempio di come usare un handle di serializzazione dello stile del buffer fisso per la codifica dei tipi.

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

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

L'estratto seguente rappresenta i frammenti dell'applicazione pertinenti.

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