如何包含已在另一个.avdl文件中定义的记录?

时间:2013-08-30 21:30:57

标签: java avro

我有以下.avdl文件,我正在尝试编译:

@namespace("com.test.foo.bar")
protocol PairStore {

    /* This is already defined in another namespace - "com.test.foo.nan" */
    record Pair {
        string item1;
        string item2;
    }

    record Registration {
        Pair inputPair;
        Pair outputPair;
        string indexURI;
    }
}

所以问题是当我在Pair中创建com.test.foo.nanPairStore时,如何引用Registration中定义的com.test.foo.bar?< / p>

2 个答案:

答案 0 :(得分:0)

在深入了解Avro文档后,我终于找到了一个包含解决方案的示例。具体而言,this example

@namespace("com.test.foo")
protocol PairStore {

    /** Still need to define this record, but define it in the existing namespace. */
    @namespace("com.test.bar")
    record Pair {
        string item1;
        string item2;
    }

    record Registration {
        /** And this is how you refer to that record. */
        com.test.bar.Pair inputPair;
        com.test.bar.Pair outputPair;
        string indexURI;
    }
}

答案 1 :(得分:0)

您应该能够从另一个avdl文件中导入记录,如下所示:

@namespace("com.test.foo")
    protocol PairStore {

    /** No need to define the record again, 
        just import the file that has Pair defined*/
    import idl "bar.avdl";

    record Registration {
        /** And this is how you refer to that record. */
        com.test.bar.Pair inputPair;
        com.test.bar.Pair outputPair;
        string indexURI;
    }
}