Skip to content

Commit 5e0c70e

Browse files
committed
feat(zig-compat): enhance cross-version support for Zig 0.16
- add compatibility layer for `std.io.FixedBufferStream` removal - update README and README_CN with Zig 0.16 compatibility notes - modify example code to use cross-version buffer stream implementation - export compatibility module in main msgpack module - update test imports to use new compatibility layer
1 parent 0b417fc commit 5e0c70e

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ An article introducing it: [Zig Msgpack](https://blog.nvimer.org/2025/09/20/zig-
2323
| 0.13 and older | 0.0.6 | Legacy support |
2424
| 0.14.0 | Current | ✅ Fully supported |
2525
| 0.15.x | Current | ✅ Fully supported |
26-
| 0.16.0-dev (nightly) | Current | ✅ Fully supported |
26+
| 0.16.0-dev (nightly) | Current | ⚠️ Supported with compatibility layer |
2727

2828
> **Note:** For Zig 0.13 and older versions, please use version `0.0.6` of this library.
29+
> **Note:** Zig 0.16+ removes `std.io.FixedBufferStream`, but this library provides a compatibility layer to maintain the same API across all supported versions.
2930
3031
For Zig `0.14.0`, `0.15.x`, and `0.16.0-dev`, follow these steps:
3132

@@ -75,13 +76,18 @@ const msgpack = @import("msgpack");
7576
pub fn main() !void {
7677
const allocator = std.heap.page_allocator;
7778
var buffer: [1024]u8 = undefined;
78-
var stream = std.io.fixedBufferStream(&buffer);
79+
80+
// Use the compatibility layer for cross-version support
81+
const compat = msgpack.compat;
82+
var write_buffer = compat.fixedBufferStream(&buffer);
83+
var read_buffer = compat.fixedBufferStream(&buffer);
7984
85+
const BufferType = compat.BufferStream;
8086
var packer = msgpack.Pack(
81-
*std.io.FixedBufferStream([]u8), *std.io.FixedBufferStream([]u8),
82-
std.io.FixedBufferStream([]u8).WriteError, std.io.FixedBufferStream([]u8).ReadError,
83-
std.io.FixedBufferStream([]u8).write, std.io.FixedBufferStream([]u8).read,
84-
).init(&stream, &stream);
87+
*BufferType, *BufferType,
88+
BufferType.WriteError, BufferType.ReadError,
89+
BufferType.write, BufferType.read,
90+
).init(&write_buffer, &read_buffer);
8591
8692
// Create and encode data
8793
var map = msgpack.Payload.mapPayload(allocator);
@@ -91,7 +97,7 @@ pub fn main() !void {
9197
try packer.write(map);
9298
9399
// Decode
94-
stream.pos = 0;
100+
read_buffer.pos = 0;
95101
const decoded = try packer.read(allocator);
96102
defer decoded.free(allocator);
97103
@@ -133,7 +139,7 @@ const ts2 = msgpack.Payload.timestampToPayload(1234567890, 123456789);
133139
134140
// Write and read timestamp
135141
try packer.write(ts2);
136-
stream.pos = 0;
142+
read_buffer.pos = 0;
137143
const decoded_ts = try packer.read(allocator);
138144
defer decoded_ts.free(allocator);
139145
@@ -179,6 +185,17 @@ To run the unit tests for this library, use the following command:
179185
180186
```sh
181187
zig build test
188+
189+
# For more detailed test output
190+
zig build test --summary all
191+
```
192+
193+
## Documentation
194+
195+
To generate documentation for this library:
196+
197+
```sh
198+
zig build docs
182199
```
183200
184201
## Contributing

README_CN.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Zig 编程语言的 MessagePack 实现。此库提供了一种简单高效的方
2323
| 0.13 及更早版本 | 0.0.6 | 旧版支持 |
2424
| 0.14.0 | 当前版本 | ✅ 完全支持 |
2525
| 0.15.x | 当前版本 | ✅ 完全支持 |
26-
| 0.16.0-dev (nightly) | 当前版本 | ✅ 完全支持 |
26+
| 0.16.0-dev (nightly) | 当前版本 | ⚠️ 通过兼容层支持 |
2727

2828
> **注意**: 对于 Zig 0.13 及更早版本,请使用本库的 `0.0.6` 版本。
29+
> **注意**: Zig 0.16+ 移除了 `std.io.FixedBufferStream`,但本库提供了兼容层以在所有支持的版本中维持相同的 API。
2930
3031
对于 Zig `0.14.0``0.15.x``0.16.0-dev` 版本,请按以下步骤操作:
3132

@@ -75,13 +76,18 @@ const msgpack = @import("msgpack");
7576
pub fn main() !void {
7677
const allocator = std.heap.page_allocator;
7778
var buffer: [1024]u8 = undefined;
78-
var stream = std.io.fixedBufferStream(&buffer);
79+
80+
// 使用兼容层实现跨版本支持
81+
const compat = msgpack.compat;
82+
var write_buffer = compat.fixedBufferStream(&buffer);
83+
var read_buffer = compat.fixedBufferStream(&buffer);
7984
85+
const BufferType = compat.BufferStream;
8086
var packer = msgpack.Pack(
81-
*std.io.FixedBufferStream([]u8), *std.io.FixedBufferStream([]u8),
82-
std.io.FixedBufferStream([]u8).WriteError, std.io.FixedBufferStream([]u8).ReadError,
83-
std.io.FixedBufferStream([]u8).write, std.io.FixedBufferStream([]u8).read,
84-
).init(&stream, &stream);
87+
*BufferType, *BufferType,
88+
BufferType.WriteError, BufferType.ReadError,
89+
BufferType.write, BufferType.read,
90+
).init(&write_buffer, &read_buffer);
8591
8692
// 创建和编码数据
8793
var map = msgpack.Payload.mapPayload(allocator);
@@ -91,7 +97,7 @@ pub fn main() !void {
9197
try packer.write(map);
9298
9399
// 解码
94-
stream.pos = 0;
100+
read_buffer.pos = 0;
95101
const decoded = try packer.read(allocator);
96102
defer decoded.free(allocator);
97103
@@ -133,7 +139,7 @@ const ts2 = msgpack.Payload.timestampToPayload(1234567890, 123456789);
133139
134140
// 写入和读取时间戳
135141
try packer.write(ts2);
136-
stream.pos = 0;
142+
read_buffer.pos = 0;
137143
const decoded_ts = try packer.read(allocator);
138144
defer decoded_ts.free(allocator);
139145
@@ -179,6 +185,17 @@ const uint_result = int_payload.getUint() catch |err| switch (err) {
179185

180186
```sh
181187
zig build test
188+
189+
# 获取更详细的测试输出
190+
zig build test --summary all
191+
```
192+
193+
## 文档
194+
195+
要生成此库的文档:
196+
197+
```sh
198+
zig build docs
182199
```
183200

184201
## 贡献

src/msgpack.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,3 +1691,6 @@ pub fn Pack(
16911691
}
16921692
};
16931693
}
1694+
1695+
// Export compatibility layer for cross-version support
1696+
pub const compat = @import("compat.zig");

src/test.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
33
const msgpack = @import("msgpack");
4-
const compat = @import("compat.zig");
4+
const compat = msgpack.compat;
55
const allocator = std.testing.allocator;
66
const expect = std.testing.expect;
77
const Payload = msgpack.Payload;

0 commit comments

Comments
 (0)