tiny.http.ResponseStorage
Defined in tiny.http.
API (12)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/http/src/response.zig:105
zig
pub const Storage = struct { phase: alloc_phase.capacity.Phase, capacity: StorageCapacity, bytes: []align(@alignOf(Header)) u8, pub const Limits: type = StorageLimits; pub const Capacity: type = StorageCapacity; pub const Exhaustion: type = StorageExhaustion; pub const InitError = std.mem.Allocator.Error || error{CapacityOverflow}; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "http.response_storage", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{ .{ .id = "fixed_response_header_entry_region_for_every_response_slot", .lifetime = .steady, .detail = "fixed response-header entry region for every response slot", }, .{ .id = "fixed_serialized_response_head_byte_region_for_ever_e148bf132b18", .lifetime = .steady, .detail = "fixed serialized response-head byte region for every response slot", }, }, .excluded = &.{ "borrowed or transferred response body bytes and release callbacks", "connection input, socket and kernel queues, clients, TLS, and protocol sessions", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput(StorageLimits, "response_count", "response_count"), alloc_phase.capacity.bindInput(StorageLimits, "header_count_per_response", "header_count_per_response"), alloc_phase.capacity.bindInput(StorageLimits, "head_bytes_per_response", "head_bytes_per_response"), }, .type_selectors = &.{ alloc_phase.capacity.bindType(Header, "header"), }, .nodes = &.{ .{ .input = 0 }, .{ .input = 1 }, .{ .product = .{ .left = 0, .right = 1 } }, .{ .constant = 1 }, .{ .scale = .{ .node = 3, .coefficient = .{ .size_of_concrete_type = 0 } } }, .{ .product = .{ .left = 2, .right = 4 } }, .{ .input = 2 }, .{ .product = .{ .left = 0, .right = 6 } }, .{ .add = .{ .left = 5, .right = 7 } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 8, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "header and serialized-head max plus one preserve prior storage", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "response mutation and serialization allocate no storage after activation", }, .foreign = .{ .status = .excluded, .detail = "serialization transforms borrowed values without performing I/O", }, }, .obligations = &.{ .{ .key = "http_response_capacity", .role = .capacity_model }, .{ .key = "http_response_oom_retry", .role = .custom }, .{ .key = "http_response_partition", .role = .custom }, .{ .key = "http_response_sealed", .role = .transitive_risk }, .{ .key = "http_response_atomic_overload", .role = .overload }, .{ .key = "http_response_atomic_foreign_risk", .role = .foreign_risk }, .{ .key = "http_response_boundary", .role = .custom }, .{ .key = "http_response_router", .role = .custom }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; pub fn init(allocator: std.mem.Allocator, limits: StorageLimits) InitError!Storage { const capacity = try StorageCapacity.derive(limits); const bytes = if (capacity.storage_bytes == 0) @as([]align(@alignOf(Header)) u8, &.{}) else try allocator.alignedAlloc(u8, .of(Header), capacity.storage_bytes); return .{ .phase = .initialization, .capacity = capacity, .bytes = bytes, }; } pub fn activate(self: *Storage) void { std.debug.assert(self.phase == .initialization); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .steady; } pub fn response(self: *Storage, index: usize) Exhaustion!Scratch { std.debug.assert(self.phase == .steady); if (index >= self.capacity.response_count) return error.ResponseCapacityExceeded; const all_headers = std.mem.bytesAsSlice( Header, self.bytes[0..self.capacity.header_bytes], ); const header_start = index * self.capacity.header_count_per_response; const head_start = self.capacity.header_bytes + index * self.capacity.head_bytes_per_response; return .{ .headers = all_headers[header_start..][0..self.capacity.header_count_per_response], .head = self.bytes[head_start..][0..self.capacity.head_bytes_per_response], }; } pub fn deinit(self: *Storage, allocator: std.mem.Allocator) void { std.debug.assert(self.phase != .teardown); std.debug.assert(self.bytes.len == self.capacity.storage_bytes); self.phase = .teardown; if (self.bytes.len != 0) allocator.free(self.bytes); self.bytes = &.{}; }};Source: lib/http/src/root.zig:53
zig
pub const ResponseStorage = response.Storage;Audit
| Definitions | 10 |
|---|---|
| Public names | 10 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |