wasmer_journal/concrete/
archived_from.rs

1use std::borrow::Cow;
2use std::time::SystemTime;
3use wasmer_wasix_types::wasi;
4use wasmer_wasix_types::wasix::{ThreadStartType, WasiMemoryLayout};
5
6use super::*;
7
8impl From<wasi::Snapshot0Clockid> for JournalSnapshot0ClockidV1 {
9    fn from(val: wasi::Snapshot0Clockid) -> Self {
10        match val {
11            wasi::Snapshot0Clockid::Realtime => JournalSnapshot0ClockidV1::Realtime,
12            wasi::Snapshot0Clockid::Monotonic => JournalSnapshot0ClockidV1::Monotonic,
13            wasi::Snapshot0Clockid::ProcessCputimeId => JournalSnapshot0ClockidV1::ProcessCputimeId,
14            wasi::Snapshot0Clockid::ThreadCputimeId => JournalSnapshot0ClockidV1::ThreadCputimeId,
15            wasi::Snapshot0Clockid::Unknown => JournalSnapshot0ClockidV1::Unknown,
16            _ => panic!("Unsupported Snapshot0Clockid variant"),
17        }
18    }
19}
20
21impl From<JournalSnapshot0ClockidV1> for wasi::Snapshot0Clockid {
22    fn from(val: JournalSnapshot0ClockidV1) -> Self {
23        match val {
24            JournalSnapshot0ClockidV1::Realtime => wasi::Snapshot0Clockid::Realtime,
25            JournalSnapshot0ClockidV1::Monotonic => wasi::Snapshot0Clockid::Monotonic,
26            JournalSnapshot0ClockidV1::ProcessCputimeId => wasi::Snapshot0Clockid::ProcessCputimeId,
27            JournalSnapshot0ClockidV1::ThreadCputimeId => wasi::Snapshot0Clockid::ThreadCputimeId,
28            JournalSnapshot0ClockidV1::Unknown => wasi::Snapshot0Clockid::Unknown,
29        }
30    }
31}
32
33impl From<&'_ ArchivedJournalSnapshot0ClockidV1> for wasi::Snapshot0Clockid {
34    fn from(val: &'_ ArchivedJournalSnapshot0ClockidV1) -> Self {
35        match val {
36            ArchivedJournalSnapshot0ClockidV1::Realtime => wasi::Snapshot0Clockid::Realtime,
37            ArchivedJournalSnapshot0ClockidV1::Monotonic => wasi::Snapshot0Clockid::Monotonic,
38            ArchivedJournalSnapshot0ClockidV1::ProcessCputimeId => {
39                wasi::Snapshot0Clockid::ProcessCputimeId
40            }
41            ArchivedJournalSnapshot0ClockidV1::ThreadCputimeId => {
42                wasi::Snapshot0Clockid::ThreadCputimeId
43            }
44            ArchivedJournalSnapshot0ClockidV1::Unknown => wasi::Snapshot0Clockid::Unknown,
45        }
46    }
47}
48
49impl From<wasi::Whence> for JournalWhenceV1 {
50    fn from(val: wasi::Whence) -> Self {
51        match val {
52            wasi::Whence::Set => JournalWhenceV1::Set,
53            wasi::Whence::Cur => JournalWhenceV1::Cur,
54            wasi::Whence::End => JournalWhenceV1::End,
55            wasi::Whence::Unknown => JournalWhenceV1::Unknown,
56            _ => panic!("Unsupported Whence variant"),
57        }
58    }
59}
60
61impl From<JournalWhenceV1> for wasi::Whence {
62    fn from(val: JournalWhenceV1) -> Self {
63        match val {
64            JournalWhenceV1::Set => wasi::Whence::Set,
65            JournalWhenceV1::Cur => wasi::Whence::Cur,
66            JournalWhenceV1::End => wasi::Whence::End,
67            JournalWhenceV1::Unknown => wasi::Whence::Unknown,
68        }
69    }
70}
71
72impl From<&'_ ArchivedJournalWhenceV1> for wasi::Whence {
73    fn from(val: &'_ ArchivedJournalWhenceV1) -> Self {
74        match val {
75            ArchivedJournalWhenceV1::Set => wasi::Whence::Set,
76            ArchivedJournalWhenceV1::Cur => wasi::Whence::Cur,
77            ArchivedJournalWhenceV1::End => wasi::Whence::End,
78            ArchivedJournalWhenceV1::Unknown => wasi::Whence::Unknown,
79        }
80    }
81}
82
83impl From<wasi::Advice> for JournalAdviceV1 {
84    fn from(val: wasi::Advice) -> Self {
85        match val {
86            wasi::Advice::Normal => JournalAdviceV1::Normal,
87            wasi::Advice::Sequential => JournalAdviceV1::Sequential,
88            wasi::Advice::Random => JournalAdviceV1::Random,
89            wasi::Advice::Willneed => JournalAdviceV1::Willneed,
90            wasi::Advice::Dontneed => JournalAdviceV1::Dontneed,
91            wasi::Advice::Noreuse => JournalAdviceV1::Noreuse,
92            wasi::Advice::Unknown => JournalAdviceV1::Unknown,
93            _ => panic!("Unsupported Advice variant"),
94        }
95    }
96}
97
98impl From<JournalAdviceV1> for wasi::Advice {
99    fn from(val: JournalAdviceV1) -> Self {
100        match val {
101            JournalAdviceV1::Normal => wasi::Advice::Normal,
102            JournalAdviceV1::Sequential => wasi::Advice::Sequential,
103            JournalAdviceV1::Random => wasi::Advice::Random,
104            JournalAdviceV1::Willneed => wasi::Advice::Willneed,
105            JournalAdviceV1::Dontneed => wasi::Advice::Dontneed,
106            JournalAdviceV1::Noreuse => wasi::Advice::Noreuse,
107            JournalAdviceV1::Unknown => wasi::Advice::Unknown,
108        }
109    }
110}
111
112impl From<&'_ ArchivedJournalAdviceV1> for wasi::Advice {
113    fn from(val: &'_ ArchivedJournalAdviceV1) -> Self {
114        match val {
115            ArchivedJournalAdviceV1::Normal => wasi::Advice::Normal,
116            ArchivedJournalAdviceV1::Sequential => wasi::Advice::Sequential,
117            ArchivedJournalAdviceV1::Random => wasi::Advice::Random,
118            ArchivedJournalAdviceV1::Willneed => wasi::Advice::Willneed,
119            ArchivedJournalAdviceV1::Dontneed => wasi::Advice::Dontneed,
120            ArchivedJournalAdviceV1::Noreuse => wasi::Advice::Noreuse,
121            ArchivedJournalAdviceV1::Unknown => wasi::Advice::Unknown,
122        }
123    }
124}
125
126impl From<virtual_net::IpCidr> for JournalIpCidrV1 {
127    fn from(value: virtual_net::IpCidr) -> Self {
128        Self {
129            ip: value.ip,
130            prefix: value.prefix,
131        }
132    }
133}
134
135impl From<JournalIpCidrV1> for virtual_net::IpCidr {
136    fn from(value: JournalIpCidrV1) -> Self {
137        Self {
138            ip: value.ip,
139            prefix: value.prefix,
140        }
141    }
142}
143
144impl From<wasi::ExitCode> for JournalExitCodeV1 {
145    fn from(val: wasi::ExitCode) -> Self {
146        JournalExitCodeV1::Other(val.raw())
147    }
148}
149
150impl From<JournalExitCodeV1> for wasi::ExitCode {
151    fn from(val: JournalExitCodeV1) -> Self {
152        match val {
153            JournalExitCodeV1::Errno(errno) => wasi::ExitCode::from(errno),
154            JournalExitCodeV1::Other(id) => wasi::ExitCode::from(id),
155        }
156    }
157}
158
159impl From<&'_ ArchivedJournalExitCodeV1> for wasi::ExitCode {
160    fn from(val: &'_ ArchivedJournalExitCodeV1) -> Self {
161        match val {
162            ArchivedJournalExitCodeV1::Errno(errno) => wasi::ExitCode::from(errno.to_native()),
163            ArchivedJournalExitCodeV1::Other(id) => wasi::ExitCode::from(id.to_native()),
164        }
165    }
166}
167
168impl From<SnapshotTrigger> for JournalSnapshotTriggerV1 {
169    fn from(val: SnapshotTrigger) -> Self {
170        match val {
171            SnapshotTrigger::Idle => JournalSnapshotTriggerV1::Idle,
172            SnapshotTrigger::FirstListen => JournalSnapshotTriggerV1::Listen,
173            SnapshotTrigger::FirstEnviron => JournalSnapshotTriggerV1::Environ,
174            SnapshotTrigger::FirstStdin => JournalSnapshotTriggerV1::Stdin,
175            SnapshotTrigger::FirstSigint => JournalSnapshotTriggerV1::Sigint,
176            SnapshotTrigger::PeriodicInterval => JournalSnapshotTriggerV1::Timer,
177            SnapshotTrigger::Sigint => JournalSnapshotTriggerV1::Sigint,
178            SnapshotTrigger::Sigalrm => JournalSnapshotTriggerV1::Sigalrm,
179            SnapshotTrigger::Sigtstp => JournalSnapshotTriggerV1::Sigtstp,
180            SnapshotTrigger::Sigstop => JournalSnapshotTriggerV1::Sigstop,
181            SnapshotTrigger::NonDeterministicCall => JournalSnapshotTriggerV1::NonDeterministicCall,
182            SnapshotTrigger::Bootstrap => JournalSnapshotTriggerV1::Bootstrap,
183            SnapshotTrigger::Transaction => JournalSnapshotTriggerV1::Transaction,
184            SnapshotTrigger::Explicit => JournalSnapshotTriggerV1::Explicit,
185        }
186    }
187}
188
189impl From<JournalSnapshotTriggerV1> for SnapshotTrigger {
190    fn from(val: JournalSnapshotTriggerV1) -> Self {
191        match val {
192            JournalSnapshotTriggerV1::Idle => SnapshotTrigger::Idle,
193            JournalSnapshotTriggerV1::Listen => SnapshotTrigger::FirstListen,
194            JournalSnapshotTriggerV1::Environ => SnapshotTrigger::FirstEnviron,
195            JournalSnapshotTriggerV1::Stdin => SnapshotTrigger::FirstStdin,
196            JournalSnapshotTriggerV1::Timer => SnapshotTrigger::PeriodicInterval,
197            JournalSnapshotTriggerV1::Sigint => SnapshotTrigger::Sigint,
198            JournalSnapshotTriggerV1::Sigalrm => SnapshotTrigger::Sigalrm,
199            JournalSnapshotTriggerV1::Sigtstp => SnapshotTrigger::Sigtstp,
200            JournalSnapshotTriggerV1::Sigstop => SnapshotTrigger::Sigstop,
201            JournalSnapshotTriggerV1::NonDeterministicCall => SnapshotTrigger::NonDeterministicCall,
202            JournalSnapshotTriggerV1::Bootstrap => SnapshotTrigger::Bootstrap,
203            JournalSnapshotTriggerV1::Transaction => SnapshotTrigger::Transaction,
204            JournalSnapshotTriggerV1::Explicit => SnapshotTrigger::Explicit,
205        }
206    }
207}
208
209impl From<&'_ ArchivedJournalSnapshotTriggerV1> for SnapshotTrigger {
210    fn from(val: &'_ ArchivedJournalSnapshotTriggerV1) -> Self {
211        match val {
212            ArchivedJournalSnapshotTriggerV1::Idle => SnapshotTrigger::Idle,
213            ArchivedJournalSnapshotTriggerV1::Listen => SnapshotTrigger::FirstListen,
214            ArchivedJournalSnapshotTriggerV1::Environ => SnapshotTrigger::FirstEnviron,
215            ArchivedJournalSnapshotTriggerV1::Stdin => SnapshotTrigger::FirstStdin,
216            ArchivedJournalSnapshotTriggerV1::Timer => SnapshotTrigger::PeriodicInterval,
217            ArchivedJournalSnapshotTriggerV1::Sigint => SnapshotTrigger::Sigint,
218            ArchivedJournalSnapshotTriggerV1::Sigalrm => SnapshotTrigger::Sigalrm,
219            ArchivedJournalSnapshotTriggerV1::Sigtstp => SnapshotTrigger::Sigtstp,
220            ArchivedJournalSnapshotTriggerV1::Sigstop => SnapshotTrigger::Sigstop,
221            ArchivedJournalSnapshotTriggerV1::NonDeterministicCall => {
222                SnapshotTrigger::NonDeterministicCall
223            }
224            ArchivedJournalSnapshotTriggerV1::Bootstrap => SnapshotTrigger::Bootstrap,
225            ArchivedJournalSnapshotTriggerV1::Transaction => SnapshotTrigger::Transaction,
226            ArchivedJournalSnapshotTriggerV1::Explicit => SnapshotTrigger::Explicit,
227        }
228    }
229}
230
231impl From<wasi::EpollCtl> for JournalEpollCtlV1 {
232    fn from(val: wasi::EpollCtl) -> Self {
233        match val {
234            wasi::EpollCtl::Add => JournalEpollCtlV1::Add,
235            wasi::EpollCtl::Mod => JournalEpollCtlV1::Mod,
236            wasi::EpollCtl::Del => JournalEpollCtlV1::Del,
237            wasi::EpollCtl::Unknown => JournalEpollCtlV1::Unknown,
238        }
239    }
240}
241
242impl From<JournalEpollCtlV1> for wasi::EpollCtl {
243    fn from(val: JournalEpollCtlV1) -> Self {
244        match val {
245            JournalEpollCtlV1::Add => wasi::EpollCtl::Add,
246            JournalEpollCtlV1::Mod => wasi::EpollCtl::Mod,
247            JournalEpollCtlV1::Del => wasi::EpollCtl::Del,
248            JournalEpollCtlV1::Unknown => wasi::EpollCtl::Unknown,
249        }
250    }
251}
252
253impl From<&'_ ArchivedJournalEpollCtlV1> for wasi::EpollCtl {
254    fn from(val: &'_ ArchivedJournalEpollCtlV1) -> Self {
255        match val {
256            ArchivedJournalEpollCtlV1::Add => wasi::EpollCtl::Add,
257            ArchivedJournalEpollCtlV1::Mod => wasi::EpollCtl::Mod,
258            ArchivedJournalEpollCtlV1::Del => wasi::EpollCtl::Del,
259            ArchivedJournalEpollCtlV1::Unknown => wasi::EpollCtl::Unknown,
260        }
261    }
262}
263
264impl From<wasi::EpollEventCtl> for JournalEpollEventCtlV1 {
265    fn from(val: wasi::EpollEventCtl) -> Self {
266        JournalEpollEventCtlV1 {
267            events: val.events.bits(),
268            ptr: val.ptr,
269            fd: val.fd,
270            data1: val.data1,
271            data2: val.data2,
272        }
273    }
274}
275
276impl From<JournalEpollEventCtlV1> for wasi::EpollEventCtl {
277    fn from(val: JournalEpollEventCtlV1) -> Self {
278        Self {
279            events: wasi::EpollType::from_bits_truncate(val.events),
280            ptr: val.ptr,
281            fd: val.fd,
282            data1: val.data1,
283            data2: val.data2,
284        }
285    }
286}
287
288impl From<&'_ ArchivedJournalEpollEventCtlV1> for wasi::EpollEventCtl {
289    fn from(val: &'_ ArchivedJournalEpollEventCtlV1) -> Self {
290        Self {
291            events: wasi::EpollType::from_bits_truncate(val.events.to_native()),
292            ptr: val.ptr.to_native(),
293            fd: val.fd.to_native(),
294            data1: val.data1.to_native(),
295            data2: val.data2.to_native(),
296        }
297    }
298}
299
300impl From<virtual_net::StreamSecurity> for JournalStreamSecurityV1 {
301    fn from(val: virtual_net::StreamSecurity) -> Self {
302        use virtual_net::StreamSecurity;
303        match val {
304            StreamSecurity::Unencrypted => JournalStreamSecurityV1::Unencrypted,
305            StreamSecurity::AnyEncyption => JournalStreamSecurityV1::AnyEncryption,
306            StreamSecurity::ClassicEncryption => JournalStreamSecurityV1::ClassicEncryption,
307            StreamSecurity::DoubleEncryption => JournalStreamSecurityV1::DoubleEncryption,
308        }
309    }
310}
311
312impl From<JournalStreamSecurityV1> for virtual_net::StreamSecurity {
313    fn from(val: JournalStreamSecurityV1) -> Self {
314        use virtual_net::StreamSecurity;
315        match val {
316            JournalStreamSecurityV1::Unencrypted => StreamSecurity::Unencrypted,
317            JournalStreamSecurityV1::AnyEncryption => StreamSecurity::AnyEncyption,
318            JournalStreamSecurityV1::ClassicEncryption => StreamSecurity::ClassicEncryption,
319            JournalStreamSecurityV1::DoubleEncryption => StreamSecurity::DoubleEncryption,
320            JournalStreamSecurityV1::Unknown => StreamSecurity::AnyEncyption,
321        }
322    }
323}
324
325impl From<&'_ ArchivedJournalStreamSecurityV1> for virtual_net::StreamSecurity {
326    fn from(val: &'_ ArchivedJournalStreamSecurityV1) -> Self {
327        use virtual_net::StreamSecurity;
328        match val {
329            ArchivedJournalStreamSecurityV1::Unencrypted => StreamSecurity::Unencrypted,
330            ArchivedJournalStreamSecurityV1::AnyEncryption => StreamSecurity::AnyEncyption,
331            ArchivedJournalStreamSecurityV1::ClassicEncryption => StreamSecurity::ClassicEncryption,
332            ArchivedJournalStreamSecurityV1::DoubleEncryption => StreamSecurity::DoubleEncryption,
333            ArchivedJournalStreamSecurityV1::Unknown => StreamSecurity::AnyEncyption,
334        }
335    }
336}
337
338impl From<wasi::Addressfamily> for JournalAddressfamilyV1 {
339    fn from(val: wasi::Addressfamily) -> Self {
340        match val {
341            wasi::Addressfamily::Unspec => JournalAddressfamilyV1::Unspec,
342            wasi::Addressfamily::Inet4 => JournalAddressfamilyV1::Inet4,
343            wasi::Addressfamily::Inet6 => JournalAddressfamilyV1::Inet6,
344            wasi::Addressfamily::Unix => JournalAddressfamilyV1::Unix,
345            _ => panic!("Unsupported Addressfamily variant"),
346        }
347    }
348}
349
350impl From<JournalAddressfamilyV1> for wasi::Addressfamily {
351    fn from(val: JournalAddressfamilyV1) -> Self {
352        match val {
353            JournalAddressfamilyV1::Unspec => wasi::Addressfamily::Unspec,
354            JournalAddressfamilyV1::Inet4 => wasi::Addressfamily::Inet4,
355            JournalAddressfamilyV1::Inet6 => wasi::Addressfamily::Inet6,
356            JournalAddressfamilyV1::Unix => wasi::Addressfamily::Unix,
357        }
358    }
359}
360
361impl From<&'_ ArchivedJournalAddressfamilyV1> for wasi::Addressfamily {
362    fn from(val: &'_ ArchivedJournalAddressfamilyV1) -> Self {
363        match val {
364            ArchivedJournalAddressfamilyV1::Unspec => wasi::Addressfamily::Unspec,
365            ArchivedJournalAddressfamilyV1::Inet4 => wasi::Addressfamily::Inet4,
366            ArchivedJournalAddressfamilyV1::Inet6 => wasi::Addressfamily::Inet6,
367            ArchivedJournalAddressfamilyV1::Unix => wasi::Addressfamily::Unix,
368        }
369    }
370}
371
372impl From<wasi::Socktype> for JournalSocktypeV1 {
373    fn from(val: wasi::Socktype) -> Self {
374        match val {
375            wasi::Socktype::Stream => JournalSocktypeV1::Stream,
376            wasi::Socktype::Dgram => JournalSocktypeV1::Dgram,
377            wasi::Socktype::Raw => JournalSocktypeV1::Raw,
378            wasi::Socktype::Seqpacket => JournalSocktypeV1::Seqpacket,
379            wasi::Socktype::Unknown => JournalSocktypeV1::Unknown,
380            _ => panic!("Unsupported Socktype variant"),
381        }
382    }
383}
384
385impl From<JournalSocktypeV1> for wasi::Socktype {
386    fn from(val: JournalSocktypeV1) -> Self {
387        match val {
388            JournalSocktypeV1::Stream => wasi::Socktype::Stream,
389            JournalSocktypeV1::Dgram => wasi::Socktype::Dgram,
390            JournalSocktypeV1::Raw => wasi::Socktype::Raw,
391            JournalSocktypeV1::Seqpacket => wasi::Socktype::Seqpacket,
392            JournalSocktypeV1::Unknown => wasi::Socktype::Unknown,
393        }
394    }
395}
396
397impl From<&'_ ArchivedJournalSocktypeV1> for wasi::Socktype {
398    fn from(val: &'_ ArchivedJournalSocktypeV1) -> Self {
399        match val {
400            ArchivedJournalSocktypeV1::Stream => wasi::Socktype::Stream,
401            ArchivedJournalSocktypeV1::Dgram => wasi::Socktype::Dgram,
402            ArchivedJournalSocktypeV1::Raw => wasi::Socktype::Raw,
403            ArchivedJournalSocktypeV1::Seqpacket => wasi::Socktype::Seqpacket,
404            ArchivedJournalSocktypeV1::Unknown => wasi::Socktype::Unknown,
405        }
406    }
407}
408
409impl From<wasi::Sockoption> for JournalSockoptionV1 {
410    fn from(val: wasi::Sockoption) -> Self {
411        match val {
412            wasi::Sockoption::Noop => JournalSockoptionV1::Noop,
413            wasi::Sockoption::ReusePort => JournalSockoptionV1::ReusePort,
414            wasi::Sockoption::ReuseAddr => JournalSockoptionV1::ReuseAddr,
415            wasi::Sockoption::NoDelay => JournalSockoptionV1::NoDelay,
416            wasi::Sockoption::DontRoute => JournalSockoptionV1::DontRoute,
417            wasi::Sockoption::OnlyV6 => JournalSockoptionV1::OnlyV6,
418            wasi::Sockoption::Broadcast => JournalSockoptionV1::Broadcast,
419            wasi::Sockoption::MulticastLoopV4 => JournalSockoptionV1::MulticastLoopV4,
420            wasi::Sockoption::MulticastLoopV6 => JournalSockoptionV1::MulticastLoopV6,
421            wasi::Sockoption::Promiscuous => JournalSockoptionV1::Promiscuous,
422            wasi::Sockoption::Listening => JournalSockoptionV1::Listening,
423            wasi::Sockoption::LastError => JournalSockoptionV1::LastError,
424            wasi::Sockoption::KeepAlive => JournalSockoptionV1::KeepAlive,
425            wasi::Sockoption::Linger => JournalSockoptionV1::Linger,
426            wasi::Sockoption::OobInline => JournalSockoptionV1::OobInline,
427            wasi::Sockoption::RecvBufSize => JournalSockoptionV1::RecvBufSize,
428            wasi::Sockoption::SendBufSize => JournalSockoptionV1::SendBufSize,
429            wasi::Sockoption::RecvLowat => JournalSockoptionV1::RecvLowat,
430            wasi::Sockoption::SendLowat => JournalSockoptionV1::SendLowat,
431            wasi::Sockoption::RecvTimeout => JournalSockoptionV1::RecvTimeout,
432            wasi::Sockoption::SendTimeout => JournalSockoptionV1::SendTimeout,
433            wasi::Sockoption::ConnectTimeout => JournalSockoptionV1::ConnectTimeout,
434            wasi::Sockoption::AcceptTimeout => JournalSockoptionV1::AcceptTimeout,
435            wasi::Sockoption::Ttl => JournalSockoptionV1::Ttl,
436            wasi::Sockoption::MulticastTtlV4 => JournalSockoptionV1::MulticastTtlV4,
437            wasi::Sockoption::Type => JournalSockoptionV1::Type,
438            wasi::Sockoption::Proto => JournalSockoptionV1::Proto,
439            _ => panic!("Unsupported Sockoption variant"),
440        }
441    }
442}
443
444impl From<JournalSockoptionV1> for wasi::Sockoption {
445    fn from(val: JournalSockoptionV1) -> Self {
446        match val {
447            JournalSockoptionV1::Noop => wasi::Sockoption::Noop,
448            JournalSockoptionV1::ReusePort => wasi::Sockoption::ReusePort,
449            JournalSockoptionV1::ReuseAddr => wasi::Sockoption::ReuseAddr,
450            JournalSockoptionV1::NoDelay => wasi::Sockoption::NoDelay,
451            JournalSockoptionV1::DontRoute => wasi::Sockoption::DontRoute,
452            JournalSockoptionV1::OnlyV6 => wasi::Sockoption::OnlyV6,
453            JournalSockoptionV1::Broadcast => wasi::Sockoption::Broadcast,
454            JournalSockoptionV1::MulticastLoopV4 => wasi::Sockoption::MulticastLoopV4,
455            JournalSockoptionV1::MulticastLoopV6 => wasi::Sockoption::MulticastLoopV6,
456            JournalSockoptionV1::Promiscuous => wasi::Sockoption::Promiscuous,
457            JournalSockoptionV1::Listening => wasi::Sockoption::Listening,
458            JournalSockoptionV1::LastError => wasi::Sockoption::LastError,
459            JournalSockoptionV1::KeepAlive => wasi::Sockoption::KeepAlive,
460            JournalSockoptionV1::Linger => wasi::Sockoption::Linger,
461            JournalSockoptionV1::OobInline => wasi::Sockoption::OobInline,
462            JournalSockoptionV1::RecvBufSize => wasi::Sockoption::RecvBufSize,
463            JournalSockoptionV1::SendBufSize => wasi::Sockoption::SendBufSize,
464            JournalSockoptionV1::RecvLowat => wasi::Sockoption::RecvLowat,
465            JournalSockoptionV1::SendLowat => wasi::Sockoption::SendLowat,
466            JournalSockoptionV1::RecvTimeout => wasi::Sockoption::RecvTimeout,
467            JournalSockoptionV1::SendTimeout => wasi::Sockoption::SendTimeout,
468            JournalSockoptionV1::ConnectTimeout => wasi::Sockoption::ConnectTimeout,
469            JournalSockoptionV1::AcceptTimeout => wasi::Sockoption::AcceptTimeout,
470            JournalSockoptionV1::Ttl => wasi::Sockoption::Ttl,
471            JournalSockoptionV1::MulticastTtlV4 => wasi::Sockoption::MulticastTtlV4,
472            JournalSockoptionV1::Type => wasi::Sockoption::Type,
473            JournalSockoptionV1::Proto => wasi::Sockoption::Proto,
474        }
475    }
476}
477
478impl From<&'_ ArchivedJournalSockoptionV1> for wasi::Sockoption {
479    fn from(val: &'_ ArchivedJournalSockoptionV1) -> Self {
480        match val {
481            ArchivedJournalSockoptionV1::Noop => wasi::Sockoption::Noop,
482            ArchivedJournalSockoptionV1::ReusePort => wasi::Sockoption::ReusePort,
483            ArchivedJournalSockoptionV1::ReuseAddr => wasi::Sockoption::ReuseAddr,
484            ArchivedJournalSockoptionV1::NoDelay => wasi::Sockoption::NoDelay,
485            ArchivedJournalSockoptionV1::DontRoute => wasi::Sockoption::DontRoute,
486            ArchivedJournalSockoptionV1::OnlyV6 => wasi::Sockoption::OnlyV6,
487            ArchivedJournalSockoptionV1::Broadcast => wasi::Sockoption::Broadcast,
488            ArchivedJournalSockoptionV1::MulticastLoopV4 => wasi::Sockoption::MulticastLoopV4,
489            ArchivedJournalSockoptionV1::MulticastLoopV6 => wasi::Sockoption::MulticastLoopV6,
490            ArchivedJournalSockoptionV1::Promiscuous => wasi::Sockoption::Promiscuous,
491            ArchivedJournalSockoptionV1::Listening => wasi::Sockoption::Listening,
492            ArchivedJournalSockoptionV1::LastError => wasi::Sockoption::LastError,
493            ArchivedJournalSockoptionV1::KeepAlive => wasi::Sockoption::KeepAlive,
494            ArchivedJournalSockoptionV1::Linger => wasi::Sockoption::Linger,
495            ArchivedJournalSockoptionV1::OobInline => wasi::Sockoption::OobInline,
496            ArchivedJournalSockoptionV1::RecvBufSize => wasi::Sockoption::RecvBufSize,
497            ArchivedJournalSockoptionV1::SendBufSize => wasi::Sockoption::SendBufSize,
498            ArchivedJournalSockoptionV1::RecvLowat => wasi::Sockoption::RecvLowat,
499            ArchivedJournalSockoptionV1::SendLowat => wasi::Sockoption::SendLowat,
500            ArchivedJournalSockoptionV1::RecvTimeout => wasi::Sockoption::RecvTimeout,
501            ArchivedJournalSockoptionV1::SendTimeout => wasi::Sockoption::SendTimeout,
502            ArchivedJournalSockoptionV1::ConnectTimeout => wasi::Sockoption::ConnectTimeout,
503            ArchivedJournalSockoptionV1::AcceptTimeout => wasi::Sockoption::AcceptTimeout,
504            ArchivedJournalSockoptionV1::Ttl => wasi::Sockoption::Ttl,
505            ArchivedJournalSockoptionV1::MulticastTtlV4 => wasi::Sockoption::MulticastTtlV4,
506            ArchivedJournalSockoptionV1::Type => wasi::Sockoption::Type,
507            ArchivedJournalSockoptionV1::Proto => wasi::Sockoption::Proto,
508        }
509    }
510}
511
512impl From<SocketOptTimeType> for JournalTimeTypeV1 {
513    fn from(val: SocketOptTimeType) -> Self {
514        match val {
515            SocketOptTimeType::ReadTimeout => JournalTimeTypeV1::ReadTimeout,
516            SocketOptTimeType::WriteTimeout => JournalTimeTypeV1::WriteTimeout,
517            SocketOptTimeType::AcceptTimeout => JournalTimeTypeV1::AcceptTimeout,
518            SocketOptTimeType::ConnectTimeout => JournalTimeTypeV1::ConnectTimeout,
519            SocketOptTimeType::BindTimeout => JournalTimeTypeV1::BindTimeout,
520            SocketOptTimeType::Linger => JournalTimeTypeV1::Linger,
521        }
522    }
523}
524
525impl From<JournalTimeTypeV1> for SocketOptTimeType {
526    fn from(val: JournalTimeTypeV1) -> Self {
527        match val {
528            JournalTimeTypeV1::ReadTimeout => SocketOptTimeType::ReadTimeout,
529            JournalTimeTypeV1::WriteTimeout => SocketOptTimeType::WriteTimeout,
530            JournalTimeTypeV1::AcceptTimeout => SocketOptTimeType::AcceptTimeout,
531            JournalTimeTypeV1::ConnectTimeout => SocketOptTimeType::ConnectTimeout,
532            JournalTimeTypeV1::BindTimeout => SocketOptTimeType::BindTimeout,
533            JournalTimeTypeV1::Linger => SocketOptTimeType::Linger,
534        }
535    }
536}
537
538impl From<&'_ ArchivedJournalTimeTypeV1> for SocketOptTimeType {
539    fn from(val: &'_ ArchivedJournalTimeTypeV1) -> Self {
540        match val {
541            ArchivedJournalTimeTypeV1::ReadTimeout => SocketOptTimeType::ReadTimeout,
542            ArchivedJournalTimeTypeV1::WriteTimeout => SocketOptTimeType::WriteTimeout,
543            ArchivedJournalTimeTypeV1::AcceptTimeout => SocketOptTimeType::AcceptTimeout,
544            ArchivedJournalTimeTypeV1::ConnectTimeout => SocketOptTimeType::ConnectTimeout,
545            ArchivedJournalTimeTypeV1::BindTimeout => SocketOptTimeType::BindTimeout,
546            ArchivedJournalTimeTypeV1::Linger => SocketOptTimeType::Linger,
547        }
548    }
549}
550
551impl From<SocketShutdownHow> for JournalSocketShutdownV1 {
552    fn from(val: SocketShutdownHow) -> Self {
553        match val {
554            SocketShutdownHow::Read => JournalSocketShutdownV1::Read,
555            SocketShutdownHow::Write => JournalSocketShutdownV1::Write,
556            SocketShutdownHow::Both => JournalSocketShutdownV1::Both,
557        }
558    }
559}
560
561impl From<JournalSocketShutdownV1> for SocketShutdownHow {
562    fn from(val: JournalSocketShutdownV1) -> Self {
563        match val {
564            JournalSocketShutdownV1::Read => SocketShutdownHow::Read,
565            JournalSocketShutdownV1::Write => SocketShutdownHow::Write,
566            JournalSocketShutdownV1::Both => SocketShutdownHow::Both,
567        }
568    }
569}
570
571impl From<&'_ ArchivedJournalSocketShutdownV1> for SocketShutdownHow {
572    fn from(val: &'_ ArchivedJournalSocketShutdownV1) -> Self {
573        match val {
574            ArchivedJournalSocketShutdownV1::Read => SocketShutdownHow::Read,
575            ArchivedJournalSocketShutdownV1::Write => SocketShutdownHow::Write,
576            ArchivedJournalSocketShutdownV1::Both => SocketShutdownHow::Both,
577        }
578    }
579}
580
581impl From<JournalThreadStartTypeV1> for ThreadStartType {
582    fn from(value: JournalThreadStartTypeV1) -> Self {
583        match value {
584            JournalThreadStartTypeV1::MainThread => ThreadStartType::MainThread,
585            JournalThreadStartTypeV1::ThreadSpawn { start_ptr } => {
586                ThreadStartType::ThreadSpawn { start_ptr }
587            }
588        }
589    }
590}
591
592impl From<&'_ ArchivedJournalThreadStartTypeV1> for ThreadStartType {
593    fn from(value: &'_ ArchivedJournalThreadStartTypeV1) -> Self {
594        match value {
595            ArchivedJournalThreadStartTypeV1::MainThread => ThreadStartType::MainThread,
596            ArchivedJournalThreadStartTypeV1::ThreadSpawn { start_ptr } => {
597                ThreadStartType::ThreadSpawn {
598                    start_ptr: start_ptr.to_native(),
599                }
600            }
601        }
602    }
603}
604
605impl From<ThreadStartType> for JournalThreadStartTypeV1 {
606    fn from(value: ThreadStartType) -> Self {
607        match value {
608            ThreadStartType::MainThread => JournalThreadStartTypeV1::MainThread,
609            ThreadStartType::ThreadSpawn { start_ptr } => {
610                JournalThreadStartTypeV1::ThreadSpawn { start_ptr }
611            }
612        }
613    }
614}
615
616impl From<JournalWasiMemoryLayout> for WasiMemoryLayout {
617    fn from(value: JournalWasiMemoryLayout) -> Self {
618        Self {
619            stack_upper: value.stack_upper,
620            stack_lower: value.stack_lower,
621            guard_size: value.guard_size,
622            stack_size: value.stack_size,
623            tls_base: None,
624        }
625    }
626}
627
628impl From<&'_ ArchivedJournalWasiMemoryLayout> for WasiMemoryLayout {
629    fn from(value: &'_ ArchivedJournalWasiMemoryLayout) -> Self {
630        Self {
631            stack_upper: value.stack_upper.to_native(),
632            stack_lower: value.stack_lower.to_native(),
633            guard_size: value.guard_size.to_native(),
634            stack_size: value.stack_size.to_native(),
635            tls_base: None,
636        }
637    }
638}
639
640impl From<WasiMemoryLayout> for JournalWasiMemoryLayout {
641    fn from(value: WasiMemoryLayout) -> Self {
642        Self {
643            stack_upper: value.stack_upper,
644            stack_lower: value.stack_lower,
645            guard_size: value.guard_size,
646            stack_size: value.stack_size,
647        }
648    }
649}
650
651impl<'a> TryFrom<ArchivedJournalEntry<'a>> for JournalEntry<'a> {
652    type Error = anyhow::Error;
653
654    fn try_from(value: ArchivedJournalEntry<'a>) -> anyhow::Result<Self> {
655        Ok(match value {
656            ArchivedJournalEntry::InitModuleV1(ArchivedJournalEntryInitModuleV1 { wasm_hash }) => {
657                Self::InitModuleV1 {
658                    wasm_hash: Box::from(wasm_hash.get()),
659                }
660            }
661            ArchivedJournalEntry::ClearEtherealV1(ArchivedJournalEntryClearEtherealV1 {
662                ..
663            }) => Self::ClearEtherealV1,
664            ArchivedJournalEntry::UpdateMemoryRegionV1(
665                ArchivedJournalEntryUpdateMemoryRegionV1 {
666                    start,
667                    end,
668                    compressed_data,
669                },
670            ) => Self::UpdateMemoryRegionV1 {
671                region: (start.to_native())..(end.to_native()),
672                compressed_data: Cow::Borrowed(compressed_data.as_ref()),
673            },
674            ArchivedJournalEntry::ProcessExitV1(ArchivedJournalEntryProcessExitV1 {
675                exit_code,
676            }) => Self::ProcessExitV1 {
677                exit_code: exit_code.as_ref().map(|code| code.into()),
678            },
679            ArchivedJournalEntry::SetThreadV1(ArchivedJournalEntrySetThreadV1 {
680                id,
681                call_stack,
682                memory_stack,
683                store_data,
684                is_64bit,
685                start,
686                layout,
687            }) => Self::SetThreadV1 {
688                id: id.to_native(),
689                call_stack: call_stack.as_ref().into(),
690                memory_stack: memory_stack.as_ref().into(),
691                store_data: store_data.as_ref().into(),
692                start: start.into(),
693                layout: layout.into(),
694                is_64bit: *is_64bit,
695            },
696            ArchivedJournalEntry::CloseThreadV1(ArchivedJournalEntryCloseThreadV1 {
697                id,
698                exit_code,
699            }) => Self::CloseThreadV1 {
700                id: id.to_native(),
701                exit_code: exit_code.as_ref().map(|code| code.into()),
702            },
703            ArchivedJournalEntry::FileDescriptorWriteV1(
704                ArchivedJournalEntryFileDescriptorWriteV1 {
705                    data,
706                    fd,
707                    offset,
708                    is_64bit,
709                },
710            ) => Self::FileDescriptorWriteV1 {
711                data: data.as_ref().into(),
712                fd: fd.to_native(),
713                offset: offset.to_native(),
714                is_64bit: *is_64bit,
715            },
716            ArchivedJournalEntry::FileDescriptorSeekV1(
717                ArchivedJournalEntryFileDescriptorSeekV1 { fd, offset, whence },
718            ) => Self::FileDescriptorSeekV1 {
719                fd: fd.to_native(),
720                offset: offset.to_native(),
721                whence: whence.into(),
722            },
723            ArchivedJournalEntry::OpenFileDescriptorV1(
724                ArchivedJournalEntryOpenFileDescriptorV1 {
725                    fd,
726                    dirfd,
727                    dirflags,
728                    path,
729                    o_flags,
730                    fs_rights_base,
731                    fs_rights_inheriting,
732                    fs_flags,
733                },
734            ) => Self::OpenFileDescriptorV1 {
735                fd: fd.to_native(),
736                dirfd: dirfd.to_native(),
737                dirflags: dirflags.to_native(),
738                path: String::from_utf8_lossy(path.as_ref()),
739                o_flags: wasi::Oflags::from_bits_truncate(o_flags.to_native()),
740                fs_rights_base: wasi::Rights::from_bits_truncate(fs_rights_base.to_native()),
741                fs_rights_inheriting: wasi::Rights::from_bits_truncate(
742                    fs_rights_inheriting.to_native(),
743                ),
744                fs_flags: wasi::Fdflags::from_bits_truncate(fs_flags.to_native()),
745            },
746            ArchivedJournalEntry::OpenFileDescriptorV2(
747                ArchivedJournalEntryOpenFileDescriptorV2 {
748                    fd,
749                    dirfd,
750                    dirflags,
751                    path,
752                    o_flags,
753                    fs_rights_base,
754                    fs_rights_inheriting,
755                    fs_flags,
756                    fd_flags,
757                },
758            ) => Self::OpenFileDescriptorV2 {
759                fd: fd.to_native(),
760                dirfd: dirfd.to_native(),
761                dirflags: dirflags.to_native(),
762                path: String::from_utf8_lossy(path.as_ref()),
763                o_flags: wasi::Oflags::from_bits_truncate(o_flags.to_native()),
764                fs_rights_base: wasi::Rights::from_bits_truncate(fs_rights_base.to_native()),
765                fs_rights_inheriting: wasi::Rights::from_bits_truncate(
766                    fs_rights_inheriting.to_native(),
767                ),
768                fs_flags: wasi::Fdflags::from_bits_truncate(fs_flags.to_native()),
769                fd_flags: wasi::Fdflagsext::from_bits_truncate(fd_flags.to_native()),
770            },
771            ArchivedJournalEntry::CloseFileDescriptorV1(
772                ArchivedJournalEntryCloseFileDescriptorV1 { fd },
773            ) => Self::CloseFileDescriptorV1 { fd: fd.to_native() },
774            ArchivedJournalEntry::RemoveDirectoryV1(ArchivedJournalEntryRemoveDirectoryV1 {
775                fd,
776                path,
777            }) => Self::RemoveDirectoryV1 {
778                fd: fd.to_native(),
779                path: String::from_utf8_lossy(path.as_ref()),
780            },
781            ArchivedJournalEntry::UnlinkFileV1(ArchivedJournalEntryUnlinkFileV1 { fd, path }) => {
782                Self::UnlinkFileV1 {
783                    fd: fd.to_native(),
784                    path: String::from_utf8_lossy(path.as_ref()),
785                }
786            }
787            ArchivedJournalEntry::PathRenameV1(ArchivedJournalEntryPathRenameV1 {
788                old_fd,
789                old_path,
790                new_fd,
791                new_path,
792            }) => Self::PathRenameV1 {
793                old_fd: old_fd.to_native(),
794                old_path: String::from_utf8_lossy(old_path.as_ref()),
795                new_fd: new_fd.to_native(),
796                new_path: String::from_utf8_lossy(new_path.as_ref()),
797            },
798            ArchivedJournalEntry::SnapshotV1(ArchivedJournalEntrySnapshotV1 {
799                since_epoch,
800                trigger,
801            }) => Self::SnapshotV1 {
802                when: SystemTime::UNIX_EPOCH
803                    .checked_add((*since_epoch).into())
804                    .unwrap_or(SystemTime::UNIX_EPOCH),
805                trigger: trigger.into(),
806            },
807            ArchivedJournalEntry::SetClockTimeV1(ArchivedJournalEntrySetClockTimeV1 {
808                clock_id,
809                time,
810            }) => Self::SetClockTimeV1 {
811                clock_id: clock_id.into(),
812                time: time.to_native(),
813            },
814            ArchivedJournalEntry::RenumberFileDescriptorV1(
815                ArchivedJournalEntryRenumberFileDescriptorV1 { old_fd, new_fd },
816            ) => Self::RenumberFileDescriptorV1 {
817                old_fd: old_fd.to_native(),
818                new_fd: new_fd.to_native(),
819            },
820            ArchivedJournalEntry::DuplicateFileDescriptorV1(
821                ArchivedJournalEntryDuplicateFileDescriptorV1 {
822                    original_fd: old_fd,
823                    copied_fd: new_fd,
824                },
825            ) => Self::DuplicateFileDescriptorV1 {
826                original_fd: old_fd.to_native(),
827                copied_fd: new_fd.to_native(),
828            },
829            ArchivedJournalEntry::DuplicateFileDescriptorV2(
830                ArchivedJournalEntryDuplicateFileDescriptorV2 {
831                    original_fd: old_fd,
832                    copied_fd: new_fd,
833                    cloexec,
834                },
835            ) => Self::DuplicateFileDescriptorV2 {
836                original_fd: old_fd.to_native(),
837                copied_fd: new_fd.to_native(),
838                cloexec: *cloexec,
839            },
840            ArchivedJournalEntry::CreateDirectoryV1(ArchivedJournalEntryCreateDirectoryV1 {
841                fd,
842                path,
843            }) => Self::CreateDirectoryV1 {
844                fd: fd.to_native(),
845                path: String::from_utf8_lossy(path.as_ref()),
846            },
847            ArchivedJournalEntry::PathSetTimesV1(ArchivedJournalEntryPathSetTimesV1 {
848                fd,
849                path,
850                flags,
851                st_atim,
852                st_mtim,
853                fst_flags,
854            }) => Self::PathSetTimesV1 {
855                fd: fd.to_native(),
856                path: String::from_utf8_lossy(path.as_ref()),
857                flags: flags.to_native(),
858                st_atim: st_atim.to_native(),
859                st_mtim: st_mtim.to_native(),
860                fst_flags: wasi::Fstflags::from_bits_truncate(fst_flags.to_native()),
861            },
862            ArchivedJournalEntry::FileDescriptorSetTimesV1(
863                ArchivedJournalEntryFileDescriptorSetTimesV1 {
864                    fd,
865                    st_atim,
866                    st_mtim,
867                    fst_flags,
868                },
869            ) => Self::FileDescriptorSetTimesV1 {
870                fd: fd.to_native(),
871                st_atim: st_atim.to_native(),
872                st_mtim: st_mtim.to_native(),
873                fst_flags: wasi::Fstflags::from_bits_truncate(fst_flags.to_native()),
874            },
875            ArchivedJournalEntry::FileDescriptorSetSizeV1(
876                ArchivedJournalEntryFileDescriptorSetSizeV1 { fd, st_size },
877            ) => Self::FileDescriptorSetSizeV1 {
878                fd: fd.to_native(),
879                st_size: st_size.to_native(),
880            },
881            ArchivedJournalEntry::FileDescriptorSetFdFlagsV1(
882                ArchivedJournalEntryFileDescriptorSetFdFlagsV1 { fd, flags },
883            ) => Self::FileDescriptorSetFdFlagsV1 {
884                fd: fd.to_native(),
885                flags: wasi::Fdflagsext::from_bits_truncate(flags.to_native()),
886            },
887            ArchivedJournalEntry::FileDescriptorSetFlagsV1(
888                ArchivedJournalEntryFileDescriptorSetFlagsV1 { fd, flags },
889            ) => Self::FileDescriptorSetFlagsV1 {
890                fd: fd.to_native(),
891                flags: wasi::Fdflags::from_bits_truncate(flags.to_native()),
892            },
893            ArchivedJournalEntry::FileDescriptorSetRightsV1(
894                ArchivedJournalEntryFileDescriptorSetRightsV1 {
895                    fd,
896                    fs_rights_base,
897                    fs_rights_inheriting,
898                },
899            ) => Self::FileDescriptorSetRightsV1 {
900                fd: fd.to_native(),
901                fs_rights_base: wasi::Rights::from_bits_truncate(fs_rights_base.to_native()),
902                fs_rights_inheriting: wasi::Rights::from_bits_truncate(
903                    fs_rights_inheriting.to_native(),
904                ),
905            },
906            ArchivedJournalEntry::FileDescriptorAdviseV1(
907                ArchivedJournalEntryFileDescriptorAdviseV1 {
908                    fd,
909                    offset,
910                    len,
911                    advice,
912                },
913            ) => Self::FileDescriptorAdviseV1 {
914                fd: fd.to_native(),
915                offset: offset.to_native(),
916                len: len.to_native(),
917                advice: advice.into(),
918            },
919            ArchivedJournalEntry::FileDescriptorAllocateV1(
920                ArchivedJournalEntryFileDescriptorAllocateV1 { fd, offset, len },
921            ) => Self::FileDescriptorAllocateV1 {
922                fd: fd.to_native(),
923                offset: offset.to_native(),
924                len: len.to_native(),
925            },
926            ArchivedJournalEntry::CreateHardLinkV1(ArchivedJournalEntryCreateHardLinkV1 {
927                old_fd,
928                old_path,
929                old_flags,
930                new_fd,
931                new_path,
932            }) => Self::CreateHardLinkV1 {
933                old_fd: old_fd.to_native(),
934                old_path: String::from_utf8_lossy(old_path.as_ref()),
935                old_flags: old_flags.to_native(),
936                new_fd: new_fd.to_native(),
937                new_path: String::from_utf8_lossy(new_path.as_ref()),
938            },
939            ArchivedJournalEntry::CreateSymbolicLinkV1(
940                ArchivedJournalEntryCreateSymbolicLinkV1 {
941                    old_path,
942                    fd,
943                    new_path,
944                },
945            ) => Self::CreateSymbolicLinkV1 {
946                old_path: String::from_utf8_lossy(old_path.as_ref()),
947                fd: fd.to_native(),
948                new_path: String::from_utf8_lossy(new_path.as_ref()),
949            },
950            ArchivedJournalEntry::ChangeDirectoryV1(ArchivedJournalEntryChangeDirectoryV1 {
951                path,
952            }) => Self::ChangeDirectoryV1 {
953                path: String::from_utf8_lossy(path.as_ref()),
954            },
955            ArchivedJournalEntry::EpollCreateV1(ArchivedJournalEntryEpollCreateV1 { fd }) => {
956                Self::EpollCreateV1 { fd: fd.to_native() }
957            }
958            ArchivedJournalEntry::EpollCtlV1(ArchivedJournalEntryEpollCtlV1 {
959                epfd,
960                op,
961                fd,
962                event,
963            }) => Self::EpollCtlV1 {
964                epfd: epfd.to_native(),
965                op: op.into(),
966                fd: fd.to_native(),
967                event: event.as_ref().map(|e| e.into()),
968            },
969            ArchivedJournalEntry::TtySetV1(ArchivedJournalEntryTtySetV1 {
970                cols,
971                rows,
972                width,
973                height,
974                stdin_tty,
975                stdout_tty,
976                stderr_tty,
977                echo,
978                line_buffered,
979                line_feeds,
980            }) => Self::TtySetV1 {
981                tty: wasi::Tty {
982                    cols: cols.to_native(),
983                    rows: rows.to_native(),
984                    width: width.to_native(),
985                    height: height.to_native(),
986                    stdin_tty: *stdin_tty,
987                    stdout_tty: *stdout_tty,
988                    stderr_tty: *stderr_tty,
989                    echo: *echo,
990                    line_buffered: *line_buffered,
991                },
992                line_feeds: *line_feeds,
993            },
994            ArchivedJournalEntry::CreatePipeV1(ArchivedJournalEntryCreatePipeV1 {
995                read_fd,
996                write_fd,
997            }) => Self::CreatePipeV1 {
998                read_fd: read_fd.to_native(),
999                write_fd: write_fd.to_native(),
1000            },
1001            ArchivedJournalEntry::PortAddAddrV1(ArchivedJournalEntryPortAddAddrV1 { cidr }) => {
1002                Self::PortAddAddrV1 {
1003                    cidr: JournalIpCidrV1 {
1004                        ip: cidr.ip.as_ipaddr(),
1005                        prefix: cidr.prefix,
1006                    }
1007                    .into(),
1008                }
1009            }
1010            ArchivedJournalEntry::PortDelAddrV1(ArchivedJournalEntryPortDelAddrV1 { addr }) => {
1011                Self::PortDelAddrV1 {
1012                    addr: addr.as_ipaddr(),
1013                }
1014            }
1015            ArchivedJournalEntry::PortAddrClearV1 => Self::PortAddrClearV1,
1016            ArchivedJournalEntry::PortBridgeV1(ArchivedJournalEntryPortBridgeV1 {
1017                network,
1018                token,
1019                security,
1020            }) => Self::PortBridgeV1 {
1021                network: String::from_utf8_lossy(network.as_ref()),
1022                token: String::from_utf8_lossy(token.as_ref()),
1023                security: security.into(),
1024            },
1025            ArchivedJournalEntry::PortUnbridgeV1 => Self::PortUnbridgeV1,
1026            ArchivedJournalEntry::PortDhcpAcquireV1 => Self::PortDhcpAcquireV1,
1027            ArchivedJournalEntry::PortGatewaySetV1(ArchivedJournalEntryPortGatewaySetV1 { ip }) => {
1028                Self::PortGatewaySetV1 { ip: ip.as_ipaddr() }
1029            }
1030            ArchivedJournalEntry::PortRouteAddV1(ArchivedJournalEntryPortRouteAddV1 {
1031                cidr,
1032                via_router,
1033                preferred_until,
1034                expires_at,
1035            }) => Self::PortRouteAddV1 {
1036                cidr: JournalIpCidrV1 {
1037                    ip: cidr.ip.as_ipaddr(),
1038                    prefix: cidr.prefix,
1039                }
1040                .into(),
1041                via_router: via_router.as_ipaddr(),
1042                preferred_until: preferred_until.as_ref().map(|time| (*time).into()),
1043                expires_at: expires_at.as_ref().map(|time| (*time).into()),
1044            },
1045            ArchivedJournalEntry::PortRouteClearV1 => Self::PortRouteClearV1,
1046            ArchivedJournalEntry::PortRouteDelV1(ArchivedJournalEntryPortRouteDelV1 { ip }) => {
1047                Self::PortRouteDelV1 { ip: ip.as_ipaddr() }
1048            }
1049            ArchivedJournalEntry::SocketOpenV1(ArchivedJournalEntrySocketOpenV1 {
1050                af,
1051                ty,
1052                pt,
1053                fd,
1054            }) => Self::SocketOpenV1 {
1055                af: af.into(),
1056                ty: ty.into(),
1057                pt: (pt.to_native()).try_into().unwrap_or(wasi::SockProto::Max),
1058                fd: fd.to_native(),
1059            },
1060            ArchivedJournalEntry::SocketPairV1(ArchivedJournalEntrySocketPairV1 { fd1, fd2 }) => {
1061                Self::SocketPairV1 {
1062                    fd1: fd1.to_native(),
1063                    fd2: fd2.to_native(),
1064                }
1065            }
1066            ArchivedJournalEntry::SocketListenV1(ArchivedJournalEntrySocketListenV1 {
1067                fd,
1068                backlog,
1069            }) => Self::SocketListenV1 {
1070                fd: fd.to_native(),
1071                backlog: backlog.to_native(),
1072            },
1073            ArchivedJournalEntry::SocketBindV1(ArchivedJournalEntrySocketBindV1 { fd, addr }) => {
1074                Self::SocketBindV1 {
1075                    fd: fd.to_native(),
1076                    addr: addr.as_socket_addr(),
1077                }
1078            }
1079            ArchivedJournalEntry::SocketConnectedV1(ArchivedJournalEntrySocketConnectedV1 {
1080                fd,
1081                local_addr,
1082                peer_addr,
1083            }) => Self::SocketConnectedV1 {
1084                fd: fd.to_native(),
1085                local_addr: local_addr.as_socket_addr(),
1086                peer_addr: peer_addr.as_socket_addr(),
1087            },
1088            ArchivedJournalEntry::SocketAcceptedV1(ArchivedJournalEntrySocketAcceptedV1 {
1089                listen_fd,
1090                fd,
1091                local_addr,
1092                peer_addr,
1093                fd_flags,
1094                nonblocking,
1095            }) => Self::SocketAcceptedV1 {
1096                listen_fd: listen_fd.to_native(),
1097                fd: fd.to_native(),
1098                local_addr: local_addr.as_socket_addr(),
1099                peer_addr: peer_addr.as_socket_addr(),
1100                fd_flags: wasi::Fdflags::from_bits_truncate(fd_flags.to_native()),
1101                non_blocking: *nonblocking,
1102            },
1103            ArchivedJournalEntry::SocketJoinIpv4MulticastV1(
1104                ArchivedJournalEntrySocketJoinIpv4MulticastV1 {
1105                    fd,
1106                    multiaddr,
1107                    iface,
1108                },
1109            ) => Self::SocketJoinIpv4MulticastV1 {
1110                fd: fd.to_native(),
1111                multiaddr: multiaddr.as_ipv4(),
1112                iface: iface.as_ipv4(),
1113            },
1114            ArchivedJournalEntry::SocketJoinIpv6MulticastV1(
1115                ArchivedJournalEntrySocketJoinIpv6MulticastV1 {
1116                    fd,
1117                    multiaddr,
1118                    iface,
1119                },
1120            ) => Self::SocketJoinIpv6MulticastV1 {
1121                fd: fd.to_native(),
1122                multi_addr: multiaddr.as_ipv6(),
1123                iface: iface.to_native(),
1124            },
1125            ArchivedJournalEntry::SocketLeaveIpv4MulticastV1(
1126                ArchivedJournalEntrySocketLeaveIpv4MulticastV1 {
1127                    fd,
1128                    multiaddr,
1129                    iface,
1130                },
1131            ) => Self::SocketLeaveIpv4MulticastV1 {
1132                fd: fd.to_native(),
1133                multi_addr: multiaddr.as_ipv4(),
1134                iface: iface.as_ipv4(),
1135            },
1136            ArchivedJournalEntry::SocketLeaveIpv6MulticastV1(
1137                ArchivedJournalEntrySocketLeaveIpv6MulticastV1 {
1138                    fd,
1139                    multiaddr,
1140                    iface,
1141                },
1142            ) => Self::SocketLeaveIpv6MulticastV1 {
1143                fd: fd.to_native(),
1144                multi_addr: multiaddr.as_ipv6(),
1145                iface: iface.to_native(),
1146            },
1147            ArchivedJournalEntry::SocketSendFileV1(ArchivedJournalEntrySocketSendFileV1 {
1148                socket_fd,
1149                file_fd,
1150                offset,
1151                count,
1152            }) => Self::SocketSendFileV1 {
1153                socket_fd: socket_fd.to_native(),
1154                file_fd: file_fd.to_native(),
1155                offset: offset.to_native(),
1156                count: count.to_native(),
1157            },
1158            ArchivedJournalEntry::SocketSendToV1(ArchivedJournalEntrySocketSendToV1 {
1159                fd,
1160                data,
1161                flags,
1162                addr,
1163                is_64bit,
1164            }) => Self::SocketSendToV1 {
1165                fd: fd.to_native(),
1166                data: data.as_ref().into(),
1167                flags: flags.to_native(),
1168                addr: addr.as_socket_addr(),
1169                is_64bit: *is_64bit,
1170            },
1171            ArchivedJournalEntry::SocketSendV1(ArchivedJournalEntrySocketSendV1 {
1172                fd,
1173                data,
1174                flags,
1175                is_64bit,
1176            }) => Self::SocketSendV1 {
1177                fd: fd.to_native(),
1178                data: data.as_ref().into(),
1179                flags: flags.to_native(),
1180                is_64bit: *is_64bit,
1181            },
1182            ArchivedJournalEntry::SocketSetOptFlagV1(ArchivedJournalEntrySocketSetOptFlagV1 {
1183                fd,
1184                opt,
1185                flag,
1186            }) => Self::SocketSetOptFlagV1 {
1187                fd: fd.to_native(),
1188                opt: opt.into(),
1189                flag: *flag,
1190            },
1191            ArchivedJournalEntry::SocketSetOptSizeV1(ArchivedJournalEntrySocketSetOptSizeV1 {
1192                fd,
1193                opt,
1194                size,
1195            }) => Self::SocketSetOptSizeV1 {
1196                fd: fd.to_native(),
1197                opt: opt.into(),
1198                size: size.to_native(),
1199            },
1200            ArchivedJournalEntry::SocketSetOptTimeV1(ArchivedJournalEntrySocketSetOptTimeV1 {
1201                fd,
1202                ty,
1203                time,
1204            }) => Self::SocketSetOptTimeV1 {
1205                fd: fd.to_native(),
1206                ty: ty.into(),
1207                time: time.as_ref().map(|time| (*time).into()),
1208            },
1209            ArchivedJournalEntry::SocketShutdownV1(ArchivedJournalEntrySocketShutdownV1 {
1210                fd,
1211                how,
1212            }) => Self::SocketShutdownV1 {
1213                fd: fd.to_native(),
1214                how: how.into(),
1215            },
1216            ArchivedJournalEntry::CreateEventV1(ArchivedJournalEntryCreateEventV1 {
1217                initial_val,
1218                flags,
1219                fd,
1220            }) => Self::CreateEventV1 {
1221                initial_val: initial_val.to_native(),
1222                flags: flags.to_native(),
1223                fd: fd.to_native(),
1224            },
1225        })
1226    }
1227}