You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> [IDL](https://en.wikipedia.org/wiki/IDL)(Interface description language), which is a descriptive language used to define data types and interfaces in a way that is independent of the programming language or operating system/processor platform.
9
10
10
11
[中文文档](./docs/cn.md)
11
12
13
+
Feel free to try out our [web interface](https://pb-thrift.markeyyuan.monster/), and of course, both languages specification as below, if there are any questions, don't hesitate to open an issue, and PRs are welcome too.
Since protobuf and thrift have many different syntaxes, we can only transform syntaxes that have same meaning, e.g. protobuf message => thrift struct, protobuf enum => thrift enum.
61
69
62
-
Here is a list of transformation rule, so we hope you don't have to worry about protobuf-thrift do sth unexpected.
63
-
64
-
|protobuf type|thrift type|field type|notice|
65
-
|:--:|:--:|:--:|:--:|
66
-
|message|struct|optional => optional; repeated T => list\<T\>|only protobuf 2 have optional field|
67
-
|map<T1,T2>|map<T1,T2>||T1 only support int32/int64/string/float/double, due to thrift syntax|
68
-
|enum|enum|||
69
-
|int32|i32|||
70
-
|int64|i64|||
71
-
|float|double|||
72
-
|double|double|||
73
-
|bool|bool|||
74
-
|string|string|||
75
-
|bytes|binary|||
76
-
|service|service|rpc => methods||
77
-
|constant|const||not support currently|
78
-
|package|namespace|||
79
-
|import|include|||
80
-
|syntax|||only supported in protobuf, so thrift will omit it|
81
-
|option|||only supported in protobuf, so thrift will omit it|
82
-
|extend|||only supported in protobuf, so thrift will omit it|
83
-
|extension|||only supported in protobuf, so thrift will omit it|
84
-
85
-
### Nested Fields
86
-
protobuf support nested field within message, but thrift does not, so protobuf-thrift will prefix nested field name with outer message name to work around this. for example:
70
+
We hope you don't have to worry about protobuf-thrift do sth unexpected, so we **strongly recommend you to read the following document** to get a grasp of what it will do for specific syntaxes.
Protobuf and thrift both have `enum` declaration syntax and basically same grammar, only to note that:
97
+
98
+
> **Proto3 enum declaration's first element must be zero, so if thrift enum with non-zero first element transform to protobuf, protobut-thrift will automatically generate a zero element for you.**
99
+
100
+
for example, if thrift enum like this:
101
+
102
+
```thrift
103
+
enum Status {
104
+
StatusUnreviewed = 1 // first non-zero element
105
+
StatusOnline = 2
106
+
StatusRejected = 3
107
+
StatusOffline = 4
108
+
}
109
+
```
110
+
111
+
will be transformed to:
112
+
113
+
```protobuf
114
+
enum Status {
115
+
Status_Unknown = 0;
116
+
Status_Unreviewed = 1; // first non-zero element
117
+
Status_Online = 2;
118
+
Status_Rejected = 3;
119
+
Status_Offline = 4;
120
+
}
121
+
```
122
+
123
+
### Service
124
+
Protobuf and thrift both have same `service` declaration syntax, but there are several differences:
125
+
126
+
1.**oneway**: only thrift support, which means function will not wait for response. so during thrift-to-pb transformation, this keyword will be ignored.
127
+
128
+
2.**throws**: only thrift support, which specified what kind of exceptions can be thrown by the function. this keyword will be ignored, too, in thrift-to-pb mode.
129
+
130
+
3.**arguments**:
131
+
* thrift supports multiple arguments for one function, but protobuf only supports one, so it will ignore all the arguments other than the first one in thrift-to-pb transformation.
132
+
133
+
* thrift functions support `void` return type, but protobuf doesn't, so it will leave the return type blank in thrift-to-pb mode.
134
+
135
+
* currently, only support basic type and identifier for function/rpc request and response type, might be implemented in the future.
136
+
137
+
### Options || Annotation
138
+
Both language support this feature, but they have different syntax to apply it, since the meaning for them are language-bound, we decide to ignore this between transformations.
139
+
140
+
### Message || Struct
141
+
Thrift `struct` and protobuf `message` are very similar, but still have some differences:
142
+
143
+
1.**set type**: only thrift support, it will be transformed to `repeated` field in protobuf just like thrift `list`.
144
+
145
+
2.**optional**: thrift and proto2 support, it will be ignored in thrift-to-pb mode if protobuf syntax is proto3
146
+
147
+
3.**required**: thrift and proto2 support, since it's highly not recommend to mark field as `required`, currently it will be ignored, if you have any questions about this, please open an issue.
148
+
149
+
4.**map type**: as protobuf [language-specification](https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#map_field) mentioned, protobuf only support basic type as key type, but thrift support any [FieldType](https://thrift.apache.org/docs/idl.html) as map key type, for simplicity, currently only support basic type and identifier as map key and value
150
+
151
+
152
+
### Import || Include
153
+
As [language-specification](https://developers.google.com/protocol-buffers/docs/proto#importing_definitions) mentioned, protobuf import paths are relative to protoc command's working directory or using -I/--proto_path specified path, and can not include relative paths prefix, such as `./XXX.proto`, we are not able to detect the correct path for current file both in thrift-to-pb mode and pb-to-thrift mode, since it's dynamic.
154
+
155
+
So, you have to manually check whether the generated path is correct.
156
+
157
+
### Constant || Const
158
+
Currently not supported.
159
+
160
+
### Package || Namespace
161
+
Thrift `namespace` value will be used for protobuf `package`, the NamespaceScope will be ignored in thrift-to-pb mode.
162
+
163
+
In pb-to-thrift mode, generated `namespace` will use `*` as NamespaceScope.
164
+
165
+
### Nested Types
166
+
Protobuf supports [nested types](https://developers.google.com/protocol-buffers/docs/proto#nested) within message, but thrift does not, so protobuf-thrift will prefix nested field name with outer message name to work around this. for example:
0 commit comments