새소식

Big Data

Apache Thrift IDL 작성 시 .thrift 파일 include 하기

  • -

Thrift 파일은 다른 Thrift 파일의 공용 구조체나 서비스 정의를 참조할 수 있다.

Thrift 는 이런 참조를 현재 경로나, 컴파일러의 -I 플래그에 지정된 상대 경로에서 찾아 Include 한다.

참조된 객체들은 .thrift 파일의 이름을 접두어로 사용해서 접근 가능하다.

1). org.model.thrift 파일

namespace java org.model

struct FileModel{ 
    1: string name; 
    2: string cPath; 
    3: string hPath; 
    4: string pPath; 
    5: string createDate; 
    6: string modifiedDate; 
    7: string accessDate; 
    8: long size; 
    9: boolean canRead; 
    10: boolean canWrite; 
    11: boolean isFile; 
}


2). org.service.thrift 파일

include "org.model.thrift"

namespace java org.service

typedef list<org.model.FileModel> FileCollection

service FileService{
    FileCollection file(1:string path)
}


컴파일 시 -r 옵션은 include된 .thrift 파일까지 함께 컴파일 할 수 있는 옵션으로 실행

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.