Thrift语法错误

Thrift syntax error

这里是 Thrift 0.9.2。这是我的简单 led.thrift 文件:

namespace c_glib com.example.led
namespace java com.example.led

typedef i32 int

enum LedState {
    Off = 0,
    On = 1
}

struct LedToggleCommand {
    1: required int ledId;
    2: required LedState state;
}

exception LedUnavailableException {
    1: message;
    2: cause;
}

service LedService {
    oneway void toggle(1: LedToggleCommand cmd) throws (1: LedUnavailableException luex);
}

当我 运行 thrift --gen java led.thrift 我得到以下错误:

[ERROR:/Users/myuser/tmp/thrift_samples/samples/led.thrift:17] (last token was ';')
syntax error
[FAILURE:/Users/myuser/tmp/thrift_samples/samples/led.thrift:17] Parser error during include pass.

这是怎么回事?

您需要添加一些数据类型。

exception LedUnavailableException {
    1: string message;
    2: string cause;
}

此外,(至少)较新的版本会告诉您...

[FAILURE:test.thrift:22] Oneway methods can't throw exceptions.