1 /++
2 + Machine generated D bindings for Sokol library.
3 + 
4 +     Generated on: 2025-06-01 10:38:03
5 + 
6 +     Source header: sokol_fetch.h
7 +     Module: sokol.fetch
8 + 
9 +     Do not edit manually; regenerate using gen_d.py.
10 +/
11 module sokol.fetch;
12 
13 enum LogItem {
14     Ok,
15     Malloc_failed,
16     File_path_utf8_decoding_failed,
17     Send_queue_full,
18     Request_channel_index_too_big,
19     Request_path_is_null,
20     Request_path_too_long,
21     Request_callback_missing,
22     Request_chunk_size_greater_buffer_size,
23     Request_userdata_ptr_is_set_but_userdata_size_is_null,
24     Request_userdata_ptr_is_null_but_userdata_size_is_not,
25     Request_userdata_size_too_big,
26     Clamping_num_channels_to_max_channels,
27     Request_pool_exhausted,
28 }
29 /++
30 + sfetch_logger_t
31 + 
32 +     Used in sfetch_desc_t to provide a custom logging and error reporting
33 +     callback to sokol-fetch.
34 +/
35 extern(C) struct Logger {
36     extern(C) void function(const(char)*, uint, uint, const(char)*, uint, const(char)*, void*) func = null;
37     void* user_data = null;
38 }
39 /++
40 + sfetch_range_t
41 + 
42 +     A pointer-size pair struct to pass memory ranges into and out of sokol-fetch.
43 +     When initialized from a value type (array or struct) you can use the
44 +     SFETCH_RANGE() helper macro to build an sfetch_range_t struct.
45 +/
46 extern(C) struct Range {
47     const(void)* ptr = null;
48     size_t size = 0;
49 }
50 /++
51 + sfetch_allocator_t
52 + 
53 +     Used in sfetch_desc_t to provide custom memory-alloc and -free functions
54 +     to sokol_fetch.h. If memory management should be overridden, both the
55 +     alloc and free function must be provided (e.g. it's not valid to
56 +     override one function but not the other).
57 +/
58 extern(C) struct Allocator {
59     extern(C) void* function(size_t, void*) alloc_fn = null;
60     extern(C) void function(void*, void*) free_fn = null;
61     void* user_data = null;
62 }
63 /++
64 + configuration values for sfetch_setup()
65 +/
66 extern(C) struct Desc {
67     uint max_requests = 0;
68     uint num_channels = 0;
69     uint num_lanes = 0;
70     Allocator allocator = {};
71     Logger logger = {};
72 }
73 /++
74 + a request handle to identify an active fetch request, returned by sfetch_send()
75 +/
76 extern(C) struct Handle {
77     uint id = 0;
78 }
79 /++
80 + error codes
81 +/
82 enum Error {
83     No_error,
84     File_not_found,
85     No_buffer,
86     Buffer_too_small,
87     Unexpected_eof,
88     Invalid_http_status,
89     Cancelled,
90     Js_other,
91 }
92 /++
93 + the response struct passed to the response callback
94 +/
95 extern(C) struct Response {
96     Handle handle = {};
97     bool dispatched = false;
98     bool fetched = false;
99     bool paused = false;
100     bool finished = false;
101     bool failed = false;
102     bool cancelled = false;
103     Error error_code = Error.No_error;
104     uint channel = 0;
105     uint lane = 0;
106     const(char)* path = null;
107     void* user_data = null;
108     uint data_offset = 0;
109     Range data = {};
110     Range buffer = {};
111 }
112 /++
113 + request parameters passed to sfetch_send()
114 +/
115 extern(C) struct Request {
116     uint channel = 0;
117     const(char)* path = null;
118     extern(C) void function(const Response*) callback = null;
119     uint chunk_size = 0;
120     Range buffer = {};
121     Range user_data = {};
122 }
123 /++
124 + setup sokol-fetch (can be called on multiple threads)
125 +/
126 extern(C) void sfetch_setup(const Desc* desc) @system @nogc nothrow pure;
127 void setup(scope ref Desc desc) @trusted @nogc nothrow pure {
128     sfetch_setup(&desc);
129 }
130 /++
131 + discard a sokol-fetch context
132 +/
133 extern(C) void sfetch_shutdown() @system @nogc nothrow pure;
134 void shutdown() @trusted @nogc nothrow pure {
135     sfetch_shutdown();
136 }
137 /++
138 + return true if sokol-fetch has been setup
139 +/
140 extern(C) bool sfetch_valid() @system @nogc nothrow pure;
141 bool valid() @trusted @nogc nothrow pure {
142     return sfetch_valid();
143 }
144 /++
145 + get the desc struct that was passed to sfetch_setup()
146 +/
147 extern(C) Desc sfetch_desc() @system @nogc nothrow pure;
148 Desc desc() @trusted @nogc nothrow pure {
149     return sfetch_desc();
150 }
151 /++
152 + return the max userdata size in number of bytes (SFETCH_MAX_USERDATA_UINT64 * sizeof(uint64_t))
153 +/
154 extern(C) int sfetch_max_userdata_bytes() @system @nogc nothrow pure;
155 int maxUserdataBytes() @trusted @nogc nothrow pure {
156     return sfetch_max_userdata_bytes();
157 }
158 /++
159 + return the value of the SFETCH_MAX_PATH implementation config value
160 +/
161 extern(C) int sfetch_max_path() @system @nogc nothrow pure;
162 int maxPath() @trusted @nogc nothrow pure {
163     return sfetch_max_path();
164 }
165 /++
166 + send a fetch-request, get handle to request back
167 +/
168 extern(C) Handle sfetch_send(const Request* request) @system @nogc nothrow pure;
169 Handle send(scope ref Request request) @trusted @nogc nothrow pure {
170     return sfetch_send(&request);
171 }
172 /++
173 + return true if a handle is valid *and* the request is alive
174 +/
175 extern(C) bool sfetch_handle_valid(Handle h) @system @nogc nothrow pure;
176 bool handleValid(Handle h) @trusted @nogc nothrow pure {
177     return sfetch_handle_valid(h);
178 }
179 /++
180 + do per-frame work, moves requests into and out of IO threads, and invokes response-callbacks
181 +/
182 extern(C) void sfetch_dowork() @system @nogc nothrow pure;
183 void dowork() @trusted @nogc nothrow pure {
184     sfetch_dowork();
185 }
186 /++
187 + bind a data buffer to a request (request must not currently have a buffer bound, must be called from response callback
188 +/
189 extern(C) void sfetch_bind_buffer(Handle h, Range buffer) @system @nogc nothrow pure;
190 void bindBuffer(Handle h, Range buffer) @trusted @nogc nothrow pure {
191     sfetch_bind_buffer(h, buffer);
192 }
193 /++
194 + clear the 'buffer binding' of a request, returns previous buffer pointer (can be 0), must be called from response callback
195 +/
196 extern(C) void* sfetch_unbind_buffer(Handle h) @system @nogc nothrow pure;
197 void* unbindBuffer(Handle h) @trusted @nogc nothrow pure {
198     return sfetch_unbind_buffer(h);
199 }
200 /++
201 + cancel a request that's in flight (will call response callback with .cancelled + .finished)
202 +/
203 extern(C) void sfetch_cancel(Handle h) @system @nogc nothrow pure;
204 void cancel(Handle h) @trusted @nogc nothrow pure {
205     sfetch_cancel(h);
206 }
207 /++
208 + pause a request (will call response callback each frame with .paused)
209 +/
210 extern(C) void sfetch_pause(Handle h) @system @nogc nothrow pure;
211 void pause(Handle h) @trusted @nogc nothrow pure {
212     sfetch_pause(h);
213 }
214 /++
215 + continue a paused request
216 +/
217 extern(C) void sfetch_continue(Handle h) @system @nogc nothrow pure;
218 void continueFetching(Handle h) @trusted @nogc nothrow pure {
219     sfetch_continue(h);
220 }