1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// GENERATED: re-run the analytics schema generator (peechy) with .rs output
// source: src/analytics/schema.zig
// TODO(port): regenerate remaining analytics::* types for Rust
use Error;
// ──────────────────────────────────────────────────────────────────────────
// Reader / Writer
// ──────────────────────────────────────────────────────────────────────────
//
// Zig's peechy codec exposes a concrete `Reader` struct and a comptime-generic
// `Writer(WritableStream)` struct, but every generated `decode`/`encode` takes
// `reader: anytype` / `writer: anytype` — i.e. structural duck typing. Per
// PORTING.md §Comptime reflection, `anytype` → trait bound: the *protocol* is
// the trait, and the Zig `Reader` struct is one concrete impl (`BufReader`
// below).
//
// Only the primitive-int / byte-slice surface is ported. Zig's
// `readValue(comptime T)` / `writeValue(comptime T, ...)` switch on
// `@typeInfo(T)` to dispatch to enum/packed-struct/`.decode` paths; that
// reflection has no Rust equivalent, so per-type `decode`/`encode` impls call
// the primitive methods directly (which is what the generated schema bodies
// already do).
/// Zig: `Reader.ReadError = error{EOF}`.
// PORT NOTE: peechy's two error cases (`EOF`, `InvalidValue`) are folded into
// the crate-wide `bun_core::Error` so downstream `decode` signatures stay
// `Result<_, bun_core::Error>` without an extra `From` hop.
pub const EOF: Error = TODO; // TODO(port): Error::from_name("EOF") once name→code table lands
/// Primitive integers encodable in the peechy wire format (native-endian raw
/// bytes). Zig handled this via `comptime T` + `std.mem.readIntSliceNative` /
/// `std.mem.asBytes`; Rust needs an explicit trait bound.
pub use NativeEndianInt as SchemaInt;
/// Duck-typed reader protocol for peechy `decode` impls.
///
/// Zig: `fn decode(reader: anytype) anyerror!T` — the `anytype` becomes a
/// `R: Reader` bound on the Rust side.
// peechy `Writer` lives in `bun_options_types::schema::Writer` (the canonical
// `Vec<u8>`-backed struct port of `schema.zig:169 fn Writer(WritableStream)`).
// This crate keeps only the read side; encode users depend on options_types
// directly.
/// Concrete buffer-backed reader — direct port of Zig's `pub const Reader = struct`.
///
/// PORT NOTE: the Zig struct also carries `std.mem.Allocator param` for
/// `readArray`'s nested-slice case; per PORTING.md §Allocators (non-AST crate)
/// the allocator param is dropped — callers that need owned sub-arrays
/// allocate at the call site.
// ──────────────────────────────────────────────────────────────────────────
// Hand-ported subset of `analytics::*` needed by lib.rs (OperatingSystem,
// Architecture, Platform). The full encode/decode machinery and the rest of
// the schema (EventKind, EventListHeader, …) are unused at runtime today and
// will be filled in by the peechy regen.
// ported from: src/analytics/schema.zig