OSSP CVS Repository

ossp - Check-in [809]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 809
Date: 2001-Aug-30 16:49:49 (local)
2001-Aug-30 14:49:49 (UTC)
User:simons
Branch:
Comment: Implemented xml_encode_double(), xml_decode_double(), xml_encode_float(), and xml_decode_float().
Tickets:
Inspections:
Files:
ossp-pkg/xds/xds_engine_xml.c      1.7 -> 1.8     42 inserted, 4 deleted

ossp-pkg/xds/xds_engine_xml.c 1.7 -> 1.8

--- xds_engine_xml.c     2001/08/13 19:48:02     1.7
+++ xds_engine_xml.c     2001/08/30 14:49:49     1.8
@@ -414,6 +414,35 @@
 #endif /* XDS_HAVE_64_BIT_SUPPORT */
 
 /*
+ * Encode/decode floating point values.
+ */
+
+int xml_encode_float(xds_t *xds, void *engine_context,
+                     void *buffer, size_t buffer_size,
+                     size_t *used_buffer_size, va_list *args)
+    {
+    xds_init_encoding_engine(7 + 8 + 1);
+    *used_buffer_size =
+        snprintf(buffer, buffer_size, "<float>%f</float>", va_arg(*args, double));
+    if (*used_buffer_size >= buffer_size)
+        return XDS_ERR_OVERFLOW;
+    else
+        return XDS_OK;
+    }
+
+int xml_decode_float(xds_t *xds, void *engine_context,
+                      void *buffer, size_t buffer_size,
+                      size_t *used_buffer_size, va_list *args)
+    {
+    xds_init_decoding_engine(7 + 8 + 1);
+    if (sscanf(buffer, "<float>%f</float>%n",
+               va_arg(*args, float*), used_buffer_size) != 1)
+        return XDS_ERR_TYPE_MISMATCH;
+    else
+        return XDS_OK;
+    }
+
+/*
  * Encode/decode double-precision floating point values.
  */
 
@@ -421,16 +450,25 @@
                       void *buffer, size_t buffer_size,
                       size_t *used_buffer_size, va_list *args)
 {
-    /* XXX */
-    return -1;
+    xds_init_encoding_engine(8 + 9 + 1);
+    *used_buffer_size =
+        snprintf(buffer, buffer_size, "<double>%f</double>", va_arg(*args, double));
+    if (*used_buffer_size >= buffer_size)
+        return XDS_ERR_OVERFLOW;
+    else
+        return XDS_OK;
 }
 
 int xml_decode_double(xds_t *xds, void *engine_context,
                       void *buffer, size_t buffer_size,
                       size_t *used_buffer_size, va_list *args)
 {
-    /* XXX */
-    return -1;
+    xds_init_decoding_engine(8 + 9 + 1);
+    if (sscanf(buffer, "<double>%lf</double>%n",
+               va_arg(*args, double*), used_buffer_size) != 1)
+        return XDS_ERR_TYPE_MISMATCH;
+    else
+        return XDS_OK;
 }
 
 /*

CVSTrac 2.0.1