Skip to content

Commit f61843d

Browse files
committed
Add Claude instruction file for the codebase
1 parent 0222e07 commit f61843d

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a MessagePack implementation library for Zig, providing serialization and deserialization capabilities with full MessagePack specification support including timestamp extensions.
8+
9+
## Development Commands
10+
11+
### Build and Test
12+
```bash
13+
# Run all unit tests
14+
zig build test
15+
16+
# Run tests with detailed output
17+
zig build test --summary all
18+
19+
# Generate documentation
20+
zig build docs
21+
```
22+
23+
### Zig Version Compatibility
24+
- **Currently supports**: Zig 0.14.0 and 0.15.x
25+
- **Partial support**: Zig 0.16 (nightly) - may have compatibility issues
26+
- **Legacy support**: Zig 0.11-0.13 (use library version 0.0.6 for Zig 0.13 and older)
27+
- Code uses version detection (`builtin.zig_version.minor`) to handle API differences:
28+
- Endianness enum changes (`.Big`/`.Little` vs `.big`/`.little`)
29+
- ArrayList API changes in Zig 0.15+ (allocator parameter required for methods)
30+
- Build system API differences between versions
31+
32+
## Architecture
33+
34+
### Core Structure
35+
36+
The library consists of three main files:
37+
- `src/msgpack.zig`: Core implementation with Pack/Unpack functionality and Payload type system
38+
- `src/test.zig`: Comprehensive test suite
39+
- `build.zig`: Build configuration with version compatibility handling
40+
41+
### Key Components
42+
43+
**Payload Union Type**: Central data representation supporting all MessagePack types:
44+
- Basic types: nil, bool, int, uint, float
45+
- Container types: array, map
46+
- Binary types: str, bin, ext
47+
- Special type: timestamp (extension type -1)
48+
49+
**Pack Generic Function**: Template-based packer/unpacker that works with any Read/Write context:
50+
- Handles endianness conversion (MessagePack uses big-endian)
51+
- Supports streaming serialization/deserialization
52+
- Memory efficient with configurable allocators
53+
54+
**Type Wrappers**: Special wrapper types for structured data:
55+
- `Str`, `Bin`, `EXT`, `Timestamp` - provide type safety and convenience methods
56+
- `wrapStr()`, `wrapBin()`, `wrapEXT()` - helper functions for creating wrapped types
57+
58+
### MessagePack Format Implementation
59+
60+
The library implements the complete MessagePack specification:
61+
- Fixed-size formats for small integers and strings
62+
- Variable-size formats with size prefixes
63+
- Extension type system with timestamp support (type -1)
64+
- Proper handling of signed/unsigned integer boundaries
65+
66+
### Memory Management
67+
68+
- All dynamic allocations go through provided Allocator
69+
- Payload types that allocate memory must be freed with `payload.free(allocator)`
70+
- Container types (array, map) manage their child elements' memory
71+
72+
## Testing Approach
73+
74+
Tests use Zig's built-in testing framework. The test suite in `src/test.zig` covers:
75+
- All MessagePack type encodings/decodings
76+
- Edge cases and boundary conditions
77+
- Timestamp format variations (32-bit, 64-bit, 96-bit)
78+
- Round-trip serialization verification
79+
80+
## CI/CD
81+
82+
GitHub Actions workflow tests against multiple Zig versions (0.14.0, 0.15.1, nightly) to ensure compatibility.

0 commit comments

Comments
 (0)