示例#1
0
int mount_fiboMain(int argc, char *argv[]) {
    /* Create class that mounts fibonacci numbers */
    corto_class FiboClass = createFiboClass();
    if (!FiboClass) {
        goto error;
    }

    /* Create instance of fibonacci mount */
    corto_mount connector = createMountInstance(FiboClass);
    if (!connector) {
        goto error;
    }

    /* Request fibonacci numbers 0 to 10 */
    corto_resultIter it;
    corto_select("/fibo", "*").limit(0, 10).contentType("text/corto").iter(&it);
    {corto_resultIterForeach(it, result) {
        printf("fibo(%s) = %s\n", result.id, corto_result_getText(&result));
    }}
示例#2
0
文件: mount.c 项目: hendrenja/corto
int corto_mount_alignSubscriptionsAction(
  corto_object e,
  corto_object instance,
  void *userData)
{
    corto_mount this = userData;
    corto_iter it;
    corto_subscriber s = e;

    CORTO_UNUSED(instance);

    corto_select(s->query.select)
      .from(s->query.from)
      .type(s->query.type)
      .mount(this)
      .subscribe(&it);

    /* Visit all objects to find all subscriptions */
    while (corto_iter_hasNext(&it)) {
        corto_iter_next(&it);
    }

    return 1;
}
int select_contentTypeMain(int argc, char *argv[]) {

    /* Create a Point type, so we have something to serialize to JSON */
    corto_struct Point = corto_declareChild(root_o, "Point", corto_struct_o);
    if (!Point) {
        goto error;
    }

    /* Create x member */
    corto_member x = corto_declareChild(Point, "x", corto_member_o);
    if (!x) {
        goto error;
    }
    if (!corto_checkState(x, CORTO_DEFINED)) {
        corto_setref(&x->type, corto_int32_o);
        if (corto_define(x)) {
            goto error;
        }
    }

    /* Create y member */
    corto_member y = corto_declareChild(Point, "y", corto_member_o);
    if (!y) {
        goto error;
    }
    if (!corto_checkState(y, CORTO_DEFINED)) {
        corto_setref(&y->type, corto_int32_o);
        if (corto_define(y)) {
            goto error;
        }
    }

    /* Finalize Point struct */
    if (corto_define(Point)) {
        goto error;
    }

    /* Create two instances of Point. */
    corto_object p1 = corto_declareChild(root_o, "p1", Point);
    if (!p1) {
        goto error;
    }

    if (!corto_checkState(p1, CORTO_DEFINED)) {
        *(corto_int32*)CORTO_OFFSET(p1, x->offset) = 10;
        *(corto_int32*)CORTO_OFFSET(p1, y->offset) = 10;
        if (corto_define(p1)) {
            goto error;
        }
    }

    corto_object p2 = corto_declareChild(root_o, "p2", Point);
    if (!p2) {
        goto error;
    }

    if (!corto_checkState(p2, CORTO_DEFINED)) {
        *(corto_int32*)CORTO_OFFSET(p2, x->offset) = 20;
        *(corto_int32*)CORTO_OFFSET(p2, y->offset) = 30;
        if (corto_define(p2)) {
            goto error;
        }
    }

    /* Select all instances of type Point, get value in JSON */
    corto_iter it;
    corto_int16 ret = corto_select("/", "*")
      .contentType("text/json")
      .type("/Point")
      .iter(&it);
    if (ret) {
        goto error;
    }

    while (corto_iterHasNext(&it)) {
        corto_result *r = corto_iterNext(&it);
        printf("id: %s, value: %s\n", r->id, corto_result_getText(r));
    }

    return 0;
error:
    corto_error("error: %s", corto_lasterr());
    return -1;
}
示例#4
0
/* This is a managed file. Do not delete this comment. */

#include <include/test.h>
void test_BinarySerializer_tc_serializeReferenceType(
    test_BinarySerializer this)
{
    /* Use corto_select to serialize corto package to binary format */
    ut_iter it;
    test_assert(corto_select("corto").format("binary/corto").iter(&it) == 0);

    test_assert(ut_iter_hasNext(&it) != 0);
    corto_record *r = ut_iter_next(&it);
    test_assert(r != NULL);
    test_assert(r->value != 0);

    corto_value src_value = corto_value_mem(corto_o, corto_package_o);
    corto_value dst_value = corto_value_mem((void*)r->value, corto_package_o);

    /* Test if values are equal */
    test_assert(corto_value_compare(&src_value, &dst_value) == 0);
    test_assert(ut_iter_hasNext(&it) == 0);
}

void test_BinarySerializer_tc_copyReferenceType(
    test_BinarySerializer this)
{
    corto_fmt fmt = corto_fmt_lookup("binary/corto");
    test_assert(fmt != NULL);

    corto_value src_value = corto_value_mem(corto_o, corto_package_o);