mirror of
https://github.com/tars-node/tars2node.git
synced 2024-03-22 13:10:56 +08:00
Merge pull request #6 from danielzheng-Tencent/patch-2
Update README.md
This commit is contained in:
commit
17850d361a
86
README.md
86
README.md
|
@ -1,65 +1,65 @@
|
||||||
# Tars2Node
|
# Tars2Node
|
||||||
|
|
||||||
`tars2node` 可以将 Tars IDL 定义文件转换为 JavaScript 语言所使用的版本,结合 [@tars/stream](https://www.npmjs.com/package/@tars/stream) 模块执行编解码操作。
|
`tars2node` can convert the Tars IDL definition file to the version used by the JavaScript language, combined with the [@ tars / stream] (https://www.npmjs.com/package/@tars/stream) module to perform codec operations.
|
||||||
|
|
||||||
如您有 Tars RPC 需求可结合 [@tars/rpc](https://www.npmjs.com/package/@tars/rpc) 模块进行调用。
|
If you have Tars RPC requirements, you can call it in conjunction with the [@ tars / rpc] (https://www.npmjs.com/package/@tars/rpc) module.
|
||||||
|
|
||||||
## 用法
|
## Usage
|
||||||
|
|
||||||
直接使用 build 目录中的 `tars2node` 预编译程序即可(Linux 平台)。
|
Just use the `tars2node` precompiler in the build directory (Linux platform).
|
||||||
|
|
||||||
```bash
|
`` `bash
|
||||||
tars2node [OPTIONS] tarsfile
|
tars2node [OPTIONS] tarsfile
|
||||||
```
|
`` `
|
||||||
|
|
||||||
## 选项
|
## options
|
||||||
|
|
||||||
| 选项 | 作用 |
|
Options | Functions |
|
||||||
| ------------- | ------------- |
|
| ------------- | ------------- |
|
||||||
| --stream-path=[DIRECTORY] | 指定编解码模块名称,默认为 @tars/stream。 |
|
| --stream-path = [DIRECTORY] | Specify the codec module name, the default is @ tars / stream. |
|
||||||
| --rpc-path=[DIRECTORY] | 指定 RPC 模块名称,默认为 @tars/rpc。 |
|
| --rpc-path = [DIRECTORY] | Specify the RPC module name. The default is @ tars / rpc. |
|
||||||
| --allow-reserved-namespace | 是否允许 `tars` 作为命名空间(因为此命名空间主要用于框架服务的 tars 文件定义)。 |
|
| --allow-reserved-namespace | Whether to allow `tars` as a namespace (because this namespace is mainly used for tars file definitions for framework services). |
|
||||||
| --dir=[DIRECTORY] | 生成文件的输出目录。 |
|
| --dir = [DIRECTORY] | Output directory for generated files. |
|
||||||
| --relative | 限定所有的 `.tars` 文件都在当前目录寻找。|
|
| --relative | Limits all `.tars` files to look in the current directory. |
|
||||||
| --tarsBase=[DIRECTORY] | 指定 `.tars` 文件的搜索目录。|
|
| --tarsBase = [DIRECTORY] | Specify the search directory for `.tars` files. |
|
||||||
| --r | 转换嵌套的 `.tars` 文件。|
|
| --r | Convert nested `.tars` files. |
|
||||||
| --r-minimal | 精简依赖文件,移除非必须成员。|
|
| --r-minimal | Reduce dependent files and remove unnecessary members. |
|
||||||
| --r-reserved | 精简依赖文件时需保留的成员。|
|
| --r-reserved | Members to keep when thinning dependent files. |
|
||||||
| --client | 生成客户端的调用类代码。|
|
| --client | Generate the calling class code for the client. |
|
||||||
| --server | 生成服务端的框架代码。|
|
| --server | Generate server-side framework code. |
|
||||||
| --ts | 打开此选项将后将只生成 TypeScript (.ts) 代码。|
|
| --ts | Turning on this option will only generate TypeScript (.ts) code. |
|
||||||
| --dts | 生成时附加 TypeScript 描述文件(.d.ts)。|
|
| --dts | Append a TypeScript description file (.d.ts) when generating. |
|
||||||
| --long-type=[number|string|bigint] | 可选择使用 \<Number\|String\|BigInt\> 表达 \<long\> 类型,默认值为 \<Number\>。|
|
| --long-type = [number | string | bigint] | Optionally use \ <Number \ | String \ | BigInt \> to express the \ <long \> type, with a default value of \ <Number \>. |
|
||||||
| --string-binary-encoding | 遇到字符编码问题或需对原始数据进行存取时,打开此选项使用 \<buffer\> 存储 \<string\>。|
|
| --string-binary-encoding | When you encounter character encoding problems or need to access the original data, turn on this option to use \ <buffer \> to store \ <string \>. |
|
||||||
| --enum-reverse-mappings | 输出代码 \<enum\> 支持枚举值到枚举名的反向映射 。|
|
| --enum-reverse-mappings | Output code \ <enum \> supports reverse mapping of enum values to enum names. |
|
||||||
| --optimize=[0\|s] | 优化输出代码大小,默认为 0(也就是不优化)。|
|
| --optimize = [0 \ | s] | Optimize the output code size. The default is 0 (that is, not optimized). |
|
||||||
|
|
||||||
## 例子
|
## Examples
|
||||||
|
|
||||||
```bash
|
`` `bash
|
||||||
tars2node Protocol.tars
|
tars2node Protocol.tars
|
||||||
```
|
`` `
|
||||||
|
|
||||||
上述命令将转换 `Protocol.tars` 文件中定义的 `常量`、`枚举`、`结构体` 等数据类型生成 `ProtocolTars.js` 供编解码使用。
|
The above command will convert the constants, enumerations, and structures defined in the Protocol.tars file to generate ProtocolTars.js for encoding and decoding.
|
||||||
使用方法请参考 [@tars/stream](https://www.npmjs.com/package/@tars/stream) 模块说明文档。
|
For usage, please refer to the [@ tars / stream] (https://www.npmjs.com/package/@tars/stream) module documentation.
|
||||||
|
|
||||||
```bash
|
`` `bash
|
||||||
tars2node Protocol.tars --client
|
tars2node Protocol.tars --client
|
||||||
```
|
`` `
|
||||||
|
|
||||||
上述命令将转换文件中定义的 `常量`、`枚举值`、`结构体` 等数据类型,并将 `interface` 描述段转换为 Tars RPC 客户端接口文件,最终生成 `ProtocolProxy.js` 供调用方使用。
|
The above command will convert the data types such as `constant`,` enumeration value`, `structure` defined in the file, and convert the` interface` description section into a Tars RPC client interface file, and finally generate `ProtocolProxy.js` for Used by the caller.
|
||||||
使用方法请参考 [@tars/rpc](https://www.npmjs.com/package/@tars/rpc) 模块说明文档。
|
For usage, please refer to [@ tars / rpc] (https://www.npmjs.com/package/@tars/rpc) module documentation.
|
||||||
|
|
||||||
```bash
|
`` `bash
|
||||||
tars2node Protocol.tars --server
|
tars2node Protocol.tars --server
|
||||||
```
|
`` `
|
||||||
|
|
||||||
上述命令将转换文件中定义的 `常量`、`枚举值`、`结构体` 等数据类型,并将 `interface` 描述段转换为 Tars RPC 服务端接口文件,最终生成 `Protocol.js` 以及 `ProtocolImp.js` 供服务提供方使用。
|
The above command will convert data types such as `constant`,` enumeration value`, `struct` defined in the file, and convert the` interface` description section into a Tars RPC server interface file, and finally generate `Protocol.js` and `ProtocolImp.js` is used by the service provider.
|
||||||
开发者无需改动 `Protocol.js`,只需要继续完善 `ProtocolImp.js` 实现文件中具体的函数,即可作为 Tars RPC 服务端提供服务。
|
Developers do not need to change `Protocol.js`, they only need to continue to improve the specific functions in the` ProtocolImp.js` implementation file to provide services as Tars RPC server.
|
||||||
使用方法请参考 [@tars/rpc](https://www.npmjs.com/package/@tars/rpc) 模块说明文档。
|
For usage, please refer to [@ tars / rpc] (https://www.npmjs.com/package/@tars/rpc) module documentation.
|
||||||
|
|
||||||
## 从源码编译
|
## Compile from source
|
||||||
|
|
||||||
1. 安装对应平台的 build-essential
|
1. Install build-essential for the corresponding platform
|
||||||
2. 安装 [CMake](https://cmake.org/)
|
2. Install [CMake] (https://cmake.org/)
|
||||||
3. 在源码 build 目录下执行 `cmake ../ && make`
|
3. Execute `cmake ../ && make` in the source build directory
|
||||||
|
|
Loading…
Reference in New Issue
Block a user