kiwi-macro 0.1.1-alpha.4

Macros for the Kiwi SDK
Documentation
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
// Generated by `wit-bindgen` 0.17.0. DO NOT EDIT!
pub type Context = kiwi::kiwi::intercept_types::Context;
pub type Action = kiwi::kiwi::intercept_types::Action;
const _: () = {
    #[doc(hidden)]
    #[export_name = "intercept"]
    #[allow(non_snake_case)]
    unsafe extern "C" fn __export_intercept(arg0: i32) -> i32 {
        #[allow(unused_imports)]
        use ::kiwi_sdk::wit_bindgen::rt::{alloc, string::String, vec::Vec};

        // Before executing any other code, use this function to run all static
        // constructors, if they have not yet been run. This is a hack required
        // to work around wasi-libc ctors calling import functions to initialize
        // the environment.
        //
        // This functionality will be removed once rust 1.69.0 is stable, at which
        // point wasi-libc will no longer have this behavior.
        //
        // See
        // https://github.com/bytecodealliance/preview2-prototyping/issues/99
        // for more details.
        #[cfg(target_arch = "wasm32")]
        ::kiwi_sdk::wit_bindgen::rt::run_ctors_once();

        let l0 = i32::from(*((arg0 + 0) as *const u8));
        let l4 = i32::from(*((arg0 + 12) as *const u8));
        use kiwi::kiwi::intercept_types::ConnectionCtx as V9;
        let v9 = match l4 {
            n => {
                debug_assert_eq!(n, 0, "invalid enum discriminant");
                let e9 = {
                    let l5 = i32::from(*((arg0 + 16) as *const u8));

                    kiwi::kiwi::intercept_types::Websocket {
                        addr: match l5 {
                            0 => None,
                            1 => {
                                let e = {
                                    let l6 = *((arg0 + 20) as *const i32);
                                    let l7 = *((arg0 + 24) as *const i32);
                                    let len8 = l7 as usize;
                                    let bytes8 = Vec::from_raw_parts(l6 as *mut _, len8, len8);

                                    ::kiwi_sdk::wit_bindgen::rt::string_lift(bytes8)
                                };
                                Some(e)
                            }
                            _ => ::kiwi_sdk::wit_bindgen::rt::invalid_enum_discriminant(),
                        },
                    }
                };
                V9::Websocket(e9)
            }
        };
        let l10 = i32::from(*((arg0 + 32) as *const u8));
        use kiwi::kiwi::intercept_types::EventCtx as V29;
        let v29 = match l10 {
            0 => {
                let e29 = {
                    let l11 = i32::from(*((arg0 + 40) as *const u8));
                    let l15 = *((arg0 + 52) as *const i32);
                    let l16 = *((arg0 + 56) as *const i32);
                    let len17 = l16 as usize;
                    let bytes17 = Vec::from_raw_parts(l15 as *mut _, len17, len17);
                    let l18 = *((arg0 + 60) as *const i32);
                    let l19 = *((arg0 + 64) as *const i32);
                    let len20 = l19 as usize;
                    let bytes20 = Vec::from_raw_parts(l18 as *mut _, len20, len20);
                    let l21 = i32::from(*((arg0 + 72) as *const u8));
                    let l23 = *((arg0 + 88) as *const i32);
                    let l24 = *((arg0 + 96) as *const i64);

                    kiwi::kiwi::intercept_types::KafkaEventCtx {
                        payload: match l11 {
                            0 => None,
                            1 => {
                                let e = {
                                    let l12 = *((arg0 + 44) as *const i32);
                                    let l13 = *((arg0 + 48) as *const i32);
                                    let len14 = l13 as usize;

                                    Vec::from_raw_parts(l12 as *mut _, len14, len14)
                                };
                                Some(e)
                            }
                            _ => ::kiwi_sdk::wit_bindgen::rt::invalid_enum_discriminant(),
                        },
                        source_id: ::kiwi_sdk::wit_bindgen::rt::string_lift(bytes17),
                        topic: ::kiwi_sdk::wit_bindgen::rt::string_lift(bytes20),
                        timestamp: match l21 {
                            0 => None,
                            1 => {
                                let e = {
                                    let l22 = *((arg0 + 80) as *const i64);

                                    l22 as u64
                                };
                                Some(e)
                            }
                            _ => ::kiwi_sdk::wit_bindgen::rt::invalid_enum_discriminant(),
                        },
                        partition: l23 as u32,
                        offset: l24 as u64,
                    }
                };
                V29::Kafka(e29)
            }
            n => {
                debug_assert_eq!(n, 1, "invalid enum discriminant");
                let e29 = {
                    let l25 = *((arg0 + 40) as *const i32);
                    let l26 = *((arg0 + 44) as *const i32);
                    let len27 = l26 as usize;
                    let bytes27 = Vec::from_raw_parts(l25 as *mut _, len27, len27);
                    let l28 = *((arg0 + 48) as *const i64);

                    kiwi::kiwi::intercept_types::CounterEventCtx {
                        source_id: ::kiwi_sdk::wit_bindgen::rt::string_lift(bytes27),
                        count: l28 as u64,
                    }
                };
                V29::Counter(e29)
            }
        };
        let result30 = <_GuestImpl as Guest>::intercept(kiwi::kiwi::intercept_types::Context {
            auth: match l0 {
                0 => None,
                1 => {
                    let e = {
                        let l1 = *((arg0 + 4) as *const i32);
                        let l2 = *((arg0 + 8) as *const i32);
                        let len3 = l2 as usize;

                        Vec::from_raw_parts(l1 as *mut _, len3, len3)
                    };
                    Some(e)
                }
                _ => ::kiwi_sdk::wit_bindgen::rt::invalid_enum_discriminant(),
            },
            connection: v9,
            event: v29,
        });
        ::kiwi_sdk::wit_bindgen::rt::dealloc(arg0, 104, 8);
        let ptr31 = _RET_AREA.0.as_mut_ptr() as i32;
        use kiwi::kiwi::intercept_types::Action as V34;
        match result30 {
            V34::Forward => {
                *((ptr31 + 0) as *mut u8) = (0i32) as u8;
            }
            V34::Discard => {
                *((ptr31 + 0) as *mut u8) = (1i32) as u8;
            }
            V34::Transform(e) => {
                *((ptr31 + 0) as *mut u8) = (2i32) as u8;
                use kiwi::kiwi::intercept_types::TransformedPayload as V33;
                match e {
                    V33::Kafka(e) => {
                        *((ptr31 + 8) as *mut u8) = (0i32) as u8;
                        match e {
                            Some(e) => {
                                *((ptr31 + 16) as *mut u8) = (1i32) as u8;
                                let vec32 = (e).into_boxed_slice();
                                let ptr32 = vec32.as_ptr() as i32;
                                let len32 = vec32.len() as i32;
                                ::core::mem::forget(vec32);
                                *((ptr31 + 24) as *mut i32) = len32;
                                *((ptr31 + 20) as *mut i32) = ptr32;
                            }
                            None => {
                                *((ptr31 + 16) as *mut u8) = (0i32) as u8;
                            }
                        };
                    }
                    V33::Counter(e) => {
                        *((ptr31 + 8) as *mut u8) = (1i32) as u8;
                        *((ptr31 + 16) as *mut i64) = ::kiwi_sdk::wit_bindgen::rt::as_i64(e);
                    }
                }
            }
        }
        ptr31
    }

    const _: () = {
        #[doc(hidden)]
        #[export_name = "cabi_post_intercept"]
        #[allow(non_snake_case)]
        unsafe extern "C" fn __post_return_intercept(arg0: i32) {
            let l0 = i32::from(*((arg0 + 0) as *const u8));
            match l0 {
                0 => (),
                1 => (),
                _ => {
                    let l1 = i32::from(*((arg0 + 8) as *const u8));
                    match l1 {
                        0 => {
                            let l2 = i32::from(*((arg0 + 16) as *const u8));
                            match l2 {
                                0 => (),
                                _ => {
                                    let l3 = *((arg0 + 20) as *const i32);
                                    let l4 = *((arg0 + 24) as *const i32);
                                    let base5 = l3;
                                    let len5 = l4;
                                    ::kiwi_sdk::wit_bindgen::rt::dealloc(
                                        base5,
                                        (len5 as usize) * 1,
                                        1,
                                    );
                                }
                            }
                        }
                        _ => (),
                    }
                }
            }
        }
    };
};
use Kiwi as _GuestImpl;
pub trait Guest {
    fn intercept(ctx: Context) -> Action;
}

#[allow(unused_imports)]
use ::kiwi_sdk::wit_bindgen::rt::{alloc, string::String, vec::Vec};

#[repr(align(8))]
struct _RetArea([u8; 32]);
static mut _RET_AREA: _RetArea = _RetArea([0; 32]);
pub mod kiwi {
    pub mod kiwi {

        #[allow(clippy::all)]
        pub mod intercept_types {
            #[used]
            #[doc(hidden)]
            #[cfg(target_arch = "wasm32")]
            static __FORCE_SECTION_REF: fn() = super::super::super::__link_section;
            #[derive(Clone)]
            pub struct CounterEventCtx {
                pub source_id: ::kiwi_sdk::wit_bindgen::rt::string::String,
                pub count: u64,
            }
            impl ::core::fmt::Debug for CounterEventCtx {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    f.debug_struct("CounterEventCtx")
                        .field("source-id", &self.source_id)
                        .field("count", &self.count)
                        .finish()
                }
            }
            #[derive(Clone)]
            pub struct KafkaEventCtx {
                pub payload: Option<::kiwi_sdk::wit_bindgen::rt::vec::Vec<u8>>,
                pub source_id: ::kiwi_sdk::wit_bindgen::rt::string::String,
                pub topic: ::kiwi_sdk::wit_bindgen::rt::string::String,
                pub timestamp: Option<u64>,
                pub partition: u32,
                pub offset: u64,
            }
            impl ::core::fmt::Debug for KafkaEventCtx {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    f.debug_struct("KafkaEventCtx")
                        .field("payload", &self.payload)
                        .field("source-id", &self.source_id)
                        .field("topic", &self.topic)
                        .field("timestamp", &self.timestamp)
                        .field("partition", &self.partition)
                        .field("offset", &self.offset)
                        .finish()
                }
            }
            #[derive(Clone)]
            pub enum EventCtx {
                Kafka(KafkaEventCtx),
                Counter(CounterEventCtx),
            }
            impl ::core::fmt::Debug for EventCtx {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    match self {
                        EventCtx::Kafka(e) => f.debug_tuple("EventCtx::Kafka").field(e).finish(),
                        EventCtx::Counter(e) => {
                            f.debug_tuple("EventCtx::Counter").field(e).finish()
                        }
                    }
                }
            }
            #[derive(Clone)]
            pub struct Websocket {
                pub addr: Option<::kiwi_sdk::wit_bindgen::rt::string::String>,
            }
            impl ::core::fmt::Debug for Websocket {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    f.debug_struct("Websocket")
                        .field("addr", &self.addr)
                        .finish()
                }
            }
            #[derive(Clone)]
            pub enum ConnectionCtx {
                Websocket(Websocket),
            }
            impl ::core::fmt::Debug for ConnectionCtx {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    match self {
                        ConnectionCtx::Websocket(e) => {
                            f.debug_tuple("ConnectionCtx::Websocket").field(e).finish()
                        }
                    }
                }
            }
            /// Plugin context
            #[derive(Clone)]
            pub struct Context {
                pub auth: Option<::kiwi_sdk::wit_bindgen::rt::vec::Vec<u8>>,
                pub connection: ConnectionCtx,
                pub event: EventCtx,
            }
            impl ::core::fmt::Debug for Context {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    f.debug_struct("Context")
                        .field("auth", &self.auth)
                        .field("connection", &self.connection)
                        .field("event", &self.event)
                        .finish()
                }
            }
            #[derive(Clone)]
            pub enum TransformedPayload {
                Kafka(Option<::kiwi_sdk::wit_bindgen::rt::vec::Vec<u8>>),
                Counter(u64),
            }
            impl ::core::fmt::Debug for TransformedPayload {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    match self {
                        TransformedPayload::Kafka(e) => {
                            f.debug_tuple("TransformedPayload::Kafka").field(e).finish()
                        }
                        TransformedPayload::Counter(e) => f
                            .debug_tuple("TransformedPayload::Counter")
                            .field(e)
                            .finish(),
                    }
                }
            }
            #[derive(Clone)]
            pub enum Action {
                Forward,
                Discard,
                Transform(TransformedPayload),
            }
            impl ::core::fmt::Debug for Action {
                fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                    match self {
                        Action::Forward => f.debug_tuple("Action::Forward").finish(),
                        Action::Discard => f.debug_tuple("Action::Discard").finish(),
                        Action::Transform(e) => {
                            f.debug_tuple("Action::Transform").field(e).finish()
                        }
                    }
                }
            }
        }
    }
}

#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:intercept-hook"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 656] = [
    0, 97, 115, 109, 13, 0, 1, 0, 0, 25, 22, 119, 105, 116, 45, 99, 111, 109, 112, 111, 110, 101,
    110, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 4, 0, 7, 140, 4, 1, 65, 2, 1, 65, 8, 1,
    66, 20, 1, 114, 2, 9, 115, 111, 117, 114, 99, 101, 45, 105, 100, 115, 5, 99, 111, 117, 110,
    116, 119, 4, 0, 17, 99, 111, 117, 110, 116, 101, 114, 45, 101, 118, 101, 110, 116, 45, 99, 116,
    120, 3, 0, 0, 1, 112, 125, 1, 107, 2, 1, 107, 119, 1, 114, 6, 7, 112, 97, 121, 108, 111, 97,
    100, 3, 9, 115, 111, 117, 114, 99, 101, 45, 105, 100, 115, 5, 116, 111, 112, 105, 99, 115, 9,
    116, 105, 109, 101, 115, 116, 97, 109, 112, 4, 9, 112, 97, 114, 116, 105, 116, 105, 111, 110,
    121, 6, 111, 102, 102, 115, 101, 116, 119, 4, 0, 15, 107, 97, 102, 107, 97, 45, 101, 118, 101,
    110, 116, 45, 99, 116, 120, 3, 0, 5, 1, 113, 2, 5, 107, 97, 102, 107, 97, 1, 6, 0, 7, 99, 111,
    117, 110, 116, 101, 114, 1, 1, 0, 4, 0, 9, 101, 118, 101, 110, 116, 45, 99, 116, 120, 3, 0, 7,
    1, 107, 115, 1, 114, 1, 4, 97, 100, 100, 114, 9, 4, 0, 9, 119, 101, 98, 115, 111, 99, 107, 101,
    116, 3, 0, 10, 1, 113, 1, 9, 119, 101, 98, 115, 111, 99, 107, 101, 116, 1, 11, 0, 4, 0, 14, 99,
    111, 110, 110, 101, 99, 116, 105, 111, 110, 45, 99, 116, 120, 3, 0, 12, 1, 114, 3, 4, 97, 117,
    116, 104, 3, 10, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 13, 5, 101, 118, 101, 110,
    116, 8, 4, 0, 7, 99, 111, 110, 116, 101, 120, 116, 3, 0, 14, 1, 113, 2, 5, 107, 97, 102, 107,
    97, 1, 3, 0, 7, 99, 111, 117, 110, 116, 101, 114, 1, 119, 0, 4, 0, 19, 116, 114, 97, 110, 115,
    102, 111, 114, 109, 101, 100, 45, 112, 97, 121, 108, 111, 97, 100, 3, 0, 16, 1, 113, 3, 7, 102,
    111, 114, 119, 97, 114, 100, 0, 0, 7, 100, 105, 115, 99, 97, 114, 100, 0, 0, 9, 116, 114, 97,
    110, 115, 102, 111, 114, 109, 1, 17, 0, 4, 0, 6, 97, 99, 116, 105, 111, 110, 3, 0, 18, 3, 1,
    31, 107, 105, 119, 105, 58, 107, 105, 119, 105, 47, 105, 110, 116, 101, 114, 99, 101, 112, 116,
    45, 116, 121, 112, 101, 115, 64, 48, 46, 49, 46, 48, 5, 0, 2, 3, 0, 0, 7, 99, 111, 110, 116,
    101, 120, 116, 3, 0, 7, 99, 111, 110, 116, 101, 120, 116, 3, 0, 1, 2, 3, 0, 0, 6, 97, 99, 116,
    105, 111, 110, 3, 0, 6, 97, 99, 116, 105, 111, 110, 3, 0, 3, 1, 64, 1, 3, 99, 116, 120, 2, 0,
    4, 4, 0, 9, 105, 110, 116, 101, 114, 99, 101, 112, 116, 1, 5, 4, 1, 30, 107, 105, 119, 105, 58,
    107, 105, 119, 105, 47, 105, 110, 116, 101, 114, 99, 101, 112, 116, 45, 104, 111, 111, 107, 64,
    48, 46, 49, 46, 48, 4, 0, 11, 20, 1, 0, 14, 105, 110, 116, 101, 114, 99, 101, 112, 116, 45,
    104, 111, 111, 107, 3, 0, 0, 0, 70, 9, 112, 114, 111, 100, 117, 99, 101, 114, 115, 1, 12, 112,
    114, 111, 99, 101, 115, 115, 101, 100, 45, 98, 121, 2, 13, 119, 105, 116, 45, 99, 111, 109,
    112, 111, 110, 101, 110, 116, 6, 48, 46, 50, 48, 46, 49, 16, 119, 105, 116, 45, 98, 105, 110,
    100, 103, 101, 110, 45, 114, 117, 115, 116, 6, 48, 46, 49, 55, 46, 48,
];

#[inline(never)]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
pub fn __link_section() {}