Skip to content

Commit

Permalink
fix document about struct_pack::type_info_config
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Sep 15, 2023
1 parent 6b8b298 commit fbbf80f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions website/docs/en/struct_pack/struct_pack_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Current configurations are:
2. `ADD_TYPE_INFO`(1 bit). It is a flag indicating if type information is present
- 0 : full type information not present (0 in release mode)
- 1 : full type information present
You can also control it manually. See [link](https://alibaba.github.io/yalantinglibs/en/struct_pack/struct_pack_tips.html#type-check)

3. `LEN_SIZE` (2 bits). It records the maximum number of bytes of the containers.
- 00 : 1 byte (in range of uint8_t, 0~256)
Expand Down
5 changes: 4 additions & 1 deletion website/docs/en/struct_pack/struct_pack_tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ When C++20 standard was enabled, struct_pack has better performance by support m
4. define macro `STRUCT_PACK_OPTIMIZE`.
## Type Check
struct_pack will generate a name for the serialized type during compilation, and get a 32-bit MD5 based on the string, then take its upper 31 bits for type check. When deserializing, it will check whether the hash code stored is the same as the type to be deserialized.
In order to alleviate possible hash collisions, in debug mode, struct_pack will store the complete type name instead of hash code. Therefore, the binary size in debug mode is slightly larger than release.
In order to alleviate possible hash collisions, in debug mode, struct_pack will store the complete type name instead of hash code. Therefore, the binary size in debug mode is slightly larger than release. User can also enable it manually by add option `struct_pack::type_info_config::enable`:
```cpp
auto result=struct_pack::serialize<struct_pack::type_info_config::enable>(person);
```
## Type requires

1. The type to serialize should be legal struct_pack type.。See document:[struct_pack type system](https://alibaba.github.io/yalantinglibs/en/struct_pack/struct_pack_type_system.html)
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/struct_pack/struct_pack_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
从低位到高位,各设置分别为:

1. `DATA_SIZE`。共两比特。当包含compatible兼容字段时,反序列化时无法确定尾部的兼容字段有多长。为保证能够跳过这些未知字段,需要记录序列化结果的总长度。`01``10``11`代表数据总长度所占的字节数为:2字节,4字节,8字节。`00`代表不记录数据总长度,说明用户序列化的结构体中不包含compatible字段。
2. `ADD_TYPE_INFO`。 是否包含类型信息,共一比特。0代表不存在完整类型信息,1代表存在。struct_pack在debug模式下会默认包含元信息,release下不会包含,用户也可自行配置,详见:
2. `ADD_TYPE_INFO`。 是否包含类型信息,共一比特。0代表不存在完整类型信息,1代表存在。struct_pack在debug模式下会默认包含元信息,release下不会包含,用户也可自行配置,详见:[链接](https://alibaba.github.io/yalantinglibs/zh/struct_pack/struct_pack_tips.html#%E7%B1%BB%E5%9E%8B%E6%A0%A1%E9%AA%8C)
3. `LEN_SIZE`大小,共2bit。`00`,`01`,`10`,`11`分别对应的长度为:1字节,2字节,4字节,8字节。该大小是记录最长的容器的长度所需要的字节数。默认值为`00`,即长度小于256。
4. 剩余3bit保留,目前应该保持为`000`,有待后续扩展。

Expand Down
4 changes: 4 additions & 0 deletions website/docs/zh/struct_pack/struct_pack_tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ struct_pack需要你的编译器良好的支持C++17标准。
## 类型校验
struct_pack在编译期会根据被序列化的对象的类型生成类型字符串,并根据该字符串生成一个32位的MD5并取其高31位作为类型校验码。反序列化时会检查校验码是否和待反序列化的类型相同。
为了缓解可能出现的哈希冲突,在debug模式下,struct_pack会存储完整的类型字符串。因此debug模式下生成的二进制体积比release略大。
用户也可以通过`struct_pack::type_info_config::enable`手动控制是否启动类型字符串。
```cpp
auto result=struct_pack::serialize<struct_pack::type_info_config::enable>(person);
```
## 类型约束

1. 序列化的类型必须是struct_pack类型系统中的合法类型。详见:struct_pack的类型系统。See document:[struct_pack 类型系统](https://alibaba.github.io/yalantinglibs/zh/struct_pack/struct_pack_type_system.html)
Expand Down

0 comments on commit fbbf80f

Please sign in to comment.