Referencia Zigconduit-zig (SDK consumido)

zig/wire.zig

Declaraciones públicas de zig/wire.zig (conduit-zig (SDK consumido)).

ImplementadoSin versión del tren todavía· generada desde apps/docs/generated/zig/conduit.json

Página generada desde conduit@conduit-0.1.0-f7J_7zg5DwCsHBHItwdOz9ZVq8cvH7ceFsk7-m3-T61t (zig/root.zig). No se edita a mano: bun run docs:gen la regenera y bun run docs:check falla si difiere.

conduit wire v1 — the single codec shared by the client and the server.

Normative text: spec/wire-v1.md. Conformance: spec/vectors/wire-v1.json (run by wire_vectors_test.zig here and by @mks2508/chunk-engine in TS).

Everything here parses input that crosses a trust boundary (styx dec-0117 B4/I5): every length and offset is bounds-checked with overflow-checked arithmetic, nothing unreachables on input, errors are typed. The module is freestanding-clean (no OS calls): it also builds for wasm32.

wire.version

const · línea 15

pub const version: u32 = 1

Sin ///.

wire.max_safe_integer

const · línea 17

pub const max_safe_integer: u64 = (1 << 53) - 1

JSON integers must fit a JavaScript number exactly (Number.MAX_SAFE_INTEGER).

wire.max_request_json

const · línea 19

pub const max_request_json: usize = 4096

Request JSON bodies over this size are rejected before parsing.

wire.default_base

const · línea 20

pub const default_base = "/api/upload"

Sin ///.

wire.max_filename_len

const · línea 21

pub const max_filename_len = 255

Sin ///.

wire.Digest

const · línea 23

pub const Digest = [Sha256.digest_length]u8

Sin ///.

wire.hex_digest_len

const · línea 24

pub const hex_digest_len = 64

Sin ///.

wire.content_digest_len

const · línea 26

pub const content_digest_len = 9 + 44 + 1

sha-256=: + 44 base64 chars + :.

wire.max_content_range_len

const · línea 28

pub const max_content_range_len = 6 + 16 + 1 + 16 + 1 + 16

bytes + 3 × 16 digits + - + /.

wire.ErrorCode

type · línea 33

pub const ErrorCode = enum

Wire error codes (spec §5). The tag name is the JSON error string.

wire.ErrorCode.httpStatus

fn · línea 58

pub fn httpStatus(c: ErrorCode) u16

Sin ///.

wire.ErrorCode.retryable

fn · línea 73

pub fn retryable(c: ErrorCode) bool

Sin ///.

wire.ErrorCode.fromName

fn · línea 80

pub fn fromName(name: []const u8) ?ErrorCode

Sin ///.

wire.ErrorCode.retryableStatus

fn · línea 86

pub fn retryableStatus(status: u16) bool

Classification of a response whose code this client does not know: 5xx and 429 retry, everything else is final (spec §5).

wire.ParseError

const · línea 91

pub const ParseError = error{Invalid}

Sin ///.

wire.UploadId

type · línea 95

pub const UploadId = struct

Sin ///.

wire.UploadId.min_len

const · línea 96

pub const min_len = 8

Sin ///.

wire.UploadId.max_len

const · línea 97

pub const max_len = 64

Sin ///.

wire.UploadId.parse

fn · línea 102

pub fn parse(s: []const u8) ParseError!UploadId

Sin ///.

wire.UploadId.slice

fn · línea 114

pub fn slice(self: *const UploadId) []const u8

Sin ///.

wire.UploadId.eql

fn · línea 118

pub fn eql(a: *const UploadId, b: *const UploadId) bool

Sin ///.

wire.parseDecimal

fn · línea 128

pub fn parseDecimal(s: []const u8, max_digits: usize) ParseError!u64

Strict unsigned decimal: no sign, no leading zeros, at most max_digits.

wire.parseIndex

fn · línea 141

pub fn parseIndex(s: []const u8) ParseError!u32

Chunk index from a path segment (spec §3).

wire.validateFilename

fn · línea 147

pub fn validateFilename(name: []const u8) ParseError!void

Filename rules (spec §3). The name is metadata; it is never a path.

wire.Range

type · línea 158

pub const Range = struct

Sin ///.

wire.Range.end

fn · línea 163

pub fn end(r: Range) u64

Inclusive end (Content-Range). Only valid for len > 0.

wire.PlanError

const · línea 168

pub const PlanError = error{ InvalidSize, InvalidChunkSize, TooManyChunks }

Sin ///.

wire.Plan

type · línea 172

pub const Plan = struct

totalChunks = ceil(size / chunkSize); chunk i covers [i·chunkSize, min((i+1)·chunkSize, size)) (spec §6.1).

wire.Plan.init

fn · línea 177

pub fn init(total_size: u64, chunk_size: u64, max_chunks: u32) PlanError!Plan

Sin ///.

wire.Plan.chunk

fn · línea 187

pub fn chunk(p: Plan, index: u32) ?Range

null if index is not a chunk of this plan.

wire.ContentRange

type · línea 197

pub const ContentRange = struct

Sin ///.

wire.ContentRange.parse

fn · línea 204

pub fn parse(s: []const u8) ParseError!ContentRange

Strict bytes <start>-<end>/<total> (spec §4.2): no spaces, no *, no leading zeros, start ≤ end < total ≤ 2^53−1.

wire.ContentRange.ofChunk

fn · línea 218

pub fn ofChunk(p: Plan, index: u32) ?ContentRange

Sin ///.

wire.ContentRange.format

fn · línea 223

pub fn format(cr: ContentRange, buf: *[max_content_range_len]u8) []const u8

Sin ///.

wire.ContentRange.eql

fn · línea 227

pub fn eql(a: ContentRange, b: ContentRange) bool

Sin ///.

wire.parseContentDigest

fn · línea 237

pub fn parseContentDigest(s: []const u8) ParseError!Digest

RFC 9530 Content-Digest with exactly one sha-256 member.

wire.formatContentDigest

fn · línea 253

pub fn formatContentDigest(d: Digest, buf: *[content_digest_len]u8) []const u8

Sin ///.

wire.hexDigest

fn · línea 260

pub fn hexDigest(d: Digest) [hex_digest_len]u8

Sin ///.

wire.parseHexDigest

fn · línea 265

pub fn parseHexDigest(s: []const u8) ParseError!Digest

Lowercase hex only (spec §4.1).

wire.Method

type · línea 275

pub const Method = enum

Sin ///.

wire.Route

type · línea 277

pub const Route = union

Sin ///.

wire.RouteError

const · línea 285

pub const RouteError = error{ NotFound, BadRequest }

Sin ///.

wire.route

fn · línea 290

pub fn route(base: []const u8, method: Method, path: []const u8) RouteError!Route

Resolve path (raw request target) under base (spec §4). Routing is by method and segment count; ids and indices are validated here, so nothing downstream ever sees an unvalidated path component.

wire.max_path_len

const · línea 324

pub const max_path_len = 1 + 8 + 1 + UploadId.max_len + 1 + 10

Sin ///.

wire.formatPath

fn · línea 327

pub fn formatPath(r: Route, buf: *[max_path_len]u8) []const u8

Path of r relative to the base (e.g. /chunk/<id>/3).

wire.bearerToken

fn · línea 340

pub fn bearerToken(header: ?[]const u8) ?[]const u8

Token of an Authorization: Bearer <token> header; null for anything else (spec §2: missing, other scheme or empty ⇒ 401).

wire.CreateRequest

type · línea 351

pub const CreateRequest = struct

Sin ///.

wire.SessionResponse

type · línea 358

pub const SessionResponse = struct

Sin ///.

wire.ChunkResponse

type · línea 367

pub const ChunkResponse = struct

Sin ///.

wire.SessionStatus

type · línea 373

pub const SessionStatus = enum

Sin ///.

wire.StatusResponse

type · línea 375

pub const StatusResponse = struct

Sin ///.

wire.CompleteResponse

type · línea 384

pub const CompleteResponse = struct

Sin ///.

wire.ErrorBody

type · línea 391

pub const ErrorBody = struct

Sin ///.

wire.DecodeError

const · línea 396

pub const DecodeError = error{ Invalid, OutOfMemory }

Sin ///.

wire.parseValue

fn · línea 400

pub fn parseValue(arena: std.mem.Allocator, bytes: []const u8) DecodeError!std.json.ObjectMap

Sin ///.

wire.getInt

fn · línea 415

pub fn getInt(o: std.json.ObjectMap, key: []const u8) ParseError!u64

Sin ///.

wire.getOptInt

fn · línea 419

pub fn getOptInt(o: std.json.ObjectMap, key: []const u8) ParseError!?u64

Sin ///.

wire.intOf

fn · línea 424

pub fn intOf(v: Value) ParseError!u64

Sin ///.

wire.getString

fn · línea 434

pub fn getString(o: std.json.ObjectMap, key: []const u8) ParseError![]const u8

Sin ///.

wire.getOptString

fn · línea 441

pub fn getOptString(o: std.json.ObjectMap, key: []const u8) ParseError!?[]const u8

Sin ///.

wire.decodeCreateRequest

fn · línea 450

pub fn decodeCreateRequest(arena: std.mem.Allocator, bytes: []const u8) DecodeError!CreateRequest

Server side: POST {base}/session body. Strings in the result point into arena.

wire.decodeCreateObject

fn · línea 457

pub fn decodeCreateObject(o: std.json.ObjectMap) ParseError!CreateRequest

decodeCreateRequest on an already parsed body (wire v2 parses once and dispatches on protocol).

wire.decodeCompleteRequest

fn · línea 472

pub fn decodeCompleteRequest(arena: std.mem.Allocator, bytes: []const u8) DecodeError!?Digest

Server side: optional POST {base}/complete/{id} body {"sha256":…}. Empty body ⇒ null.

wire.decodeSessionResponse

fn · línea 480

pub fn decodeSessionResponse(arena: std.mem.Allocator, bytes: []const u8) DecodeError!SessionResponse

Sin ///.

wire.decodeChunkResponse

fn · línea 500

pub fn decodeChunkResponse(arena: std.mem.Allocator, bytes: []const u8) DecodeError!ChunkResponse

Sin ///.

wire.decodeStatusResponse

fn · línea 509

pub fn decodeStatusResponse(arena: std.mem.Allocator, bytes: []const u8) DecodeError!StatusResponse

Sin ///.

wire.decodeCompleteResponse

fn · línea 536

pub fn decodeCompleteResponse(arena: std.mem.Allocator, bytes: []const u8) DecodeError!CompleteResponse

Sin ///.

wire.decodeErrorBody

fn · línea 548

pub fn decodeErrorBody(arena: std.mem.Allocator, bytes: []const u8) ErrorBody

Error bodies are best-effort: an unparseable body still has a status.

wire.encodeCreateRequest

fn · línea 561

pub fn encodeCreateRequest(w: *Writer, r: CreateRequest) Writer.Error!void

Sin ///.

wire.encodeCompleteRequest

fn · línea 569

pub fn encodeCompleteRequest(w: *Writer, root_digest: Digest) Writer.Error!void

Sin ///.

wire.encodeSessionResponse

fn · línea 573

pub fn encodeSessionResponse(w: *Writer, r: SessionResponse) Writer.Error!void

Sin ///.

wire.encodeChunkResponse

fn · línea 584

pub fn encodeChunkResponse(w: *Writer, r: ChunkResponse) Writer.Error!void

Sin ///.

wire.encodeStatusResponse

fn · línea 590

pub fn encodeStatusResponse(w: *Writer, r: StatusResponse) Writer.Error!void

Sin ///.

wire.encodeCompleteResponse

fn · línea 601

pub fn encodeCompleteResponse(w: *Writer, r: CompleteResponse) Writer.Error!void

Sin ///.

wire.encodeAbortResponse

fn · línea 609

pub fn encodeAbortResponse(w: *Writer, id: UploadId) Writer.Error!void

Sin ///.

wire.encodeError

fn · línea 615

pub fn encodeError(w: *Writer, code: ErrorCode, message: []const u8) Writer.Error!void

Sin ///.

wire.formatRfc3339

fn · línea 622

pub fn formatRfc3339(unix_seconds: u64, buf: *[20]u8) []const u8

RFC 3339 UTC (2026-09-29T10:00:00Z) of a Unix time in seconds.

wire.sha256

fn · línea 632

pub fn sha256(bytes: []const u8) Digest

Sin ///.

wire.backoffMs

fn · línea 640

pub fn backoffMs(attempt: u32) u32

Exponential backoff for retry attempt (1-based): 250 ms · 2^(n−1), capped at 10 s. Hosts add jitter.