diff --git a/src/utils/proto.c b/src/utils/proto.c
index cb88887d1f1313cd0797dcf9a5fbec9c63404277..51c2ed8c45361f4625c4e7dc6d956594d7a96a7e 100644 (file)
--- a/src/utils/proto.c
+++ b/src/utils/proto.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "core/data.h"
#include "core/time.h"
#include "utils/error.h"
#include "utils/proto.h"
-#include <arpa/inet.h>
+#include <assert.h>
#include <errno.h>
+#include <arpa/inet.h>
#include <limits.h>
#include <string.h>
} /* marshal_int */
static ssize_t
-marshal_double(char __attribute__((unused)) *buf,
- size_t __attribute__((unused)) buf_len,
- double __attribute__((unused)) v)
+marshal_double(char *buf, size_t buf_len, double v)
{
- /* XXX: find a good network representation */
- errno = ENOTSUP;
- return -1;
+ uint64_t t = 0;
+ assert(sizeof(v) == sizeof(t));
+ memcpy(&t, &v, sizeof(v));
+#if IEEE754_DOUBLE_BYTE_ORDER != IEEE754_DOUBLE_BIG_ENDIAN
+ t = (((int64_t)ntohl((int32_t)t)) << 32)
+ + ((int64_t)ntohl((int32_t)(t >> 32)));
+#endif
+ if (buf_len >= sizeof(t))
+ memcpy(buf, &t, sizeof(t));
+ return sizeof(t);
} /* marshal_double */
static ssize_t
else if (datum->type == SDB_TYPE_BINARY)
n = marshal_binary(buf, buf_len,
datum->data.binary.length, datum->data.binary.datum);
+ else if (datum->type == SDB_TYPE_REGEX)
+ n = marshal_string(buf, buf_len, datum->data.re.raw);
if (n < 0)
return n;
char **v = datum->data.array.values;
n = marshal_string(buf, buf_len, v[i]);
}
+ else if (type == SDB_TYPE_DATETIME) {
+ sdb_time_t *v = datum->data.array.values;
+ n = marshal_datetime(buf, buf_len, v[i]);
+ }
+ else if (type == SDB_TYPE_BINARY) {
+ struct {
+ size_t length;
+ unsigned char *datum;
+ } *v = datum->data.array.values;
+ n = marshal_binary(buf, buf_len, v[i].length, v[i].datum);
+ }
+ else if (type == SDB_TYPE_REGEX) {
+ struct {
+ char *raw;
+ regex_t regex;
+ } *v = datum->data.array.values;
+ n = marshal_string(buf, buf_len, v[i].raw);
+ }
else {
- errno = ENOTSUP;
+ errno = EINVAL;
return -1;
}