|
1 | 1 | # Zigpak |
2 | 2 |
|
3 | | -Messagepack implementation for Zig. |
| 3 | +Messagepack for Zig. |
4 | 4 |
|
5 | | -Supported Zig 0.12 & 0.13 |
| 5 | +- [API References (latest release)](https://zigpak.pages.dev/zigpak/) |
| 6 | +- [API References (master)](https://master.zigpak.pages.dev/zigpak/) |
6 | 7 |
|
7 | | -## Usage |
| 8 | +Supported: |
8 | 9 |
|
9 | | -Include this package and use the module "zigpak". This module include two sub fields: |
| 10 | +- Zig 0.12 (best effort) |
| 11 | +- Zig 0.13 |
| 12 | +- Zig 0.14 (the master branch) |
10 | 13 |
|
11 | | -- `zigpak.fmt` - The tools to emit messagepack values directly |
12 | | -- `zigpak.io` - Utilities to work with `std.io.Reader` and `std.io.Writer`. |
| 14 | +## Use In Your Project |
13 | 15 |
|
14 | | -`zigpak.fmt` has two kinds of writing functions and two kinds of reading functions: |
| 16 | +Use a tarball link with `zig fetch --save`. You can find it in the "Tags" page. Some versions of zig can only fetch "tar.gz" file, so you may prefer this type. |
15 | 17 |
|
16 | | -- `prefix*` emits the prefixing of the value. Usually the values are no need to be transformed and can be written directly. |
17 | | -- `write*` accepts a value and writes into a buffer. The function name suffixed with `Sm` means this function uses run-time branching to reduce result size as possible. |
| 18 | +```sh |
| 19 | +zig fetch --save https://link-to-tarball |
| 20 | +``` |
18 | 21 |
|
19 | | -- `readValue` and `.next` in `Value.LazyArray` and `Value.LazyMap` reads a value and returns in a dynamic-typed favour. |
20 | | -- `.nextOf` in `Value.LazyArray` and `Value.LazyMap` accepts a specific type and generate code to read only the specific type. This may reduce run-time branching and affect performance. |
| 22 | +Assume the saved name is the default "zigpak". In the build script, refer the "zigpak" module in it. |
| 23 | + |
| 24 | +```zig |
| 25 | +// build.zig |
| 26 | +
|
| 27 | +pub fn build(b: *std.Build) void { |
| 28 | + // ... |
| 29 | + const exe: *std.Build.Compile; |
| 30 | +
|
| 31 | + const zigpak = b.dependency("zigpak", .{ |
| 32 | + .target = target, |
| 33 | + .optimize = optimize, |
| 34 | + }).module("zigpak"); |
| 35 | +
|
| 36 | + exe.root_module.addImport("zigpak", zigpak); |
| 37 | +} |
| 38 | +``` |
21 | 39 |
|
22 | 40 | ## License |
23 | 41 |
|
24 | 42 | Apache-2.0 |
25 | | - |
|
0 commit comments