[Commotion-admin] [commotiond] pretty print nested trees and lists (#89)

Dan Staples notifications at github.com
Sat Feb 8 02:04:18 UTC 2014


updated and added printing functions for lists and trees to output fully formatted JSON-style nested objects

to test: write test program, build a complex nested object using lists and objects and various basic types, and print it using `co_list_print()` or `co_tree_print()`!

Here's code for a sample object:

    CHECK_MEM((params = co_tree16_create()));
    CHECK(co_tree_insert(params,"testint",sizeof("testint"),co_int8_create(-123,0)),"Failed to insert testint into request tree");
    co_tree_insert(params,"testuint",sizeof("testuint"),co_uint8_create(123,0));
    co_tree_insert(params,"testfloat",sizeof("testfloat"),co_float32_create(123.567,0));
    co_obj_t *tree2 = co_tree16_create();
    co_obj_t *tree3 = co_tree16_create();
    co_tree_insert(tree3,"subtree2",sizeof("subtree2"),co_str8_create("subtree",sizeof("subtree"),0));
    co_tree_insert(tree3,"blah",sizeof("blah"),co_str8_create("blah",sizeof("blah"),0));
    co_tree_insert(tree2,"subtree",sizeof("subtree"),tree3);
    co_tree_insert(tree2,"foo",sizeof("foo"),co_str8_create("foo",sizeof("foo"),0));
    co_obj_t *list = co_list16_create();
    co_list_append(list,co_str8_create("bar",sizeof("bar"),0));
    co_tree_insert(tree2,"bar",sizeof("bar"),list);
    co_obj_t *tree4 = co_tree16_create();
    co_tree_insert(tree4,"baz",sizeof("baz"),co_str8_create("baz",sizeof("baz"),0));
    co_list_append(list,tree4);
    co_obj_t *list2 = co_list16_create();
    co_list_append(list2,co_str8_create("egg",sizeof("egg"),0));
    co_list_append(list,list2);
    CHECK(co_tree_insert(params,"test3",sizeof("test3"),tree2),"Failed to insert tree2 into request tree");
    co_tree_print(params);

And here's what it should print out:

      {
        "test3": 
          {
            "bar": 
              [
                "bar",
                {
                  "baz": "baz"
                },
                [
                  "egg"
                ]
              ],
            "foo": "foo",
            "subtree": 
              {
                "blah": "blah",
                "subtree2": "subtree"
              }
          },
        "testfloat": 123.567001,
        "testint": -123,
        "testuint": 123
      }

You can merge this Pull Request by running:

  git pull https://github.com/opentechinstitute/commotiond print-json

Or you can view, comment on it, or merge it online at:

  https://github.com/opentechinstitute/commotiond/pull/89

-- Commit Summary --

  * updated and added printing functions for lists and trees to output fully formatted JSON-style nested objects

-- File Changes --

    M src/list.c (91)
    M src/list.h (14)
    M src/tree.c (91)
    M src/tree.h (7)

-- Patch Links --

https://github.com/opentechinstitute/commotiond/pull/89.patch
https://github.com/opentechinstitute/commotiond/pull/89.diff

---
Reply to this email directly or view it on GitHub:
https://github.com/opentechinstitute/commotiond/pull/89
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.chambana.net/pipermail/commotion-admin/attachments/20140207/4ca240c7/attachment.html>


More information about the Commotion-admin mailing list