You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by tr...@apache.org on 2016/09/16 17:07:50 UTC

qpid-dispatch git commit: DISPATCH-513 - Added a typed iterator to parsed field (qd_parsed_field_t). [PR from Ganesh Murthy] This closes #100

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 113228490 -> 0d047bebf


DISPATCH-513 - Added a typed iterator to parsed field (qd_parsed_field_t). [PR from Ganesh Murthy]
This closes #100


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/0d047beb
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/0d047beb
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/0d047beb

Branch: refs/heads/master
Commit: 0d047bebf1ecc93e4dc95d00fdb35f4ca451b1fb
Parents: 1132284
Author: Ted Ross <tr...@redhat.com>
Authored: Fri Sep 16 13:05:53 2016 -0400
Committer: Ted Ross <tr...@redhat.com>
Committed: Fri Sep 16 13:05:53 2016 -0400

----------------------------------------------------------------------
 include/qpid/dispatch/parse.h | 12 ++++++++++++
 src/parse.c                   | 11 +++++++++++
 tests/parse_test.c            |  8 ++++++++
 3 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/0d047beb/include/qpid/dispatch/parse.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/parse.h b/include/qpid/dispatch/parse.h
index 47f3069..d38a5fa 100644
--- a/include/qpid/dispatch/parse.h
+++ b/include/qpid/dispatch/parse.h
@@ -91,6 +91,18 @@ uint8_t qd_parse_tag(qd_parsed_field_t *field);
  */
 qd_field_iterator_t *qd_parse_raw(qd_parsed_field_t *field);
 
+
+/**
+ * Return an iterator for the typed content of the field. Contains the type followed by the raw content.
+ *
+ * IMPORTANT: The returned iterator is owned by the field and *must not* be
+ * freed by the caller of this function.
+ *
+ * @param field The field pointer returned by qd_parse.
+ * @return A field iterator that describes the field's typed content.
+ */
+qd_field_iterator_t *qd_parse_typed(qd_parsed_field_t *field);
+
 /**
  * Return the raw content as an unsigned integer up to 32-bits.  This is
  * valid only for scalar fields of a fixed size of 4-octets or fewer.

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/0d047beb/src/parse.c
----------------------------------------------------------------------
diff --git a/src/parse.c b/src/parse.c
index 662b37a..7a633f1 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -30,6 +30,7 @@ struct qd_parsed_field_t {
     qd_parsed_field_list_t  children;
     uint8_t                 tag;
     qd_field_iterator_t    *raw_iter;
+    qd_field_iterator_t    *typed_iter;
     const char             *parse_error;
 };
 
@@ -111,6 +112,7 @@ static qd_parsed_field_t *qd_parse_internal(qd_field_iterator_t *iter, qd_parsed
     DEQ_INIT(field->children);
     field->parent   = p;
     field->raw_iter = 0;
+    field->typed_iter = qd_field_iterator_dup(iter);
 
     uint32_t length;
     uint32_t count;
@@ -152,6 +154,9 @@ void qd_parse_free(qd_parsed_field_t *field)
     if (field->raw_iter)
         qd_field_iterator_free(field->raw_iter);
 
+    if (field->typed_iter)
+        qd_field_iterator_free(field->typed_iter);
+
     qd_parsed_field_t *sub_field = DEQ_HEAD(field->children);
     while (sub_field) {
         qd_parsed_field_t *next = DEQ_NEXT(sub_field);
@@ -189,6 +194,12 @@ qd_field_iterator_t *qd_parse_raw(qd_parsed_field_t *field)
 }
 
 
+qd_field_iterator_t *qd_parse_typed(qd_parsed_field_t *field)
+{
+    return field->typed_iter;
+}
+
+
 uint32_t qd_parse_as_uint(qd_parsed_field_t *field)
 {
     uint32_t result = 0;

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/0d047beb/tests/parse_test.c
----------------------------------------------------------------------
diff --git a/tests/parse_test.c b/tests/parse_test.c
index 4d30cce..ec7d74a 100644
--- a/tests/parse_test.c
+++ b/tests/parse_test.c
@@ -70,6 +70,14 @@ static char *test_parser_fixed_scalars(void *context)
         qd_field_iterator_t *field  = qd_field_iterator_binary(fs_vectors[idx].data,
                                                                fs_vectors[idx].length);
         qd_parsed_field_t *parsed = qd_parse(field);
+
+        qd_field_iterator_t *typed_iter = qd_parse_typed(parsed);
+
+        int length = qd_field_iterator_length(typed_iter);
+
+        if (length != fs_vectors[idx].length)
+            return "Length of typed iterator does not match actual length";
+
         if (!qd_parse_ok(parsed)) return "Unexpected Parse Error";
         if (qd_parse_tag(parsed) != fs_vectors[idx].expected_tag) {
             sprintf(error, "(%d) Tag: Expected %02x, Got %02x", idx,


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org