1
1
const std = @import ("std" );
2
- const c = @import ("ffi.zig" );
2
+ const extism = @import ("ffi.zig" );
3
3
const Memory = @import ("Memory.zig" );
4
4
pub const http = @import ("http.zig" );
5
5
@@ -16,18 +16,18 @@ pub const Plugin = struct {
16
16
17
17
// IMPORTANT: It's the caller's responsibility to free the returned slice
18
18
pub fn getInput (self : Plugin ) ! []u8 {
19
- const len = c . extism_input_length ();
19
+ const len = extism . input_length ();
20
20
var buf = try self .allocator .alloc (u8 , @intCast (len ));
21
21
errdefer self .allocator .free (buf );
22
22
var i : usize = 0 ;
23
23
while (i < len ) {
24
24
if (len - i < 8 ) {
25
- buf [i ] = c . extism_input_load_u8 (@as (u64 , i ));
25
+ buf [i ] = extism . input_load_u8 (@as (u64 , i ));
26
26
i += 1 ;
27
27
continue ;
28
28
}
29
29
30
- const x = c . extism_input_load_u64 (@as (u64 , i ));
30
+ const x = extism . input_load_u64 (@as (u64 , i ));
31
31
std .mem .writeIntLittle (u64 , buf [i .. ][0.. 8], x );
32
32
i += 8 ;
33
33
}
@@ -36,25 +36,25 @@ pub const Plugin = struct {
36
36
37
37
pub fn outputMemory (self : Plugin , mem : Memory ) void {
38
38
_ = self ; // to make the interface consistent
39
- c . extism_output_set (mem .offset , mem .length );
39
+ extism . output_set (mem .offset , mem .length );
40
40
}
41
41
42
42
pub fn output (self : Plugin , data : []const u8 ) void {
43
43
_ = self ; // to make the interface consistent
44
44
const c_len = @as (u64 , data .len );
45
- const offset = c . extism_alloc (c_len );
45
+ const offset = extism . alloc (c_len );
46
46
const memory = Memory .init (offset , c_len );
47
47
defer memory .free ();
48
48
memory .store (data );
49
- c . extism_output_set (offset , c_len );
49
+ extism . output_set (offset , c_len );
50
50
}
51
51
52
52
/// IMPORTANT: it's the caller's responsibility to free the returned string
53
53
pub fn getConfig (self : Plugin , key : []const u8 ) ! ? []u8 {
54
54
const key_mem = Memory .allocateBytes (key );
55
55
defer key_mem .free ();
56
- const offset = c . extism_config_get (key_mem .offset );
57
- const c_len = c . extism_length (offset );
56
+ const offset = extism . config_get (key_mem .offset );
57
+ const c_len = extism . length (offset );
58
58
if (offset == 0 or c_len == 0 ) {
59
59
return null ;
60
60
}
@@ -69,10 +69,10 @@ pub const Plugin = struct {
69
69
pub fn logMemory (self : Plugin , level : LogLevel , memory : Memory ) void {
70
70
_ = self ; // to make the interface consistent
71
71
switch (level ) {
72
- .Info = > c . extism_log_info (memory .offset ),
73
- .Debug = > c . extism_log_debug (memory .offset ),
74
- .Warn = > c . extism_log_warn (memory .offset ),
75
- .Error = > c . extism_log_error (memory .offset ),
72
+ .Info = > extism . log_info (memory .offset ),
73
+ .Debug = > extism . log_debug (memory .offset ),
74
+ .Warn = > extism . log_warn (memory .offset ),
75
+ .Error = > extism . log_error (memory .offset ),
76
76
}
77
77
}
78
78
@@ -86,8 +86,8 @@ pub const Plugin = struct {
86
86
pub fn getVar (self : Plugin , key : []const u8 ) ! ? []u8 {
87
87
const key_mem = Memory .allocateBytes (key );
88
88
defer key_mem .free ();
89
- const offset = c . extism_var_get (key_mem .offset );
90
- const c_len = c . extism_length (offset );
89
+ const offset = extism . var_get (key_mem .offset );
90
+ const c_len = extism . length (offset );
91
91
if (offset == 0 or c_len == 0 ) {
92
92
return null ;
93
93
}
@@ -105,14 +105,14 @@ pub const Plugin = struct {
105
105
defer key_mem .free ();
106
106
const val_mem = Memory .allocateBytes (value );
107
107
defer val_mem .free ();
108
- c . extism_var_set (key_mem .offset , val_mem .offset );
108
+ extism . var_set (key_mem .offset , val_mem .offset );
109
109
}
110
110
111
111
pub fn removeVar (self : Plugin , key : []const u8 ) void {
112
112
_ = self ; // to make the interface consistent
113
113
const mem = Memory .allocateBytes (key );
114
114
defer mem .free ();
115
- c .extism_var_set (mem .offset , 0 );
115
+ extism .extism_var_set (mem .offset , 0 );
116
116
}
117
117
118
118
pub fn request (self : Plugin , http_request : http.HttpRequest , body : ? []const u8 ) ! http.HttpResponse {
@@ -128,9 +128,9 @@ pub const Plugin = struct {
128
128
}
129
129
};
130
130
defer req_body .free ();
131
- const offset = c . extism_http_request (req .offset , req_body .offset );
132
- const length = c . extism_length (offset );
133
- const status : u16 = @intCast (c . extism_http_status_code ());
131
+ const offset = extism . http_request (req .offset , req_body .offset );
132
+ const length = extism . length (offset );
133
+ const status : u16 = @intCast (extism . http_status_code ());
134
134
135
135
const mem = Memory .init (offset , length );
136
136
defer mem .free ();
0 commit comments