xdrfloat.c

Go to the documentation of this file.
00001 #include "xdr.h"
00002 
00003 
00004 int db__send_float(float d)
00005 {
00006     int stat = DB_OK;
00007 
00008     if (!db__send(&d, sizeof(d)))
00009         stat = DB_PROTOCOL_ERR;
00010 
00011     if (stat == DB_PROTOCOL_ERR)
00012         db_protocol_error();
00013 
00014     return stat;
00015 }
00016 
00017 int db__recv_float(float *d)
00018 {
00019     int stat = DB_OK;
00020 
00021     if (!db__recv(d, sizeof(*d)))
00022         stat = DB_PROTOCOL_ERR;
00023 
00024     if (stat == DB_PROTOCOL_ERR)
00025         db_protocol_error();
00026 
00027     return stat;
00028 }
00029 
00030 
00031 int db__send_float_array(const float *x, int n)
00032 {
00033     int stat = DB_OK;
00034 
00035     if (!db__send(&n, sizeof(n)))
00036         stat = DB_PROTOCOL_ERR;
00037 
00038     if (!db__send(x, n * sizeof(*x)))
00039         stat = DB_PROTOCOL_ERR;
00040 
00041     if (stat == DB_PROTOCOL_ERR)
00042         db_protocol_error();
00043 
00044     return stat;
00045 }
00046 
00047 /* returns an allocated array of floats */
00048 /* caller is responsible for free() */
00049 int db__recv_float_array(float **x, int *n)
00050 {
00051     int stat = DB_OK;
00052     int count = 0;
00053     float *a = NULL;
00054 
00055     if (!db__recv(&count, sizeof(count)))
00056         stat = DB_PROTOCOL_ERR;
00057 
00058     *n = count;
00059 
00060     *x = a = (float *)db_calloc(count, sizeof(*a));
00061 
00062     if (!db__recv(a, count * sizeof(*a)))
00063         stat = DB_PROTOCOL_ERR;
00064 
00065     if (stat == DB_PROTOCOL_ERR)
00066         db_protocol_error();
00067 
00068     return stat;
00069 }