OSSP CVS Repository

ossp - Difference in ossp-pkg/xds/xds_engine_xdr.c versions 1.6 and 1.7
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/xds/xds_engine_xdr.c 1.6 -> 1.7

--- xds_engine_xdr.c     2001/08/13 19:48:02     1.6
+++ xds_engine_xdr.c     2001/08/22 20:23:48     1.7
@@ -294,6 +294,90 @@
 #endif /* XDS_HAVE_64_BIT_SUPPORT */
 
 /*
+ * Encode/decode floating point values.
+ */
+
+int xdr_encode_float(xds_t *xds, void *engine_context,
+                     void *buffer, size_t buffer_size,
+                     size_t *used_buffer_size, va_list *args)
+{
+    xds_float_t value;
+    xds_uint8_t tmp;
+
+    xds_init_encoding_engine(4);
+
+    /* Get value and format it into the structure. */
+    float2xds_float(&value, (float)va_arg(*args, double));
+
+    memset(buffer, 0, 4);
+
+    if (value.sign == 1)
+        ((xds_uint8_t*)buffer)[0] |= 0x80;
+
+    tmp = value.exponent + 127;
+    ((xds_uint8_t*)buffer)[0] |= tmp >> 1;
+    ((xds_uint8_t*)buffer)[1] |= (tmp & 0x01) << 7;
+
+    ((xds_uint8_t*)buffer)[1] |= (xds_uint8_t)((value.fraction & 0x7fffff) >> 16);
+    ((xds_uint8_t*)buffer)[2] |= (xds_uint8_t)((value.fraction & 0x00ffff) >>  8);
+    ((xds_uint8_t*)buffer)[3] |= (xds_uint8_t)((value.fraction & 0x0000ff) >>  0);
+
+    return XDS_OK;
+}
+
+int xdr_decode_float(xds_t *xds, void *engine_context,
+                     void *buffer, size_t buffer_size,
+                     size_t *used_buffer_size, va_list *args)
+{
+    float*       value;
+    xds_uint32_t fraction;
+    xds_uint8_t  exponent;
+    size_t       i;
+    char         sign;
+
+    xds_init_decoding_engine(4);
+
+    value = va_arg(*args, float*);
+    *value = 0.0;
+
+    fraction  = (((xds_uint8_t*)buffer)[1] & 0x7fffff) << 16;
+    fraction += ((xds_uint8_t*)buffer)[2] << 8;
+    fraction += ((xds_uint8_t*)buffer)[3];
+    exponent  = (((xds_uint8_t*)buffer)[0] & 0x7f) << 1;
+    exponent += (((xds_uint8_t*)buffer)[1] & 0x80) >> 7;
+    sign = (((xds_uint8_t*)buffer)[0] & 0x80) >> 7;
+
+    if (fraction == 0 && exponent == 0)
+        return XDS_OK;
+
+    for (i = 23; i > 0; --i)
+        {
+        if ((fraction & 0x01) == 1)
+            *value += 1;
+        *value /= 2.0;
+        fraction /= 2;
+        }
+    *value += 1;
+
+    if (exponent > 127)
+        {
+        for (exponent -= 127; exponent > 0; --exponent)
+            *value *= 2.0;
+        }
+    else
+        {
+        for (exponent = 127 - exponent; exponent > 0; --exponent)
+            *value /= 2.0;
+        }
+
+    if (sign == 1)
+        *value = 0.0 - *value;
+
+    return XDS_OK;
+}
+
+
+/*
  * Encode/decode double-precision floating point values.
  */
 

CVSTrac 2.0.1