Thrift manual
Install
brew install thrift
Grammer
namespace
As same as “package” in Java.
namespace java resource.thrift.sdk.hermes
结合mv,管理路径。
Primary
- byte: 有符号字节
- i16: 16位有符号整数
- i32: 32位有符号整数
- i64: 64位有符号整数
- double: 64位浮点数
- string: 字符串
Collection
Element in collection can be any types except service.
- list
- set
- map<K, V>
Enum
enum THermesTemplateVerifyStatus {
PENDING = 0
SUCCESS = 1
FAIL = 2
}
Struct
struct THermesUserReply {
1: required i64 id
2: required string phone_number
3: required Timestamp reply_time
4: required string message
}
会生成一个同名class(Java Bean) bool/byte/i16/i32/i64/double/enum类型的处理逻辑 [required属性字段]转为原生类型:boolean/byte/short/int/long/double/int [optional属性字段]转为装箱类型:Boolean/Byte/Short/Integer/Long/Double/Integer [default属性字段]转为装箱类型:Boolean/Byte/Short/Integer/Long/Double/Integer 如服务端实现中有特殊逻辑,可以在和服务方确认逻辑后手动修改类型 Thrift中每个字段都会生成一个private字段,一个public getter,一个public setter 生成的每个字段都会打上@Index(index)注解 字段不支持默认值
Service
service HermesService {
bool ping()
throws (1: HermesUserException user_exception,
2: HermesSystemException system_exception,
3: HermesUnknownException unknown_exception),
Exception
exception HermesUnknownException {
1: required HermesErrorCode error_code,
2: required string error_name,
3: required string message,
}
Generate
thrift -gen java hermes.thrift
Tutorial
This work is licensed under a CC A-S 4.0 International License.