Pregunta

I want to define several structs in IDL file. Then return that struct type's object in a service. To do that I have to import that structs. How can I import them in IDL.

namespace java abc.xyz

struct struct_{
    1:string s
    2:bool b

}

service struct_test{
    struct_ getstruct_()
}
¿Fue útil?

Solución

Yes, and it is as @Vj- correctly pointed out:

include "path/to/file.thrift"

By the way, it is possible to generate code for all thrift IDL including the included files by using the -r (for recursive) when calling the compiler.

There are two important things to know:

(1) Definitions from the included file are referred in the including file using a prefix, which comes from the file name of the included IDL. The tutorial has a good example (note the shared prefix):

include "shared.thrift"

service Calculator extends shared.SharedService {
    // more code
}

(2) it is very recommended to declare different namespaces in every IDL file. Otherwise it could happen with some target languages (for example PHP), that the code generated from the outer IDL overwrites the code generated from the inner IDL because the same output folder is used.

For example:

namespace * tutorial

and

namespace * shared

Otros consejos

You can do that by simply adding the following to the beginning of the .thrift file.

include "path/to/file.thrift"

Note the .thrift extension at the end of the file name.

The path given is relative, and if none is given, then the current directory is searched.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top