Code

proto: Add support for marshaling regex types.
authorSebastian Harl <sh@tokkee.org>
Tue, 23 Dec 2014 17:25:57 +0000 (18:25 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 23 Dec 2014 17:25:57 +0000 (18:25 +0100)
That is, marshal the regex's raw string to be recompiled by the receiver.

src/utils/proto.c
t/unit/utils/proto_test.c

index af4215b8f987a32c5c0c264f9b5f43bbec56ed5f..56ef745ff0d5f6b06336174f55538b40fd042013 100644 (file)
@@ -164,6 +164,8 @@ sdb_proto_marshal_data(char *buf, size_t buf_len, sdb_data_t *datum)
        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;
index 1ec0615fa33fd7a7f29c2796a9c2c369e92afebe..52ae936bc4bf6a69bf3ab77f81e67093524e26d3 100644 (file)
@@ -39,6 +39,7 @@ START_TEST(test_marshal_data)
 #define STRING_TYPE "\0\0\0\3"
 #define DATETIME_TYPE "\0\0\0\4"
 #define BINARY_TYPE "\0\0\0\5"
+#define REGEX_TYPE "\0\0\0\6"
 
 #define NULL_ARRAY "\0\0\1\0"
 #define INT_ARRAY "\0\0\1\1"
@@ -46,6 +47,7 @@ START_TEST(test_marshal_data)
 #define STRING_ARRAY "\0\0\1\3"
 #define DATETIME_ARRAY "\0\0\1\4"
 #define BINARY_ARRAY "\0\0\1\5"
+#define REGEX_ARRAY "\0\0\1\6"
 
        regex_t dummy_re;
        int64_t int_values[] = { 47, 11, 23 };
@@ -85,7 +87,7 @@ START_TEST(test_marshal_data)
                },
                {
                        { SDB_TYPE_REGEX, { .re = { "dummy", dummy_re } } },
-                       -1, NULL, /* not supported */
+                       14, REGEX_TYPE "\0\0\0\x6" "dummy\0",
                },
                {
                        { SDB_TYPE_INTEGER | SDB_TYPE_ARRAY, { .array = {