From 8dd1618e1dc92bd9bc60d78401e879caf919e37e Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 23 Dec 2014 18:25:57 +0100 Subject: [PATCH] proto: Add support for marshaling regex types. That is, marshal the regex's raw string to be recompiled by the receiver. --- src/utils/proto.c | 2 ++ t/unit/utils/proto_test.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/proto.c b/src/utils/proto.c index af4215b..56ef745 100644 --- a/src/utils/proto.c +++ b/src/utils/proto.c @@ -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; diff --git a/t/unit/utils/proto_test.c b/t/unit/utils/proto_test.c index 1ec0615..52ae936 100644 --- a/t/unit/utils/proto_test.c +++ b/t/unit/utils/proto_test.c @@ -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 = { -- 2.30.2