Thrift manual

    xiaoxiao2026-01-11  5

    Thrift manual

    我的github pages 地址:https://alexanderwangsgithub.github.io/

    Thrift manual InstallGrammer namespacePrimaryCollectionEnumStructServiceException GenerateTutorial

    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.

    listsetmap

    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

    tutorial

    基础使用教程

    基础使用教2

    Java版的各种Thrift server实现的比较

    转载请注明原文地址: https://ju.6miu.com/read-1305883.html
    最新回复(0)