Skip to content

Commit e381ce9

Browse files
committed
docs: add prutal docs
1 parent 5662e62 commit e381ce9

File tree

4 files changed

+119
-5
lines changed

4 files changed

+119
-5
lines changed

content/en/blog/releases/Kitex/release-v0_13_0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ description: >
1515
v0.12.0 released the StreamX interface to optimise the streaming experience, and supported the custom streaming protocol TTHeader Streaming, but did not support gRPC. So stock users could not migrate.
1616
This version supports gRPC for StreamX, users can migrate to StreamX, and the Server side can be compatible with two streaming protocols at the same time. So there is no need to worry about protocol compatibility after interface migration.
1717
In particular, when adapting gRPC with StreamX, we found that there are still some inconvenient problems. In order to bring a better experience of using the interface, we have adjusted the StreamX interface for the second time, which will affect the users who have already been using StreamX. We apologise for that.
18-
User documentation: Kitex StreamX - 基础流编程 | Stream Basic Programming
18+
User documentation: [StreamX User Documentation](/en/docs/kitex/tutorials/basic-feature/streamx)
1919
2. Prutal - Protobuf's non-generated code serialisation library
2020
Prutal is officially open source (https://github.com/cloudwego/prutal), on par with Thrift's Frugal library, and the new version of Kitex integrates Prutal by default.
2121
Advantages:
2222
- Minimized Code Product Size: Generating Only Structures, No Runtime Code
2323
- Leveraging Reflection Optimization Similar to Frugal, Achieving Over 50% Speed Increase
2424
- Generating Code Compatible with Existing Protobuf and Derivative Versions
25-
User documentation: Kitex 集成 Prutal 说明
25+
User documentation: [Prutal](/en/docs/kitex/tutorials/code-gen/prutal)
2626

2727
### **Feature/Experience Optimization**
2828
1. **TTHeader Streaming**: Support interface-level Recv timeout control
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "Prutal"
3+
date: 2025-04-09
4+
weight: 11
5+
keywords: ["Prutal"]
6+
description: "Protobuf's non-generated code serialisation library"
7+
---
8+
9+
## **Abstraction**
10+
Starting from v0.13.0, kitex will use its own prutal implementation to replace Protobuf's protoc and protoc-gen-go for code generation and serialisation.
11+
kitex will no longer need to install protoc, protoc-gen-go. New users will not be aware of the change.
12+
prutal is compatible with the existing protobuf in terms of serialisation, and generates code that is very compact, has no extra code, and has better serialisation performance than the official one.
13+
Technically prutal and frugal similar to the use of struct tags and efficient reflection to achieve serialisation , and does not rely on redundant generation code .
14+
Currently open source, the specific implementation and subsequent benchmark data can be concerned: https://github.com/cloudwego/prutal
15+
16+
## **Using Advices**
17+
Initially, it is not recommended that users use prutal directly, and currently only promises forward and backward compatibility with prutal integration in kitex.
18+
If you find any problems while using kitex, you can fallback to protobuf using the environment variable KITEX_TOOL_USE_PROTOC
19+
```KITEX_TOOL_USE_PROTOC=1 kitex --version```.
20+
In the long run, kitex will deprecate the protoc implementation. It is recommended that if you encounter problems with usage, you can provide feedback to help improve it.
21+
22+
## **Kitex Tool Updates**
23+
Since protoc is no longer used as the default code generation tool, the following arguments will be deprecated:
24+
--protobuf
25+
--protobuf-plugin
26+
These two arguments are mainly used for passthrough to protoc, and are not actually used by kitex itself. If they are still specified, an error will be reported:
27+
```
28+
[ERROR] invalid value ‘xxx’ for flag -protobuf: flag is deprecated
29+
[ERROR] invalid value ‘xxx’ for flag -protobuf-plugin: flag is deprecated
30+
```
31+
Users can call protoc and related plugins for code generation if they want. Instead of relying on kitex to call protoc.
32+
33+
Due to the complexity of generating paths in older protoc implementations, the following arguments do not work in older implementations:
34+
-gen-path
35+
which defaults to kitex_gen, has been fixed in the new Prutal.
36+
37+
## **Prutal and Protobuf compatibility issues**
38+
kitex uses prutal to generate code by default.
39+
If the user does Marshal / Unmarshal directly from the protobuf library, the new kitex will generate code with a compile-time error:
40+
```cannot use &YourRequest{} (value of type *YourRequest) as protoreflect.ProtoMessage value in argument to proto.Marshal: *YourRequest does not implement protoreflect.ProtoMessage (missing method ProtoReflect) ```
41+
This is because the protobuf library is strongly bound to the protobuf generation code, and protobuf needs to generate a lot of binary data to assist its reflection implementation.
42+
43+
It is recommended to use the github.com/cloudwego/prutal package directly.
44+
```
45+
// MarshalAppend appends the protobuf encoding of v to b and returns the new bytes
46+
func MarshalAppend(b []byte, v interface{}) ([]byte, error)
47+
48+
// Unmarshal parses the protobuf-encoded data and stores the result in the value pointed to by v.
49+
func Unmarshal(b []byte, v interface{}) error
50+
``
51+
52+
prutal is compatible with protobuf generated code. So even if the original code was generated by the official protobuf, you can use prutal to serialise it for better performance.
53+
Since protobuf is complex and has a lot of features, prutal can't guarantee 100% compatibility, so if you find any problems, please feel free to comment.
54+
55+
## **Feedback to us**
56+
If you have any questions, you can submit an issue to prutal for feedback.
57+
https://github.com/cloudwego/prutal/issues

content/zh/blog/releases/Kitex/release-v0_13_0.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ description: >
1616
v0.13.0 对 StreamX 支持 gRPC 后,用户可迁移至 StreamX 新接口,Server 端可以同时兼容两个流式协议,无需担心接口迁移后的协议兼容性问题。
1717
特别地,StreamX 在适配 gRPC 时,发现依然有一些不便利的问题,为带来更好的接口使用体验,因此对 StreamX 接口做了二次调整。
1818
已经使用 v0.12.* StreamX 用户会带来影响,在这里表示抱歉。
19-
详见
19+
详见 [StreamX 用户文档](/zh/docs/kitex/tutorials/basic-feature/streamx)
2020
2. Prutal - Protobuf 的无生成代码序列化库
21-
Prutal 正式开源https://github.com/cloudwego/prutal,对标 Thrift 的 Frugal 库,新版本 Kitex 默认集成 Prutal。特点:
21+
Prutal 正式开源 (https://github.com/cloudwego/prutal),对标 Thrift 的 Frugal 库,新版本 Kitex 默认集成 Prutal。特点:
2222
- 产物体积最小化,只需生成结构体
2323
- 使用与 Frugal 相似的反射优化,性能优于官方 Protobuf
2424
- 兼容官方 Protobuf 及衍生版本的生成代码
25-
详见 Kitex - 集成 Prutal 说明
25+
详细信息参考 [Prutal](/zh/docs/kitex/tutorials/code-gen/prutal)
2626

2727
### **功能/体验优化**
2828
1. TTHeader Streaming 支持配置接口级别 Recv 超时
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: "Prutal"
3+
date: 2025-04-09
4+
weight: 11
5+
keywords: ["Prutal"]
6+
description: "Protobuf 的无生成代码序列化库"
7+
---
8+
9+
## **概要**
10+
kitex 从 v0.13.0 版本开始将使用自研的 prutal 实现用于替换 Protobuf 的 protoc 、protoc-gen-go 来生成代码、序列化。
11+
kitex 将不再需要安装 protoc 、protoc-gen-go 。对于新的用户并不会感知相应的变化。
12+
prutal 在序列化上兼容现有的 protobuf,并且生成代码十分精简、没有多余的代码,并且在序列化性能优于官方。
13+
技术上 prutal 与 frugal 类似,借助 struct tag 还有高效的反射实现序列化,并不依赖冗余的生成代码。
14+
当前已经开源,具体实现还有后续的 benchmark 数据可以关注: https://github.com/cloudwego/prutal
15+
16+
## **使用建议**
17+
初期并不建议用户直接使用 prutal,当前只会承诺通过 kitex 里 prutal 集成的向前和向后兼容性。
18+
如果在使用 kitex 过程,发现任何问题,可以使用环境变量 KITEX_TOOL_USE_PROTOC 回退到 protobuf
19+
```KITEX_TOOL_USE_PROTOC=1 kitex --version```
20+
长期来看,kitex 将废弃 protoc 的实现。建议遇到使用上的问题,可以反馈以帮助改进。
21+
22+
## **Kitex Tool 变更**
23+
由于不再使用 protoc 作为默认的代码生成工具,以下的参数将废弃:
24+
- --protobuf
25+
- --protobuf-plugin
26+
这两个参数主要用于直接透传参数到 protoc,kitex 自身并没有实际在使用。如果仍指定使用,将会报错:
27+
```
28+
[ERROR] invalid value "xxx" for flag -protobuf: flag is deprecated
29+
[ERROR] invalid value "xxx" for flag -protobuf-plugin: flag is deprecated
30+
```
31+
如果用户有需求,可以自行调用 protoc 以及相关的插件进行代码生成。而不是依赖 kitex 去调用 protoc。
32+
33+
由于旧的protoc 实现的生成路径问题比较复杂,在老的实现中,以下参数并不生效:
34+
- -gen-path
35+
其默认值只能为 kitex_gen,在新的 Prutal 中,修复了这问题。
36+
37+
## **Prutal 与 Protobuf 兼容性问题**
38+
由于 kitex 默认使用 prutal 进行生成代码,
39+
如果用户直接通过 protobuf 的库 进行 Marshal / Unmarshal 新 kitex 的生成代码将会在编译期发生错误:
40+
```cannot use &YourRequest{} (value of type *YourRequest) as protoreflect.ProtoMessage value in argument to proto.Marshal: *YourRequest does not implement protoreflect.ProtoMessage (missing method ProtoReflect)```
41+
这是因为 protobuf 库与 protobuf 的生成代码是强绑定的,protobuf 需要生成大量的二进制数据以协助其反射的实现。
42+
43+
建议直接使用 github.com/cloudwego/prutal 包
44+
```
45+
// MarshalAppend appends the protobuf encoding of v to b and returns the new bytes
46+
func MarshalAppend(b []byte, v interface{}) ([]byte, error)
47+
48+
// Unmarshal parses the protobuf-encoded data and stores the result in the value pointed to by v.
49+
func Unmarshal(b []byte, v interface{}) error
50+
```
51+
52+
prutal 兼容 protobuf 的生成代码。因此哪怕原本的代码是官方 protobuf 生成的,都可以使用 prutal 来序列化,以获取更好的性能。
53+
由于 protobuf实现上比较复杂,功能十分丰富。prutal 很难保证 100% 的功能都可以兼容,如果发现任何问题,欢迎反馈。
54+
55+
## **问题反馈**
56+
有任何问题均可以向 prutal 提 issue 进行反馈。
57+
https://github.com/cloudwego/prutal/issues

0 commit comments

Comments
 (0)