This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new f86da24 C: Namespace "" means space = NULL.
f86da24 is described below
commit f86da24a94fb0cd9d31f266c2639f4b82a3392b7
Author: Ben Walsh <[email protected]>
AuthorDate: Fri May 17 10:11:08 2013 +0000
C: Namespace "" means space = NULL.
---
lang/c/src/schema.c | 27 +++++++++++++++++-----
lang/c/tests/schema_tests/pass/namespace_null_enum | 8 +++++++
.../c/tests/schema_tests/pass/namespace_null_fixed | 7 ++++++
.../tests/schema_tests/pass/namespace_null_record | 8 +++++++
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/lang/c/src/schema.c b/lang/c/src/schema.c
index 3ade114..a78f733 100644
--- a/lang/c/src/schema.c
+++ b/lang/c/src/schema.c
@@ -935,6 +935,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t *schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_record(fullname,
namespace);
} else {
*schema = avro_schema_record(fullname,
parent_namespace);
@@ -1032,6 +1035,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t
*schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_enum_ns(fullname,
namespace);
} else {
*schema = avro_schema_enum_ns(fullname,
parent_namespace);
@@ -1166,6 +1172,9 @@ avro_schema_from_json_t(json_t *json, avro_schema_t
*schema,
avro_str_free(namespace);
} else if (json_is_string(json_namespace)) {
const char *namespace =
json_string_value(json_namespace);
+ if (strlen(namespace) == 0) {
+ namespace = NULL;
+ }
*schema = avro_schema_fixed_ns(fullname,
namespace, (int64_t) size);
} else {
*schema = avro_schema_fixed_ns(fullname,
parent_namespace, (int64_t) size);
@@ -1638,9 +1647,11 @@ static int write_record(avro_writer_t out, const struct
avro_record_schema_t *re
check(rval, avro_write_str(out, "{\"type\":\"record\",\"name\":\""));
check(rval, avro_write_str(out, record->name));
check(rval, avro_write_str(out, "\","));
- if (record->space && nullstrcmp(record->space, parent_namespace)) {
+ if (nullstrcmp(record->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, record->space));
+ if (record->space) {
+ check(rval, avro_write_str(out, record->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"fields\":["));
@@ -1666,9 +1677,11 @@ static int write_enum(avro_writer_t out, const struct
avro_enum_schema_t *enump,
check(rval, avro_write_str(out, "{\"type\":\"enum\",\"name\":\""));
check(rval, avro_write_str(out, enump->name));
check(rval, avro_write_str(out, "\","));
- if (enump->space && nullstrcmp(enump->space, parent_namespace)) {
+ if (nullstrcmp(enump->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, enump->space));
+ if (enump->space) {
+ check(rval, avro_write_str(out, enump->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"symbols\":["));
@@ -1697,9 +1710,11 @@ static int write_fixed(avro_writer_t out, const struct
avro_fixed_schema_t *fixe
check(rval, avro_write_str(out, "{\"type\":\"fixed\",\"name\":\""));
check(rval, avro_write_str(out, fixed->name));
check(rval, avro_write_str(out, "\","));
- if (fixed->space && nullstrcmp(fixed->space, parent_namespace)) {
+ if (nullstrcmp(fixed->space, parent_namespace)) {
check(rval, avro_write_str(out, "\"namespace\":\""));
- check(rval, avro_write_str(out, fixed->space));
+ if (fixed->space) {
+ check(rval, avro_write_str(out, fixed->space));
+ }
check(rval, avro_write_str(out, "\","));
}
check(rval, avro_write_str(out, "\"size\":"));
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_enum
b/lang/c/tests/schema_tests/pass/namespace_null_enum
new file mode 100644
index 0000000..3c3a745
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_enum
@@ -0,0 +1,8 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "enum", "namespace": "", "name": "Z",
+ "symbols": ["Foo", "Bar"]}
+ }
+ ]}},
+ {"name": "t", "type": "Z"}
+]}
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_fixed
b/lang/c/tests/schema_tests/pass/namespace_null_fixed
new file mode 100644
index 0000000..a3aa570
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_fixed
@@ -0,0 +1,7 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "fixed", "namespace": "", "name": "Z",
"size": 8}
+ }
+ ]}},
+ {"name": "t", "type": "Z"}
+]}
diff --git a/lang/c/tests/schema_tests/pass/namespace_null_record
b/lang/c/tests/schema_tests/pass/namespace_null_record
new file mode 100644
index 0000000..4b18dd5
--- /dev/null
+++ b/lang/c/tests/schema_tests/pass/namespace_null_record
@@ -0,0 +1,8 @@
+{"type": "record", "name": "R", "fields": [
+ {"name": "s", "type": {"type": "record", "namespace": "x", "name": "Y",
"fields": [
+ {"name": "e", "type": {"type": "record", "namespace": "", "name": "Z",
"fields": [
+ {"name": "f", "type": "Z"}
+ ]}}
+ ]}},
+ {"name": "t", "type": "Z"}
+]}