Microsoft RPC supports two methods for encoding and decoding, or "serializing," data. You can serialize on a procedure or type basis. Serialization means that the data is marshalled to and unmarshalled from buffers that you control. This differs from the traditional usage of RPC in which the stubs and the RPC run-time library have full control of the marshalling buffers and the process is transparent to you. You can use the buffer for storage on a permanent media, encryption, and so on. When encoding, the data is marshalled to a buffer and the buffer is passed to you. When decoding, you supply a marshalling buffer with data in it and the data is unmarshalled from the buffer to memory.
When you use procedure serialization, MIDL generates a serialization stub for the procedure decorated with serialization attributes. When you call this routine, you execute a serialization call instead of a remote call. The procedure arguments are marshalled to or unmarshalled from a buffer in the usual way and you control the buffers.
In contrast, when type serialization occurs (a type is labelled with serialization attributes), MIDL generates routines to size, encode, and decode objects of that type. To serialize data, you must call these routines in the appropriate way. Type serialization is a Microsoft extension and, as such, is not available when you compile in DCE-compatibility (/osf) mode. By using the encode and decode attributes as interface attributes, RPC applies encoding to all the types and routines defined in the IDL file.
Note You must supply adequately aligned buffers when using encoding services. The beginning of the buffer must be aligned at 8. For procedure serialization, each procedure call must marshal into or unmarshal from a buffer position aligned at 8. For type serialization, sizing, encoding, and decoding must start at a position aligned at 8.