Binary send and receive functions

The binary send function converts opaque data type values to the client format before sending them to the client. The C name of the binary send function for each opaque data type is OpaqueSend(). The binary receive function converts opaque data type values from the client format before sending them to the database server. The C name of the binary receive function for each opaque data type is OpaqueReceive().

BladeSmith generates complete C code for these functions.

The generated code

The binary send and receive functions adjust data types for differing byte order and alignment requirements on the client and server computers. The functions call the appropriate mi_put and mi_get DataBlade® API accessor functions to transform individual members of the opaque type structure.

The binary send function takes the opaque data type as its argument and returns a pointer to an mi_sendrecv type, which contains the opaque type structure, and an unused MI_FPARAM pointer. The mi_sendrecv type is the client form of the opaque data type. The binary receive function takes an mi_sendrecv type as its argument and returns the opaque data type. If the opaque data type is variable length, then the binary send function takes an mi_bitvarying type as its argument, and the binary receive function returns an mi_bitvarying type.

The binary send function calls mi_put DataBlade API accessor functions to store the client representation of the data type in the structure to be returned to the database server. The binary receive function calls mi_get DataBlade API accessor functions to retrieve values for each structure member from the input received from the client.

The following code, taken from the Circle DataBlade module CircSend() function, calls mi_put_double_precision() to store values from an input Circ data type (addressed by the Gen_InData argument) to an output Circ data type (addressed by the Gen_OutData argument):
/* Prepare the value for Gen_OutData->center.x. */
mi_put_double_precision((mi_unsigned_char1 *)&Gen_OutData->center.x, &Gen_InData->center.x);

/* Prepare the value for Gen_OutData->center.y. */
mi_put_double_precision((mi_unsigned_char1 *)&Gen_OutData->center.y, &Gen_InData->center.y);

/* Prepare the value for Gen_OutData->radius. */
mi_put_double_precision((mi_unsigned_char1 *)&Gen_OutData->radius, &Gen_InData->radius);

The corresponding code for the CircReceive() function is identical, except it uses mi_get_double_precision() instead of mi_put_double_precision().

Customize the code

In general, you do not need to modify the generated binary send and receive functions. If you do add code to one of the functions, you must make corresponding changes to the other function.

You can alter the binary send and receive functions to encrypt data in the mi_sendrecv type before sending data to the client and decrypt data from the mi_sendrecv type before receiving data into the database.

Examples

The following example DataBlade module use the binary send and receive functions without modification:
  • UDTExporter DataBlade module
  • Matrix DataBlade module
  • Circle DataBlade module
  • MMXImage DataBlade module