Skip to main content

probius_mproto/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3#[cfg(all(not(feature = "std"), feature = "alloc"))]
4extern crate alloc;
5
6use core::convert::TryFrom;
7use mproto::{BaseLen, Compatible, Decode, DecodeCursor, DecodeError, DecodeResult, Encode, EncodeCursor, Lazy, Owned, max};
8
9#[cfg(any(feature = "std", feature = "alloc"))]
10#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
11pub struct SinkHandshake {
12    pub app_name: String,
13    pub session_id_hi: u64,
14    pub session_id_lo: u64,
15}
16
17pub struct SinkHandshakeLazy<'a> {
18    buffer: &'a [u8],
19    offset: usize,
20}
21
22pub struct SinkHandshakeGen<
23    AppName: Encode + Compatible<String>,
24> {
25    pub app_name: AppName,
26    pub session_id_hi: u64,
27    pub session_id_lo: u64,
28}
29
30impl<
31    AppName: Encode + Compatible<String>
32> Compatible<SinkHandshake> for SinkHandshakeGen<AppName> { }
33impl<
34    AppName: Encode + Compatible<String>
35> Compatible<SinkHandshakeGen<AppName>> for SinkHandshake { }
36
37impl<
38    AppName: Encode + Compatible<String>,
39> BaseLen for SinkHandshakeGen<AppName> {
40    const BASE_LEN: usize = 16 + AppName::BASE_LEN;
41}
42
43impl<
44    AppName: Encode + Compatible<String>,
45> Encode for SinkHandshakeGen<AppName> {
46    fn scratch_len(&self) -> usize {
47        self.app_name.scratch_len() + self.session_id_hi.scratch_len() + self.session_id_lo.scratch_len()
48    }
49
50    fn encode(&self, cursor: &mut EncodeCursor) {
51        self.app_name.encode(cursor);
52        self.session_id_hi.encode(cursor);
53        self.session_id_lo.encode(cursor);
54    }
55}
56
57#[cfg(any(feature = "std", feature = "alloc"))]
58impl Owned for SinkHandshake {
59    type Lazy<'a> = SinkHandshakeLazy<'a>;
60
61    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
62        TryFrom::try_from(lazy)
63    }
64}
65
66impl<'a> Lazy<'a> for SinkHandshakeLazy<'a> {
67    type Owned = SinkHandshake;
68}
69
70impl<'a> Compatible<SinkHandshakeLazy<'a>> for SinkHandshakeLazy<'a> { }
71#[cfg(any(feature = "std", feature = "alloc"))]
72impl<'a> Compatible<SinkHandshakeLazy<'a>> for SinkHandshake { }
73#[cfg(any(feature = "std", feature = "alloc"))]
74impl Compatible<SinkHandshake> for SinkHandshake { }
75#[cfg(any(feature = "std", feature = "alloc"))]
76impl<'a> Compatible<SinkHandshake> for SinkHandshakeLazy<'a> { }
77
78impl<'a> SinkHandshakeLazy<'a> {
79
80    pub fn app_name(&self) -> DecodeResult<&'a str> {
81        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
82    }
83
84    pub fn session_id_hi(&self) -> DecodeResult<u64> {
85        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
86    }
87
88    pub fn session_id_lo(&self) -> DecodeResult<u64> {
89        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16))
90    }
91}
92
93#[cfg(any(feature = "std", feature = "alloc"))]
94impl BaseLen for SinkHandshake {
95    const BASE_LEN: usize = 24;
96}
97
98impl Encode for SinkHandshake {
99    fn scratch_len(&self) -> usize {
100        self.app_name.scratch_len() + self.session_id_hi.scratch_len() + self.session_id_lo.scratch_len()
101    }
102
103    fn encode(&self, cursor: &mut EncodeCursor) {
104        self.app_name.encode(cursor);
105        self.session_id_hi.encode(cursor);
106        self.session_id_lo.encode(cursor);
107    }
108}
109
110#[cfg(any(feature = "std", feature = "alloc"))]
111impl<'a> Decode<'a> for SinkHandshake {
112    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
113        let app_name = Decode::decode(cursor)?;
114        let session_id_hi = Decode::decode(cursor)?;
115        let session_id_lo = Decode::decode(cursor)?;
116
117        Ok(SinkHandshake {
118            app_name,
119            session_id_hi,
120            session_id_lo,
121        })
122    }
123}
124
125impl<'a> BaseLen for SinkHandshakeLazy<'a> {
126    const BASE_LEN: usize = 24;
127}
128
129impl<'a> Encode for SinkHandshakeLazy<'a> {
130    fn scratch_len(&self) -> usize {
131        let app_name: &'a str = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
132        let session_id_hi: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
133        let session_id_lo: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
134        app_name.scratch_len() + session_id_hi.scratch_len() + session_id_lo.scratch_len()
135    }
136
137    fn encode(&self, cursor: &mut EncodeCursor) {
138        let app_name: &'a str = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
139        let session_id_hi: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
140        let session_id_lo: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
141        app_name.encode(cursor);
142        session_id_hi.encode(cursor);
143        session_id_lo.encode(cursor);
144    }
145}
146
147impl<'a> Decode<'a> for SinkHandshakeLazy<'a> {
148    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
149        let offset = cursor.offset();
150        cursor.advance(Self::BASE_LEN);
151        Ok(SinkHandshakeLazy {
152            buffer: cursor.buffer(),
153            offset,
154        })
155    }
156}
157
158#[cfg(any(feature = "std", feature = "alloc"))]
159impl<'a> TryFrom<SinkHandshakeLazy<'a>> for SinkHandshake {
160    type Error = DecodeError;
161
162    fn try_from(other: SinkHandshakeLazy<'a>) -> Result<Self, Self::Error> {
163        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
164        Decode::decode(&cursor)
165    }
166}
167
168impl<'a> Copy for SinkHandshakeLazy<'a> { }
169
170impl<'a> Clone for SinkHandshakeLazy<'a> {
171    fn clone(&self) -> Self {
172        Self {
173            buffer: self.buffer,
174            offset: self.offset,
175        }
176    }
177}
178
179impl<'a> core::fmt::Debug for SinkHandshakeLazy<'a> {
180    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
181        f.debug_struct("SinkHandshakeLazy")
182            .finish()
183    }
184}
185
186impl<'a> PartialEq for SinkHandshakeLazy<'a> {
187    fn eq(&self, other: &Self) -> bool {
188        self.app_name().unwrap() == other.app_name().unwrap()
189            && self.session_id_hi().unwrap() == other.session_id_hi().unwrap()&& self.session_id_lo().unwrap() == other.session_id_lo().unwrap()
190    }
191}
192
193#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
194pub struct SourceId {
195    pub source: u64,
196}
197
198pub struct SourceIdLazy<'a> {
199    buffer: &'a [u8],
200    offset: usize,
201}
202
203pub struct SourceIdGen<> {
204    pub source: u64,
205}
206
207impl<> Compatible<SourceId> for SourceIdGen<> { }
208impl<> Compatible<SourceIdGen<>> for SourceId { }
209
210impl<> BaseLen for SourceIdGen<> {
211    const BASE_LEN: usize = 8;
212}
213
214impl<> Encode for SourceIdGen<> {
215    fn scratch_len(&self) -> usize {
216        self.source.scratch_len()
217    }
218
219    fn encode(&self, cursor: &mut EncodeCursor) {
220        self.source.encode(cursor);
221    }
222}
223
224impl Owned for SourceId {
225    type Lazy<'a> = SourceIdLazy<'a>;
226
227    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
228        TryFrom::try_from(lazy)
229    }
230}
231
232impl<'a> Lazy<'a> for SourceIdLazy<'a> {
233    type Owned = SourceId;
234}
235
236impl<'a> Compatible<SourceIdLazy<'a>> for SourceIdLazy<'a> { }
237impl<'a> Compatible<SourceIdLazy<'a>> for SourceId { }
238impl Compatible<SourceId> for SourceId { }
239impl<'a> Compatible<SourceId> for SourceIdLazy<'a> { }
240
241impl<'a> SourceIdLazy<'a> {
242
243    pub fn source(&self) -> DecodeResult<u64> {
244        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
245    }
246}
247
248impl BaseLen for SourceId {
249    const BASE_LEN: usize = 8;
250}
251
252impl Encode for SourceId {
253    fn scratch_len(&self) -> usize {
254        self.source.scratch_len()
255    }
256
257    fn encode(&self, cursor: &mut EncodeCursor) {
258        self.source.encode(cursor);
259    }
260}
261
262impl<'a> Decode<'a> for SourceId {
263    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
264        let source = Decode::decode(cursor)?;
265
266        Ok(SourceId {
267            source,
268        })
269    }
270}
271
272impl<'a> BaseLen for SourceIdLazy<'a> {
273    const BASE_LEN: usize = 8;
274}
275
276impl<'a> Encode for SourceIdLazy<'a> {
277    fn scratch_len(&self) -> usize {
278        let source: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
279        source.scratch_len()
280    }
281
282    fn encode(&self, cursor: &mut EncodeCursor) {
283        let source: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
284        source.encode(cursor);
285    }
286}
287
288impl<'a> Decode<'a> for SourceIdLazy<'a> {
289    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
290        let offset = cursor.offset();
291        cursor.advance(Self::BASE_LEN);
292        Ok(SourceIdLazy {
293            buffer: cursor.buffer(),
294            offset,
295        })
296    }
297}
298
299impl<'a> TryFrom<SourceIdLazy<'a>> for SourceId {
300    type Error = DecodeError;
301
302    fn try_from(other: SourceIdLazy<'a>) -> Result<Self, Self::Error> {
303        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
304        Decode::decode(&cursor)
305    }
306}
307
308impl<'a> Copy for SourceIdLazy<'a> { }
309
310impl<'a> Clone for SourceIdLazy<'a> {
311    fn clone(&self) -> Self {
312        Self {
313            buffer: self.buffer,
314            offset: self.offset,
315        }
316    }
317}
318
319impl<'a> core::fmt::Debug for SourceIdLazy<'a> {
320    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
321        f.debug_struct("SourceIdLazy")
322            .finish()
323    }
324}
325
326impl<'a> PartialEq for SourceIdLazy<'a> {
327    fn eq(&self, other: &Self) -> bool {
328        self.source().unwrap() == other.source().unwrap()
329    }
330}
331
332#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
333pub struct GlobalSourceId {
334    pub session: u64,
335    pub source: SourceId,
336}
337
338pub struct GlobalSourceIdLazy<'a> {
339    buffer: &'a [u8],
340    offset: usize,
341}
342
343pub struct GlobalSourceIdGen<
344    Source: Encode + Compatible<SourceId>,
345> {
346    pub session: u64,
347    pub source: Source,
348}
349
350impl<
351    Source: Encode + Compatible<SourceId>
352> Compatible<GlobalSourceId> for GlobalSourceIdGen<Source> { }
353impl<
354    Source: Encode + Compatible<SourceId>
355> Compatible<GlobalSourceIdGen<Source>> for GlobalSourceId { }
356
357impl<
358    Source: Encode + Compatible<SourceId>,
359> BaseLen for GlobalSourceIdGen<Source> {
360    const BASE_LEN: usize = 8 + Source::BASE_LEN;
361}
362
363impl<
364    Source: Encode + Compatible<SourceId>,
365> Encode for GlobalSourceIdGen<Source> {
366    fn scratch_len(&self) -> usize {
367        self.session.scratch_len() + self.source.scratch_len()
368    }
369
370    fn encode(&self, cursor: &mut EncodeCursor) {
371        self.session.encode(cursor);
372        self.source.encode(cursor);
373    }
374}
375
376impl Owned for GlobalSourceId {
377    type Lazy<'a> = GlobalSourceIdLazy<'a>;
378
379    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
380        TryFrom::try_from(lazy)
381    }
382}
383
384impl<'a> Lazy<'a> for GlobalSourceIdLazy<'a> {
385    type Owned = GlobalSourceId;
386}
387
388impl<'a> Compatible<GlobalSourceIdLazy<'a>> for GlobalSourceIdLazy<'a> { }
389impl<'a> Compatible<GlobalSourceIdLazy<'a>> for GlobalSourceId { }
390impl Compatible<GlobalSourceId> for GlobalSourceId { }
391impl<'a> Compatible<GlobalSourceId> for GlobalSourceIdLazy<'a> { }
392
393impl<'a> GlobalSourceIdLazy<'a> {
394
395    pub fn session(&self) -> DecodeResult<u64> {
396        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
397    }
398
399    pub fn source(&self) -> DecodeResult<SourceIdLazy<'a>> {
400        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
401    }
402}
403
404impl BaseLen for GlobalSourceId {
405    const BASE_LEN: usize = 16;
406}
407
408impl Encode for GlobalSourceId {
409    fn scratch_len(&self) -> usize {
410        self.session.scratch_len() + self.source.scratch_len()
411    }
412
413    fn encode(&self, cursor: &mut EncodeCursor) {
414        self.session.encode(cursor);
415        self.source.encode(cursor);
416    }
417}
418
419impl<'a> Decode<'a> for GlobalSourceId {
420    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
421        let session = Decode::decode(cursor)?;
422        let source = Decode::decode(cursor)?;
423
424        Ok(GlobalSourceId {
425            session,
426            source,
427        })
428    }
429}
430
431impl<'a> BaseLen for GlobalSourceIdLazy<'a> {
432    const BASE_LEN: usize = 16;
433}
434
435impl<'a> Encode for GlobalSourceIdLazy<'a> {
436    fn scratch_len(&self) -> usize {
437        let session: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
438        let source: SourceIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
439        session.scratch_len() + source.scratch_len()
440    }
441
442    fn encode(&self, cursor: &mut EncodeCursor) {
443        let session: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
444        let source: SourceIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
445        session.encode(cursor);
446        source.encode(cursor);
447    }
448}
449
450impl<'a> Decode<'a> for GlobalSourceIdLazy<'a> {
451    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
452        let offset = cursor.offset();
453        cursor.advance(Self::BASE_LEN);
454        Ok(GlobalSourceIdLazy {
455            buffer: cursor.buffer(),
456            offset,
457        })
458    }
459}
460
461impl<'a> TryFrom<GlobalSourceIdLazy<'a>> for GlobalSourceId {
462    type Error = DecodeError;
463
464    fn try_from(other: GlobalSourceIdLazy<'a>) -> Result<Self, Self::Error> {
465        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
466        Decode::decode(&cursor)
467    }
468}
469
470impl<'a> Copy for GlobalSourceIdLazy<'a> { }
471
472impl<'a> Clone for GlobalSourceIdLazy<'a> {
473    fn clone(&self) -> Self {
474        Self {
475            buffer: self.buffer,
476            offset: self.offset,
477        }
478    }
479}
480
481impl<'a> core::fmt::Debug for GlobalSourceIdLazy<'a> {
482    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
483        f.debug_struct("GlobalSourceIdLazy")
484            .finish()
485    }
486}
487
488impl<'a> PartialEq for GlobalSourceIdLazy<'a> {
489    fn eq(&self, other: &Self) -> bool {
490        self.session().unwrap() == other.session().unwrap()
491            && self.source().unwrap() == other.source().unwrap()
492    }
493}
494
495#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
496pub struct TraceCallerId {
497    pub event_id: EventId,
498    pub op_index: u16,
499}
500
501pub struct TraceCallerIdLazy<'a> {
502    buffer: &'a [u8],
503    offset: usize,
504}
505
506pub struct TraceCallerIdGen<
507    TEventId: Encode + Compatible<EventId>,
508> {
509    pub event_id: TEventId,
510    pub op_index: u16,
511}
512
513impl<
514    TEventId: Encode + Compatible<EventId>
515> Compatible<TraceCallerId> for TraceCallerIdGen<TEventId> { }
516impl<
517    TEventId: Encode + Compatible<EventId>
518> Compatible<TraceCallerIdGen<TEventId>> for TraceCallerId { }
519
520impl<
521    TEventId: Encode + Compatible<EventId>,
522> BaseLen for TraceCallerIdGen<TEventId> {
523    const BASE_LEN: usize = 2 + TEventId::BASE_LEN;
524}
525
526impl<
527    TEventId: Encode + Compatible<EventId>,
528> Encode for TraceCallerIdGen<TEventId> {
529    fn scratch_len(&self) -> usize {
530        self.event_id.scratch_len() + self.op_index.scratch_len()
531    }
532
533    fn encode(&self, cursor: &mut EncodeCursor) {
534        self.event_id.encode(cursor);
535        self.op_index.encode(cursor);
536    }
537}
538
539impl Owned for TraceCallerId {
540    type Lazy<'a> = TraceCallerIdLazy<'a>;
541
542    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
543        TryFrom::try_from(lazy)
544    }
545}
546
547impl<'a> Lazy<'a> for TraceCallerIdLazy<'a> {
548    type Owned = TraceCallerId;
549}
550
551impl<'a> Compatible<TraceCallerIdLazy<'a>> for TraceCallerIdLazy<'a> { }
552impl<'a> Compatible<TraceCallerIdLazy<'a>> for TraceCallerId { }
553impl Compatible<TraceCallerId> for TraceCallerId { }
554impl<'a> Compatible<TraceCallerId> for TraceCallerIdLazy<'a> { }
555
556impl<'a> TraceCallerIdLazy<'a> {
557
558    pub fn event_id(&self) -> DecodeResult<EventIdLazy<'a>> {
559        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
560    }
561
562    pub fn op_index(&self) -> DecodeResult<u16> {
563        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18))
564    }
565}
566
567impl BaseLen for TraceCallerId {
568    const BASE_LEN: usize = 20;
569}
570
571impl Encode for TraceCallerId {
572    fn scratch_len(&self) -> usize {
573        self.event_id.scratch_len() + self.op_index.scratch_len()
574    }
575
576    fn encode(&self, cursor: &mut EncodeCursor) {
577        self.event_id.encode(cursor);
578        self.op_index.encode(cursor);
579    }
580}
581
582impl<'a> Decode<'a> for TraceCallerId {
583    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
584        let event_id = Decode::decode(cursor)?;
585        let op_index = Decode::decode(cursor)?;
586
587        Ok(TraceCallerId {
588            event_id,
589            op_index,
590        })
591    }
592}
593
594impl<'a> BaseLen for TraceCallerIdLazy<'a> {
595    const BASE_LEN: usize = 20;
596}
597
598impl<'a> Encode for TraceCallerIdLazy<'a> {
599    fn scratch_len(&self) -> usize {
600        let event_id: EventIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
601        let op_index: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18)).unwrap();
602        event_id.scratch_len() + op_index.scratch_len()
603    }
604
605    fn encode(&self, cursor: &mut EncodeCursor) {
606        let event_id: EventIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
607        let op_index: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18)).unwrap();
608        event_id.encode(cursor);
609        op_index.encode(cursor);
610    }
611}
612
613impl<'a> Decode<'a> for TraceCallerIdLazy<'a> {
614    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
615        let offset = cursor.offset();
616        cursor.advance(Self::BASE_LEN);
617        Ok(TraceCallerIdLazy {
618            buffer: cursor.buffer(),
619            offset,
620        })
621    }
622}
623
624impl<'a> TryFrom<TraceCallerIdLazy<'a>> for TraceCallerId {
625    type Error = DecodeError;
626
627    fn try_from(other: TraceCallerIdLazy<'a>) -> Result<Self, Self::Error> {
628        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
629        Decode::decode(&cursor)
630    }
631}
632
633impl<'a> Copy for TraceCallerIdLazy<'a> { }
634
635impl<'a> Clone for TraceCallerIdLazy<'a> {
636    fn clone(&self) -> Self {
637        Self {
638            buffer: self.buffer,
639            offset: self.offset,
640        }
641    }
642}
643
644impl<'a> core::fmt::Debug for TraceCallerIdLazy<'a> {
645    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
646        f.debug_struct("TraceCallerIdLazy")
647            .finish()
648    }
649}
650
651impl<'a> PartialEq for TraceCallerIdLazy<'a> {
652    fn eq(&self, other: &Self) -> bool {
653        self.event_id().unwrap() == other.event_id().unwrap()
654            && self.op_index().unwrap() == other.op_index().unwrap()
655    }
656}
657
658#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
659pub struct EventSeq {
660    pub seq: u16,
661}
662
663pub struct EventSeqLazy<'a> {
664    buffer: &'a [u8],
665    offset: usize,
666}
667
668pub struct EventSeqGen<> {
669    pub seq: u16,
670}
671
672impl<> Compatible<EventSeq> for EventSeqGen<> { }
673impl<> Compatible<EventSeqGen<>> for EventSeq { }
674
675impl<> BaseLen for EventSeqGen<> {
676    const BASE_LEN: usize = 2;
677}
678
679impl<> Encode for EventSeqGen<> {
680    fn scratch_len(&self) -> usize {
681        self.seq.scratch_len()
682    }
683
684    fn encode(&self, cursor: &mut EncodeCursor) {
685        self.seq.encode(cursor);
686    }
687}
688
689impl Owned for EventSeq {
690    type Lazy<'a> = EventSeqLazy<'a>;
691
692    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
693        TryFrom::try_from(lazy)
694    }
695}
696
697impl<'a> Lazy<'a> for EventSeqLazy<'a> {
698    type Owned = EventSeq;
699}
700
701impl<'a> Compatible<EventSeqLazy<'a>> for EventSeqLazy<'a> { }
702impl<'a> Compatible<EventSeqLazy<'a>> for EventSeq { }
703impl Compatible<EventSeq> for EventSeq { }
704impl<'a> Compatible<EventSeq> for EventSeqLazy<'a> { }
705
706impl<'a> EventSeqLazy<'a> {
707
708    pub fn seq(&self) -> DecodeResult<u16> {
709        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
710    }
711}
712
713impl BaseLen for EventSeq {
714    const BASE_LEN: usize = 2;
715}
716
717impl Encode for EventSeq {
718    fn scratch_len(&self) -> usize {
719        self.seq.scratch_len()
720    }
721
722    fn encode(&self, cursor: &mut EncodeCursor) {
723        self.seq.encode(cursor);
724    }
725}
726
727impl<'a> Decode<'a> for EventSeq {
728    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
729        let seq = Decode::decode(cursor)?;
730
731        Ok(EventSeq {
732            seq,
733        })
734    }
735}
736
737impl<'a> BaseLen for EventSeqLazy<'a> {
738    const BASE_LEN: usize = 2;
739}
740
741impl<'a> Encode for EventSeqLazy<'a> {
742    fn scratch_len(&self) -> usize {
743        let seq: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
744        seq.scratch_len()
745    }
746
747    fn encode(&self, cursor: &mut EncodeCursor) {
748        let seq: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
749        seq.encode(cursor);
750    }
751}
752
753impl<'a> Decode<'a> for EventSeqLazy<'a> {
754    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
755        let offset = cursor.offset();
756        cursor.advance(Self::BASE_LEN);
757        Ok(EventSeqLazy {
758            buffer: cursor.buffer(),
759            offset,
760        })
761    }
762}
763
764impl<'a> TryFrom<EventSeqLazy<'a>> for EventSeq {
765    type Error = DecodeError;
766
767    fn try_from(other: EventSeqLazy<'a>) -> Result<Self, Self::Error> {
768        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
769        Decode::decode(&cursor)
770    }
771}
772
773impl<'a> Copy for EventSeqLazy<'a> { }
774
775impl<'a> Clone for EventSeqLazy<'a> {
776    fn clone(&self) -> Self {
777        Self {
778            buffer: self.buffer,
779            offset: self.offset,
780        }
781    }
782}
783
784impl<'a> core::fmt::Debug for EventSeqLazy<'a> {
785    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
786        f.debug_struct("EventSeqLazy")
787            .finish()
788    }
789}
790
791impl<'a> PartialEq for EventSeqLazy<'a> {
792    fn eq(&self, other: &Self) -> bool {
793        self.seq().unwrap() == other.seq().unwrap()
794    }
795}
796
797#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
798pub struct EventId {
799    pub source: SourceId,
800    pub timestamp_nanos: u64,
801    pub seq: EventSeq,
802}
803
804pub struct EventIdLazy<'a> {
805    buffer: &'a [u8],
806    offset: usize,
807}
808
809pub struct EventIdGen<
810    Source: Encode + Compatible<SourceId>,
811    Seq: Encode + Compatible<EventSeq>,
812> {
813    pub source: Source,
814    pub timestamp_nanos: u64,
815    pub seq: Seq,
816}
817
818impl<
819    Source: Encode + Compatible<SourceId>,
820    Seq: Encode + Compatible<EventSeq>
821> Compatible<EventId> for EventIdGen<Source, Seq> { }
822impl<
823    Source: Encode + Compatible<SourceId>,
824    Seq: Encode + Compatible<EventSeq>
825> Compatible<EventIdGen<Source, Seq>> for EventId { }
826
827impl<
828    Source: Encode + Compatible<SourceId>,
829    Seq: Encode + Compatible<EventSeq>,
830> BaseLen for EventIdGen<Source, Seq> {
831    const BASE_LEN: usize = 8 + Source::BASE_LEN + Seq::BASE_LEN;
832}
833
834impl<
835    Source: Encode + Compatible<SourceId>,
836    Seq: Encode + Compatible<EventSeq>,
837> Encode for EventIdGen<Source, Seq> {
838    fn scratch_len(&self) -> usize {
839        self.source.scratch_len() + self.timestamp_nanos.scratch_len() + self.seq.scratch_len()
840    }
841
842    fn encode(&self, cursor: &mut EncodeCursor) {
843        self.source.encode(cursor);
844        self.timestamp_nanos.encode(cursor);
845        self.seq.encode(cursor);
846    }
847}
848
849impl Owned for EventId {
850    type Lazy<'a> = EventIdLazy<'a>;
851
852    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
853        TryFrom::try_from(lazy)
854    }
855}
856
857impl<'a> Lazy<'a> for EventIdLazy<'a> {
858    type Owned = EventId;
859}
860
861impl<'a> Compatible<EventIdLazy<'a>> for EventIdLazy<'a> { }
862impl<'a> Compatible<EventIdLazy<'a>> for EventId { }
863impl Compatible<EventId> for EventId { }
864impl<'a> Compatible<EventId> for EventIdLazy<'a> { }
865
866impl<'a> EventIdLazy<'a> {
867
868    pub fn source(&self) -> DecodeResult<SourceIdLazy<'a>> {
869        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
870    }
871
872    pub fn timestamp_nanos(&self) -> DecodeResult<u64> {
873        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
874    }
875
876    pub fn seq(&self) -> DecodeResult<EventSeqLazy<'a>> {
877        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16))
878    }
879}
880
881impl BaseLen for EventId {
882    const BASE_LEN: usize = 18;
883}
884
885impl Encode for EventId {
886    fn scratch_len(&self) -> usize {
887        self.source.scratch_len() + self.timestamp_nanos.scratch_len() + self.seq.scratch_len()
888    }
889
890    fn encode(&self, cursor: &mut EncodeCursor) {
891        self.source.encode(cursor);
892        self.timestamp_nanos.encode(cursor);
893        self.seq.encode(cursor);
894    }
895}
896
897impl<'a> Decode<'a> for EventId {
898    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
899        let source = Decode::decode(cursor)?;
900        let timestamp_nanos = Decode::decode(cursor)?;
901        let seq = Decode::decode(cursor)?;
902
903        Ok(EventId {
904            source,
905            timestamp_nanos,
906            seq,
907        })
908    }
909}
910
911impl<'a> BaseLen for EventIdLazy<'a> {
912    const BASE_LEN: usize = 18;
913}
914
915impl<'a> Encode for EventIdLazy<'a> {
916    fn scratch_len(&self) -> usize {
917        let source: SourceIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
918        let timestamp_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
919        let seq: EventSeqLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
920        source.scratch_len() + timestamp_nanos.scratch_len() + seq.scratch_len()
921    }
922
923    fn encode(&self, cursor: &mut EncodeCursor) {
924        let source: SourceIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
925        let timestamp_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
926        let seq: EventSeqLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
927        source.encode(cursor);
928        timestamp_nanos.encode(cursor);
929        seq.encode(cursor);
930    }
931}
932
933impl<'a> Decode<'a> for EventIdLazy<'a> {
934    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
935        let offset = cursor.offset();
936        cursor.advance(Self::BASE_LEN);
937        Ok(EventIdLazy {
938            buffer: cursor.buffer(),
939            offset,
940        })
941    }
942}
943
944impl<'a> TryFrom<EventIdLazy<'a>> for EventId {
945    type Error = DecodeError;
946
947    fn try_from(other: EventIdLazy<'a>) -> Result<Self, Self::Error> {
948        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
949        Decode::decode(&cursor)
950    }
951}
952
953impl<'a> Copy for EventIdLazy<'a> { }
954
955impl<'a> Clone for EventIdLazy<'a> {
956    fn clone(&self) -> Self {
957        Self {
958            buffer: self.buffer,
959            offset: self.offset,
960        }
961    }
962}
963
964impl<'a> core::fmt::Debug for EventIdLazy<'a> {
965    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
966        f.debug_struct("EventIdLazy")
967            .finish()
968    }
969}
970
971impl<'a> PartialEq for EventIdLazy<'a> {
972    fn eq(&self, other: &Self) -> bool {
973        self.source().unwrap() == other.source().unwrap()
974            && self.timestamp_nanos().unwrap() == other.timestamp_nanos().unwrap()&& self.seq().unwrap() == other.seq().unwrap()
975    }
976}
977
978#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
979pub struct EventHeader {
980    pub id: EventId,
981    pub len: u16,
982    pub kind: EventKind,
983}
984
985pub struct EventHeaderLazy<'a> {
986    buffer: &'a [u8],
987    offset: usize,
988}
989
990pub struct EventHeaderGen<
991    Id: Encode + Compatible<EventId>,
992    Kind: Encode + Compatible<EventKind>,
993> {
994    pub id: Id,
995    pub len: u16,
996    pub kind: Kind,
997}
998
999impl<
1000    Id: Encode + Compatible<EventId>,
1001    Kind: Encode + Compatible<EventKind>
1002> Compatible<EventHeader> for EventHeaderGen<Id, Kind> { }
1003impl<
1004    Id: Encode + Compatible<EventId>,
1005    Kind: Encode + Compatible<EventKind>
1006> Compatible<EventHeaderGen<Id, Kind>> for EventHeader { }
1007
1008impl<
1009    Id: Encode + Compatible<EventId>,
1010    Kind: Encode + Compatible<EventKind>,
1011> BaseLen for EventHeaderGen<Id, Kind> {
1012    const BASE_LEN: usize = 2 + Id::BASE_LEN + Kind::BASE_LEN;
1013}
1014
1015impl<
1016    Id: Encode + Compatible<EventId>,
1017    Kind: Encode + Compatible<EventKind>,
1018> Encode for EventHeaderGen<Id, Kind> {
1019    fn scratch_len(&self) -> usize {
1020        self.id.scratch_len() + self.len.scratch_len() + self.kind.scratch_len()
1021    }
1022
1023    fn encode(&self, cursor: &mut EncodeCursor) {
1024        self.id.encode(cursor);
1025        self.len.encode(cursor);
1026        self.kind.encode(cursor);
1027    }
1028}
1029
1030impl Owned for EventHeader {
1031    type Lazy<'a> = EventHeaderLazy<'a>;
1032
1033    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1034        TryFrom::try_from(lazy)
1035    }
1036}
1037
1038impl<'a> Lazy<'a> for EventHeaderLazy<'a> {
1039    type Owned = EventHeader;
1040}
1041
1042impl<'a> Compatible<EventHeaderLazy<'a>> for EventHeaderLazy<'a> { }
1043impl<'a> Compatible<EventHeaderLazy<'a>> for EventHeader { }
1044impl Compatible<EventHeader> for EventHeader { }
1045impl<'a> Compatible<EventHeader> for EventHeaderLazy<'a> { }
1046
1047impl<'a> EventHeaderLazy<'a> {
1048
1049    pub fn id(&self) -> DecodeResult<EventIdLazy<'a>> {
1050        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
1051    }
1052
1053    pub fn len(&self) -> DecodeResult<u16> {
1054        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18))
1055    }
1056
1057    pub fn kind(&self) -> DecodeResult<EventKindLazy> {
1058        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 20))
1059    }
1060}
1061
1062impl BaseLen for EventHeader {
1063    const BASE_LEN: usize = 21 + max(max(max(max(max(0, 0), 0), 0), 0), 0);
1064}
1065
1066impl Encode for EventHeader {
1067    fn scratch_len(&self) -> usize {
1068        self.id.scratch_len() + self.len.scratch_len() + self.kind.scratch_len()
1069    }
1070
1071    fn encode(&self, cursor: &mut EncodeCursor) {
1072        self.id.encode(cursor);
1073        self.len.encode(cursor);
1074        self.kind.encode(cursor);
1075    }
1076}
1077
1078impl<'a> Decode<'a> for EventHeader {
1079    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1080        let id = Decode::decode(cursor)?;
1081        let len = Decode::decode(cursor)?;
1082        let kind = Decode::decode(cursor)?;
1083
1084        Ok(EventHeader {
1085            id,
1086            len,
1087            kind,
1088        })
1089    }
1090}
1091
1092impl<'a> BaseLen for EventHeaderLazy<'a> {
1093    const BASE_LEN: usize = 21 + max(max(max(max(max(0, 0), 0), 0), 0), 0);
1094}
1095
1096impl<'a> Encode for EventHeaderLazy<'a> {
1097    fn scratch_len(&self) -> usize {
1098        let id: EventIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1099        let len: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18)).unwrap();
1100        let kind: EventKindLazy = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 20)).unwrap();
1101        id.scratch_len() + len.scratch_len() + kind.scratch_len()
1102    }
1103
1104    fn encode(&self, cursor: &mut EncodeCursor) {
1105        let id: EventIdLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1106        let len: u16 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 18)).unwrap();
1107        let kind: EventKindLazy = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 20)).unwrap();
1108        id.encode(cursor);
1109        len.encode(cursor);
1110        kind.encode(cursor);
1111    }
1112}
1113
1114impl<'a> Decode<'a> for EventHeaderLazy<'a> {
1115    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1116        let offset = cursor.offset();
1117        cursor.advance(Self::BASE_LEN);
1118        Ok(EventHeaderLazy {
1119            buffer: cursor.buffer(),
1120            offset,
1121        })
1122    }
1123}
1124
1125impl<'a> TryFrom<EventHeaderLazy<'a>> for EventHeader {
1126    type Error = DecodeError;
1127
1128    fn try_from(other: EventHeaderLazy<'a>) -> Result<Self, Self::Error> {
1129        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
1130        Decode::decode(&cursor)
1131    }
1132}
1133
1134impl<'a> Copy for EventHeaderLazy<'a> { }
1135
1136impl<'a> Clone for EventHeaderLazy<'a> {
1137    fn clone(&self) -> Self {
1138        Self {
1139            buffer: self.buffer,
1140            offset: self.offset,
1141        }
1142    }
1143}
1144
1145impl<'a> core::fmt::Debug for EventHeaderLazy<'a> {
1146    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1147        f.debug_struct("EventHeaderLazy")
1148            .finish()
1149    }
1150}
1151
1152impl<'a> PartialEq for EventHeaderLazy<'a> {
1153    fn eq(&self, other: &Self) -> bool {
1154        self.id().unwrap() == other.id().unwrap()
1155            && self.len().unwrap() == other.len().unwrap()&& self.kind().unwrap() == other.kind().unwrap()
1156    }
1157}
1158
1159#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
1160pub enum EventKind {
1161    CreateSource,
1162    DeleteSource,
1163    Trace,
1164    TraceAggregate,
1165    TraceAggregateDelta,
1166}
1167
1168#[derive(Clone)]
1169pub enum EventKindLazy {
1170    CreateSource,
1171    DeleteSource,
1172    Trace,
1173    TraceAggregate,
1174    TraceAggregateDelta,
1175}
1176
1177impl Compatible<EventKindLazy> for EventKindLazy { }
1178impl Compatible<EventKindLazy> for EventKind { }
1179impl Compatible<EventKind> for EventKindLazy { }
1180impl Compatible<EventKind> for EventKind { }
1181
1182impl Owned for EventKind {
1183    type Lazy<'a> = EventKindLazy;
1184
1185    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1186        TryFrom::try_from(lazy)
1187    }
1188}
1189
1190impl<'a> Lazy<'a> for EventKindLazy {
1191    type Owned = EventKind;
1192}
1193
1194impl BaseLen for EventKind {
1195    const BASE_LEN: usize = 1 + max(max(max(max(max(0, 0), 0), 0), 0), 0);
1196}
1197
1198impl Encode for EventKind {
1199    fn scratch_len(&self) -> usize {
1200        match self {
1201            EventKind::CreateSource => 0,
1202            EventKind::DeleteSource => 0,
1203            EventKind::Trace => 0,
1204            EventKind::TraceAggregate => 0,
1205            EventKind::TraceAggregateDelta => 0,
1206        }
1207    }
1208
1209    fn encode(&self, cursor: &mut EncodeCursor) {
1210        match self {
1211            EventKind::CreateSource => {
1212                cursor.base(1)[0] = 0;
1213                cursor.base(Self::BASE_LEN - 1).fill(0);
1214            }
1215            EventKind::DeleteSource => {
1216                cursor.base(1)[0] = 1;
1217                cursor.base(Self::BASE_LEN - 1).fill(0);
1218            }
1219            EventKind::Trace => {
1220                cursor.base(1)[0] = 2;
1221                cursor.base(Self::BASE_LEN - 1).fill(0);
1222            }
1223            EventKind::TraceAggregate => {
1224                cursor.base(1)[0] = 3;
1225                cursor.base(Self::BASE_LEN - 1).fill(0);
1226            }
1227            EventKind::TraceAggregateDelta => {
1228                cursor.base(1)[0] = 4;
1229                cursor.base(Self::BASE_LEN - 1).fill(0);
1230            }
1231        }
1232    }
1233}
1234
1235impl<'a> Decode<'a> for EventKind {
1236    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1237        let variant = cursor.base(1)[0];
1238        match variant {
1239            0 => {
1240                cursor.advance(Self::BASE_LEN - 1);
1241                Ok(EventKind::CreateSource)
1242            }
1243            1 => {
1244                cursor.advance(Self::BASE_LEN - 1);
1245                Ok(EventKind::DeleteSource)
1246            }
1247            2 => {
1248                cursor.advance(Self::BASE_LEN - 1);
1249                Ok(EventKind::Trace)
1250            }
1251            3 => {
1252                cursor.advance(Self::BASE_LEN - 1);
1253                Ok(EventKind::TraceAggregate)
1254            }
1255            4 => {
1256                cursor.advance(Self::BASE_LEN - 1);
1257                Ok(EventKind::TraceAggregateDelta)
1258            }
1259            _ => { Err(DecodeError) }
1260        }
1261    }
1262}
1263
1264impl BaseLen for EventKindLazy {
1265    const BASE_LEN: usize = 1 + max(max(max(max(max(0, 0), 0), 0), 0), 0);
1266}
1267
1268impl Encode for EventKindLazy {
1269    fn scratch_len(&self) -> usize {
1270        match self {
1271            EventKindLazy::CreateSource => 0,
1272            EventKindLazy::DeleteSource => 0,
1273            EventKindLazy::Trace => 0,
1274            EventKindLazy::TraceAggregate => 0,
1275            EventKindLazy::TraceAggregateDelta => 0,
1276        }
1277    }
1278
1279    fn encode(&self, cursor: &mut EncodeCursor) {
1280        match self {
1281            EventKindLazy::CreateSource => {
1282                cursor.base(1)[0] = 0;
1283                cursor.base(Self::BASE_LEN - 1).fill(0);
1284            }
1285            EventKindLazy::DeleteSource => {
1286                cursor.base(1)[0] = 1;
1287                cursor.base(Self::BASE_LEN - 1).fill(0);
1288            }
1289            EventKindLazy::Trace => {
1290                cursor.base(1)[0] = 2;
1291                cursor.base(Self::BASE_LEN - 1).fill(0);
1292            }
1293            EventKindLazy::TraceAggregate => {
1294                cursor.base(1)[0] = 3;
1295                cursor.base(Self::BASE_LEN - 1).fill(0);
1296            }
1297            EventKindLazy::TraceAggregateDelta => {
1298                cursor.base(1)[0] = 4;
1299                cursor.base(Self::BASE_LEN - 1).fill(0);
1300            }
1301        }
1302    }
1303}
1304
1305impl<'a> Decode<'a> for EventKindLazy {
1306    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1307        let variant = cursor.base(1)[0];
1308        match variant {
1309            0 => {
1310                cursor.advance(Self::BASE_LEN - 1);
1311                Ok(EventKindLazy::CreateSource)
1312            }
1313            1 => {
1314                cursor.advance(Self::BASE_LEN - 1);
1315                Ok(EventKindLazy::DeleteSource)
1316            }
1317            2 => {
1318                cursor.advance(Self::BASE_LEN - 1);
1319                Ok(EventKindLazy::Trace)
1320            }
1321            3 => {
1322                cursor.advance(Self::BASE_LEN - 1);
1323                Ok(EventKindLazy::TraceAggregate)
1324            }
1325            4 => {
1326                cursor.advance(Self::BASE_LEN - 1);
1327                Ok(EventKindLazy::TraceAggregateDelta)
1328            }
1329            _ => { Err(DecodeError) }
1330        }
1331    }
1332}
1333
1334impl TryFrom<EventKindLazy> for EventKind {
1335    type Error = DecodeError;
1336
1337    fn try_from(other: EventKindLazy) -> Result<Self, Self::Error> {
1338        match other {
1339            EventKindLazy::CreateSource => Ok(EventKind::CreateSource),
1340            EventKindLazy::DeleteSource => Ok(EventKind::DeleteSource),
1341            EventKindLazy::Trace => Ok(EventKind::Trace),
1342            EventKindLazy::TraceAggregate => Ok(EventKind::TraceAggregate),
1343            EventKindLazy::TraceAggregateDelta => Ok(EventKind::TraceAggregateDelta),
1344        }
1345    }
1346}
1347
1348impl Copy for EventKindLazy { }
1349
1350impl core::fmt::Debug for EventKindLazy {
1351    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1352        f.debug_struct("EventKindLazy")
1353            .finish()
1354    }
1355}
1356
1357impl PartialEq for EventKindLazy {
1358    fn eq(&self, other: &Self) -> bool {
1359        match (self, other) {
1360            (EventKindLazy::CreateSource, EventKindLazy::CreateSource) => true,
1361            (EventKindLazy::DeleteSource, EventKindLazy::DeleteSource) => true,
1362            (EventKindLazy::Trace, EventKindLazy::Trace) => true,
1363            (EventKindLazy::TraceAggregate, EventKindLazy::TraceAggregate) => true,
1364            (EventKindLazy::TraceAggregateDelta, EventKindLazy::TraceAggregateDelta) => true,
1365            #[allow(unreachable_patterns)]
1366            _ => false,
1367        }
1368    }
1369}
1370
1371#[cfg(any(feature = "std", feature = "alloc"))]
1372#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
1373pub struct CreateSource {
1374    pub name: String,
1375    pub parent: Option<SourceId>,
1376    pub is_recurring: bool,
1377}
1378
1379pub struct CreateSourceLazy<'a> {
1380    buffer: &'a [u8],
1381    offset: usize,
1382}
1383
1384pub struct CreateSourceGen<
1385    Name: Encode + Compatible<String>,
1386    Parent: Encode + Compatible<Option<SourceId>>,
1387> {
1388    pub name: Name,
1389    pub parent: Parent,
1390    pub is_recurring: bool,
1391}
1392
1393impl<
1394    Name: Encode + Compatible<String>,
1395    Parent: Encode + Compatible<Option<SourceId>>
1396> Compatible<CreateSource> for CreateSourceGen<Name, Parent> { }
1397impl<
1398    Name: Encode + Compatible<String>,
1399    Parent: Encode + Compatible<Option<SourceId>>
1400> Compatible<CreateSourceGen<Name, Parent>> for CreateSource { }
1401
1402impl<
1403    Name: Encode + Compatible<String>,
1404    Parent: Encode + Compatible<Option<SourceId>>,
1405> BaseLen for CreateSourceGen<Name, Parent> {
1406    const BASE_LEN: usize = 1 + Name::BASE_LEN + Parent::BASE_LEN;
1407}
1408
1409impl<
1410    Name: Encode + Compatible<String>,
1411    Parent: Encode + Compatible<Option<SourceId>>,
1412> Encode for CreateSourceGen<Name, Parent> {
1413    fn scratch_len(&self) -> usize {
1414        self.name.scratch_len() + self.parent.scratch_len() + self.is_recurring.scratch_len()
1415    }
1416
1417    fn encode(&self, cursor: &mut EncodeCursor) {
1418        self.name.encode(cursor);
1419        self.parent.encode(cursor);
1420        self.is_recurring.encode(cursor);
1421    }
1422}
1423
1424#[cfg(any(feature = "std", feature = "alloc"))]
1425impl Owned for CreateSource {
1426    type Lazy<'a> = CreateSourceLazy<'a>;
1427
1428    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1429        TryFrom::try_from(lazy)
1430    }
1431}
1432
1433impl<'a> Lazy<'a> for CreateSourceLazy<'a> {
1434    type Owned = CreateSource;
1435}
1436
1437impl<'a> Compatible<CreateSourceLazy<'a>> for CreateSourceLazy<'a> { }
1438#[cfg(any(feature = "std", feature = "alloc"))]
1439impl<'a> Compatible<CreateSourceLazy<'a>> for CreateSource { }
1440#[cfg(any(feature = "std", feature = "alloc"))]
1441impl Compatible<CreateSource> for CreateSource { }
1442#[cfg(any(feature = "std", feature = "alloc"))]
1443impl<'a> Compatible<CreateSource> for CreateSourceLazy<'a> { }
1444
1445impl<'a> CreateSourceLazy<'a> {
1446
1447    pub fn name(&self) -> DecodeResult<&'a str> {
1448        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
1449    }
1450
1451    pub fn parent(&self) -> DecodeResult<Option<SourceIdLazy<'a>>> {
1452        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
1453    }
1454
1455    pub fn is_recurring(&self) -> DecodeResult<bool> {
1456        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 17))
1457    }
1458}
1459
1460#[cfg(any(feature = "std", feature = "alloc"))]
1461impl BaseLen for CreateSource {
1462    const BASE_LEN: usize = 18;
1463}
1464
1465impl Encode for CreateSource {
1466    fn scratch_len(&self) -> usize {
1467        self.name.scratch_len() + self.parent.scratch_len() + self.is_recurring.scratch_len()
1468    }
1469
1470    fn encode(&self, cursor: &mut EncodeCursor) {
1471        self.name.encode(cursor);
1472        self.parent.encode(cursor);
1473        self.is_recurring.encode(cursor);
1474    }
1475}
1476
1477#[cfg(any(feature = "std", feature = "alloc"))]
1478impl<'a> Decode<'a> for CreateSource {
1479    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1480        let name = Decode::decode(cursor)?;
1481        let parent = Decode::decode(cursor)?;
1482        let is_recurring = Decode::decode(cursor)?;
1483
1484        Ok(CreateSource {
1485            name,
1486            parent,
1487            is_recurring,
1488        })
1489    }
1490}
1491
1492impl<'a> BaseLen for CreateSourceLazy<'a> {
1493    const BASE_LEN: usize = 18;
1494}
1495
1496impl<'a> Encode for CreateSourceLazy<'a> {
1497    fn scratch_len(&self) -> usize {
1498        let name: &'a str = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1499        let parent: Option<SourceIdLazy<'a>> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1500        let is_recurring: bool = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 17)).unwrap();
1501        name.scratch_len() + parent.scratch_len() + is_recurring.scratch_len()
1502    }
1503
1504    fn encode(&self, cursor: &mut EncodeCursor) {
1505        let name: &'a str = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1506        let parent: Option<SourceIdLazy<'a>> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1507        let is_recurring: bool = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 17)).unwrap();
1508        name.encode(cursor);
1509        parent.encode(cursor);
1510        is_recurring.encode(cursor);
1511    }
1512}
1513
1514impl<'a> Decode<'a> for CreateSourceLazy<'a> {
1515    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1516        let offset = cursor.offset();
1517        cursor.advance(Self::BASE_LEN);
1518        Ok(CreateSourceLazy {
1519            buffer: cursor.buffer(),
1520            offset,
1521        })
1522    }
1523}
1524
1525#[cfg(any(feature = "std", feature = "alloc"))]
1526impl<'a> TryFrom<CreateSourceLazy<'a>> for CreateSource {
1527    type Error = DecodeError;
1528
1529    fn try_from(other: CreateSourceLazy<'a>) -> Result<Self, Self::Error> {
1530        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
1531        Decode::decode(&cursor)
1532    }
1533}
1534
1535impl<'a> Copy for CreateSourceLazy<'a> { }
1536
1537impl<'a> Clone for CreateSourceLazy<'a> {
1538    fn clone(&self) -> Self {
1539        Self {
1540            buffer: self.buffer,
1541            offset: self.offset,
1542        }
1543    }
1544}
1545
1546impl<'a> core::fmt::Debug for CreateSourceLazy<'a> {
1547    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1548        f.debug_struct("CreateSourceLazy")
1549            .finish()
1550    }
1551}
1552
1553impl<'a> PartialEq for CreateSourceLazy<'a> {
1554    fn eq(&self, other: &Self) -> bool {
1555        self.name().unwrap() == other.name().unwrap()
1556            && self.parent().unwrap() == other.parent().unwrap()&& self.is_recurring().unwrap() == other.is_recurring().unwrap()
1557    }
1558}
1559
1560#[cfg(any(feature = "std", feature = "alloc"))]
1561#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
1562pub struct Trace {
1563    pub start_nanos: u64,
1564    pub trace: Vec<u8>,
1565}
1566
1567pub struct TraceLazy<'a> {
1568    buffer: &'a [u8],
1569    offset: usize,
1570}
1571
1572pub struct TraceGen<
1573    TTrace: Encode + Compatible<Vec<u8>>,
1574> {
1575    pub start_nanos: u64,
1576    pub trace: TTrace,
1577}
1578
1579impl<
1580    TTrace: Encode + Compatible<Vec<u8>>
1581> Compatible<Trace> for TraceGen<TTrace> { }
1582impl<
1583    TTrace: Encode + Compatible<Vec<u8>>
1584> Compatible<TraceGen<TTrace>> for Trace { }
1585
1586impl<
1587    TTrace: Encode + Compatible<Vec<u8>>,
1588> BaseLen for TraceGen<TTrace> {
1589    const BASE_LEN: usize = 8 + TTrace::BASE_LEN;
1590}
1591
1592impl<
1593    TTrace: Encode + Compatible<Vec<u8>>,
1594> Encode for TraceGen<TTrace> {
1595    fn scratch_len(&self) -> usize {
1596        self.start_nanos.scratch_len() + self.trace.scratch_len()
1597    }
1598
1599    fn encode(&self, cursor: &mut EncodeCursor) {
1600        self.start_nanos.encode(cursor);
1601        self.trace.encode(cursor);
1602    }
1603}
1604
1605#[cfg(any(feature = "std", feature = "alloc"))]
1606impl Owned for Trace {
1607    type Lazy<'a> = TraceLazy<'a>;
1608
1609    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1610        TryFrom::try_from(lazy)
1611    }
1612}
1613
1614impl<'a> Lazy<'a> for TraceLazy<'a> {
1615    type Owned = Trace;
1616}
1617
1618impl<'a> Compatible<TraceLazy<'a>> for TraceLazy<'a> { }
1619#[cfg(any(feature = "std", feature = "alloc"))]
1620impl<'a> Compatible<TraceLazy<'a>> for Trace { }
1621#[cfg(any(feature = "std", feature = "alloc"))]
1622impl Compatible<Trace> for Trace { }
1623#[cfg(any(feature = "std", feature = "alloc"))]
1624impl<'a> Compatible<Trace> for TraceLazy<'a> { }
1625
1626impl<'a> TraceLazy<'a> {
1627
1628    pub fn start_nanos(&self) -> DecodeResult<u64> {
1629        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
1630    }
1631
1632    pub fn trace(&self) -> DecodeResult<mproto::ListLazy<'a, u8>> {
1633        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
1634    }
1635}
1636
1637#[cfg(any(feature = "std", feature = "alloc"))]
1638impl BaseLen for Trace {
1639    const BASE_LEN: usize = 16;
1640}
1641
1642impl Encode for Trace {
1643    fn scratch_len(&self) -> usize {
1644        self.start_nanos.scratch_len() + self.trace.scratch_len()
1645    }
1646
1647    fn encode(&self, cursor: &mut EncodeCursor) {
1648        self.start_nanos.encode(cursor);
1649        self.trace.encode(cursor);
1650    }
1651}
1652
1653#[cfg(any(feature = "std", feature = "alloc"))]
1654impl<'a> Decode<'a> for Trace {
1655    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1656        let start_nanos = Decode::decode(cursor)?;
1657        let trace = Decode::decode(cursor)?;
1658
1659        Ok(Trace {
1660            start_nanos,
1661            trace,
1662        })
1663    }
1664}
1665
1666impl<'a> BaseLen for TraceLazy<'a> {
1667    const BASE_LEN: usize = 16;
1668}
1669
1670impl<'a> Encode for TraceLazy<'a> {
1671    fn scratch_len(&self) -> usize {
1672        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1673        let trace: mproto::ListLazy<'a, u8> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1674        start_nanos.scratch_len() + trace.scratch_len()
1675    }
1676
1677    fn encode(&self, cursor: &mut EncodeCursor) {
1678        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1679        let trace: mproto::ListLazy<'a, u8> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1680        start_nanos.encode(cursor);
1681        trace.encode(cursor);
1682    }
1683}
1684
1685impl<'a> Decode<'a> for TraceLazy<'a> {
1686    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1687        let offset = cursor.offset();
1688        cursor.advance(Self::BASE_LEN);
1689        Ok(TraceLazy {
1690            buffer: cursor.buffer(),
1691            offset,
1692        })
1693    }
1694}
1695
1696#[cfg(any(feature = "std", feature = "alloc"))]
1697impl<'a> TryFrom<TraceLazy<'a>> for Trace {
1698    type Error = DecodeError;
1699
1700    fn try_from(other: TraceLazy<'a>) -> Result<Self, Self::Error> {
1701        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
1702        Decode::decode(&cursor)
1703    }
1704}
1705
1706impl<'a> Copy for TraceLazy<'a> { }
1707
1708impl<'a> Clone for TraceLazy<'a> {
1709    fn clone(&self) -> Self {
1710        Self {
1711            buffer: self.buffer,
1712            offset: self.offset,
1713        }
1714    }
1715}
1716
1717impl<'a> core::fmt::Debug for TraceLazy<'a> {
1718    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1719        f.debug_struct("TraceLazy")
1720            .finish()
1721    }
1722}
1723
1724impl<'a> PartialEq for TraceLazy<'a> {
1725    fn eq(&self, other: &Self) -> bool {
1726        self.start_nanos().unwrap() == other.start_nanos().unwrap()
1727            && self.trace().unwrap() == other.trace().unwrap()
1728    }
1729}
1730
1731#[cfg(any(feature = "std", feature = "alloc"))]
1732#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
1733pub struct TraceAggregate {
1734    pub start_nanos: u64,
1735    pub nodes: Vec<TraceAggregateNode>,
1736    pub counters: Vec<u32>,
1737    pub metrics: Vec<MetricAggregate>,
1738}
1739
1740pub struct TraceAggregateLazy<'a> {
1741    buffer: &'a [u8],
1742    offset: usize,
1743}
1744
1745pub struct TraceAggregateGen<
1746    Nodes: Encode + Compatible<Vec<TraceAggregateNode>>,
1747    Counters: Encode + Compatible<Vec<u32>>,
1748    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1749> {
1750    pub start_nanos: u64,
1751    pub nodes: Nodes,
1752    pub counters: Counters,
1753    pub metrics: Metrics,
1754}
1755
1756impl<
1757    Nodes: Encode + Compatible<Vec<TraceAggregateNode>>,
1758    Counters: Encode + Compatible<Vec<u32>>,
1759    Metrics: Encode + Compatible<Vec<MetricAggregate>>
1760> Compatible<TraceAggregate> for TraceAggregateGen<Nodes, Counters, Metrics> { }
1761impl<
1762    Nodes: Encode + Compatible<Vec<TraceAggregateNode>>,
1763    Counters: Encode + Compatible<Vec<u32>>,
1764    Metrics: Encode + Compatible<Vec<MetricAggregate>>
1765> Compatible<TraceAggregateGen<Nodes, Counters, Metrics>> for TraceAggregate { }
1766
1767impl<
1768    Nodes: Encode + Compatible<Vec<TraceAggregateNode>>,
1769    Counters: Encode + Compatible<Vec<u32>>,
1770    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1771> BaseLen for TraceAggregateGen<Nodes, Counters, Metrics> {
1772    const BASE_LEN: usize = 8 + Nodes::BASE_LEN + Counters::BASE_LEN + Metrics::BASE_LEN;
1773}
1774
1775impl<
1776    Nodes: Encode + Compatible<Vec<TraceAggregateNode>>,
1777    Counters: Encode + Compatible<Vec<u32>>,
1778    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1779> Encode for TraceAggregateGen<Nodes, Counters, Metrics> {
1780    fn scratch_len(&self) -> usize {
1781        self.start_nanos.scratch_len() + self.nodes.scratch_len() + self.counters.scratch_len() + self.metrics.scratch_len()
1782    }
1783
1784    fn encode(&self, cursor: &mut EncodeCursor) {
1785        self.start_nanos.encode(cursor);
1786        self.nodes.encode(cursor);
1787        self.counters.encode(cursor);
1788        self.metrics.encode(cursor);
1789    }
1790}
1791
1792#[cfg(any(feature = "std", feature = "alloc"))]
1793impl Owned for TraceAggregate {
1794    type Lazy<'a> = TraceAggregateLazy<'a>;
1795
1796    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1797        TryFrom::try_from(lazy)
1798    }
1799}
1800
1801impl<'a> Lazy<'a> for TraceAggregateLazy<'a> {
1802    type Owned = TraceAggregate;
1803}
1804
1805impl<'a> Compatible<TraceAggregateLazy<'a>> for TraceAggregateLazy<'a> { }
1806#[cfg(any(feature = "std", feature = "alloc"))]
1807impl<'a> Compatible<TraceAggregateLazy<'a>> for TraceAggregate { }
1808#[cfg(any(feature = "std", feature = "alloc"))]
1809impl Compatible<TraceAggregate> for TraceAggregate { }
1810#[cfg(any(feature = "std", feature = "alloc"))]
1811impl<'a> Compatible<TraceAggregate> for TraceAggregateLazy<'a> { }
1812
1813impl<'a> TraceAggregateLazy<'a> {
1814
1815    pub fn start_nanos(&self) -> DecodeResult<u64> {
1816        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
1817    }
1818
1819    pub fn nodes(&self) -> DecodeResult<mproto::ListLazy<'a, TraceAggregateNode>> {
1820        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
1821    }
1822
1823    pub fn counters(&self) -> DecodeResult<mproto::ListLazy<'a, u32>> {
1824        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16))
1825    }
1826
1827    pub fn metrics(&self) -> DecodeResult<mproto::ListLazy<'a, MetricAggregate>> {
1828        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24))
1829    }
1830}
1831
1832#[cfg(any(feature = "std", feature = "alloc"))]
1833impl BaseLen for TraceAggregate {
1834    const BASE_LEN: usize = 32;
1835}
1836
1837impl Encode for TraceAggregate {
1838    fn scratch_len(&self) -> usize {
1839        self.start_nanos.scratch_len() + self.nodes.scratch_len() + self.counters.scratch_len() + self.metrics.scratch_len()
1840    }
1841
1842    fn encode(&self, cursor: &mut EncodeCursor) {
1843        self.start_nanos.encode(cursor);
1844        self.nodes.encode(cursor);
1845        self.counters.encode(cursor);
1846        self.metrics.encode(cursor);
1847    }
1848}
1849
1850#[cfg(any(feature = "std", feature = "alloc"))]
1851impl<'a> Decode<'a> for TraceAggregate {
1852    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1853        let start_nanos = Decode::decode(cursor)?;
1854        let nodes = Decode::decode(cursor)?;
1855        let counters = Decode::decode(cursor)?;
1856        let metrics = Decode::decode(cursor)?;
1857
1858        Ok(TraceAggregate {
1859            start_nanos,
1860            nodes,
1861            counters,
1862            metrics,
1863        })
1864    }
1865}
1866
1867impl<'a> BaseLen for TraceAggregateLazy<'a> {
1868    const BASE_LEN: usize = 32;
1869}
1870
1871impl<'a> Encode for TraceAggregateLazy<'a> {
1872    fn scratch_len(&self) -> usize {
1873        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1874        let nodes: mproto::ListLazy<'a, TraceAggregateNode> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1875        let counters: mproto::ListLazy<'a, u32> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
1876        let metrics: mproto::ListLazy<'a, MetricAggregate> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
1877        start_nanos.scratch_len() + nodes.scratch_len() + counters.scratch_len() + metrics.scratch_len()
1878    }
1879
1880    fn encode(&self, cursor: &mut EncodeCursor) {
1881        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
1882        let nodes: mproto::ListLazy<'a, TraceAggregateNode> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
1883        let counters: mproto::ListLazy<'a, u32> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
1884        let metrics: mproto::ListLazy<'a, MetricAggregate> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
1885        start_nanos.encode(cursor);
1886        nodes.encode(cursor);
1887        counters.encode(cursor);
1888        metrics.encode(cursor);
1889    }
1890}
1891
1892impl<'a> Decode<'a> for TraceAggregateLazy<'a> {
1893    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
1894        let offset = cursor.offset();
1895        cursor.advance(Self::BASE_LEN);
1896        Ok(TraceAggregateLazy {
1897            buffer: cursor.buffer(),
1898            offset,
1899        })
1900    }
1901}
1902
1903#[cfg(any(feature = "std", feature = "alloc"))]
1904impl<'a> TryFrom<TraceAggregateLazy<'a>> for TraceAggregate {
1905    type Error = DecodeError;
1906
1907    fn try_from(other: TraceAggregateLazy<'a>) -> Result<Self, Self::Error> {
1908        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
1909        Decode::decode(&cursor)
1910    }
1911}
1912
1913impl<'a> Copy for TraceAggregateLazy<'a> { }
1914
1915impl<'a> Clone for TraceAggregateLazy<'a> {
1916    fn clone(&self) -> Self {
1917        Self {
1918            buffer: self.buffer,
1919            offset: self.offset,
1920        }
1921    }
1922}
1923
1924impl<'a> core::fmt::Debug for TraceAggregateLazy<'a> {
1925    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1926        f.debug_struct("TraceAggregateLazy")
1927            .finish()
1928    }
1929}
1930
1931impl<'a> PartialEq for TraceAggregateLazy<'a> {
1932    fn eq(&self, other: &Self) -> bool {
1933        self.start_nanos().unwrap() == other.start_nanos().unwrap()
1934            && self.nodes().unwrap() == other.nodes().unwrap()&& self.counters().unwrap() == other.counters().unwrap()&& self.metrics().unwrap() == other.metrics().unwrap()
1935    }
1936}
1937
1938#[cfg(any(feature = "std", feature = "alloc"))]
1939#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
1940pub struct TraceAggregateDelta {
1941    pub start_nanos: u64,
1942    pub end_nanos: u64,
1943    pub counters: Vec<u32>,
1944    pub metrics: Vec<MetricAggregate>,
1945}
1946
1947pub struct TraceAggregateDeltaLazy<'a> {
1948    buffer: &'a [u8],
1949    offset: usize,
1950}
1951
1952pub struct TraceAggregateDeltaGen<
1953    Counters: Encode + Compatible<Vec<u32>>,
1954    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1955> {
1956    pub start_nanos: u64,
1957    pub end_nanos: u64,
1958    pub counters: Counters,
1959    pub metrics: Metrics,
1960}
1961
1962impl<
1963    Counters: Encode + Compatible<Vec<u32>>,
1964    Metrics: Encode + Compatible<Vec<MetricAggregate>>
1965> Compatible<TraceAggregateDelta> for TraceAggregateDeltaGen<Counters, Metrics> { }
1966impl<
1967    Counters: Encode + Compatible<Vec<u32>>,
1968    Metrics: Encode + Compatible<Vec<MetricAggregate>>
1969> Compatible<TraceAggregateDeltaGen<Counters, Metrics>> for TraceAggregateDelta { }
1970
1971impl<
1972    Counters: Encode + Compatible<Vec<u32>>,
1973    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1974> BaseLen for TraceAggregateDeltaGen<Counters, Metrics> {
1975    const BASE_LEN: usize = 16 + Counters::BASE_LEN + Metrics::BASE_LEN;
1976}
1977
1978impl<
1979    Counters: Encode + Compatible<Vec<u32>>,
1980    Metrics: Encode + Compatible<Vec<MetricAggregate>>,
1981> Encode for TraceAggregateDeltaGen<Counters, Metrics> {
1982    fn scratch_len(&self) -> usize {
1983        self.start_nanos.scratch_len() + self.end_nanos.scratch_len() + self.counters.scratch_len() + self.metrics.scratch_len()
1984    }
1985
1986    fn encode(&self, cursor: &mut EncodeCursor) {
1987        self.start_nanos.encode(cursor);
1988        self.end_nanos.encode(cursor);
1989        self.counters.encode(cursor);
1990        self.metrics.encode(cursor);
1991    }
1992}
1993
1994#[cfg(any(feature = "std", feature = "alloc"))]
1995impl Owned for TraceAggregateDelta {
1996    type Lazy<'a> = TraceAggregateDeltaLazy<'a>;
1997
1998    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
1999        TryFrom::try_from(lazy)
2000    }
2001}
2002
2003impl<'a> Lazy<'a> for TraceAggregateDeltaLazy<'a> {
2004    type Owned = TraceAggregateDelta;
2005}
2006
2007impl<'a> Compatible<TraceAggregateDeltaLazy<'a>> for TraceAggregateDeltaLazy<'a> { }
2008#[cfg(any(feature = "std", feature = "alloc"))]
2009impl<'a> Compatible<TraceAggregateDeltaLazy<'a>> for TraceAggregateDelta { }
2010#[cfg(any(feature = "std", feature = "alloc"))]
2011impl Compatible<TraceAggregateDelta> for TraceAggregateDelta { }
2012#[cfg(any(feature = "std", feature = "alloc"))]
2013impl<'a> Compatible<TraceAggregateDelta> for TraceAggregateDeltaLazy<'a> { }
2014
2015impl<'a> TraceAggregateDeltaLazy<'a> {
2016
2017    pub fn start_nanos(&self) -> DecodeResult<u64> {
2018        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
2019    }
2020
2021    pub fn end_nanos(&self) -> DecodeResult<u64> {
2022        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
2023    }
2024
2025    pub fn counters(&self) -> DecodeResult<mproto::ListLazy<'a, u32>> {
2026        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16))
2027    }
2028
2029    pub fn metrics(&self) -> DecodeResult<mproto::ListLazy<'a, MetricAggregate>> {
2030        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24))
2031    }
2032}
2033
2034#[cfg(any(feature = "std", feature = "alloc"))]
2035impl BaseLen for TraceAggregateDelta {
2036    const BASE_LEN: usize = 32;
2037}
2038
2039impl Encode for TraceAggregateDelta {
2040    fn scratch_len(&self) -> usize {
2041        self.start_nanos.scratch_len() + self.end_nanos.scratch_len() + self.counters.scratch_len() + self.metrics.scratch_len()
2042    }
2043
2044    fn encode(&self, cursor: &mut EncodeCursor) {
2045        self.start_nanos.encode(cursor);
2046        self.end_nanos.encode(cursor);
2047        self.counters.encode(cursor);
2048        self.metrics.encode(cursor);
2049    }
2050}
2051
2052#[cfg(any(feature = "std", feature = "alloc"))]
2053impl<'a> Decode<'a> for TraceAggregateDelta {
2054    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2055        let start_nanos = Decode::decode(cursor)?;
2056        let end_nanos = Decode::decode(cursor)?;
2057        let counters = Decode::decode(cursor)?;
2058        let metrics = Decode::decode(cursor)?;
2059
2060        Ok(TraceAggregateDelta {
2061            start_nanos,
2062            end_nanos,
2063            counters,
2064            metrics,
2065        })
2066    }
2067}
2068
2069impl<'a> BaseLen for TraceAggregateDeltaLazy<'a> {
2070    const BASE_LEN: usize = 32;
2071}
2072
2073impl<'a> Encode for TraceAggregateDeltaLazy<'a> {
2074    fn scratch_len(&self) -> usize {
2075        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
2076        let end_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
2077        let counters: mproto::ListLazy<'a, u32> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
2078        let metrics: mproto::ListLazy<'a, MetricAggregate> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
2079        start_nanos.scratch_len() + end_nanos.scratch_len() + counters.scratch_len() + metrics.scratch_len()
2080    }
2081
2082    fn encode(&self, cursor: &mut EncodeCursor) {
2083        let start_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
2084        let end_nanos: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
2085        let counters: mproto::ListLazy<'a, u32> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
2086        let metrics: mproto::ListLazy<'a, MetricAggregate> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
2087        start_nanos.encode(cursor);
2088        end_nanos.encode(cursor);
2089        counters.encode(cursor);
2090        metrics.encode(cursor);
2091    }
2092}
2093
2094impl<'a> Decode<'a> for TraceAggregateDeltaLazy<'a> {
2095    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2096        let offset = cursor.offset();
2097        cursor.advance(Self::BASE_LEN);
2098        Ok(TraceAggregateDeltaLazy {
2099            buffer: cursor.buffer(),
2100            offset,
2101        })
2102    }
2103}
2104
2105#[cfg(any(feature = "std", feature = "alloc"))]
2106impl<'a> TryFrom<TraceAggregateDeltaLazy<'a>> for TraceAggregateDelta {
2107    type Error = DecodeError;
2108
2109    fn try_from(other: TraceAggregateDeltaLazy<'a>) -> Result<Self, Self::Error> {
2110        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
2111        Decode::decode(&cursor)
2112    }
2113}
2114
2115impl<'a> Copy for TraceAggregateDeltaLazy<'a> { }
2116
2117impl<'a> Clone for TraceAggregateDeltaLazy<'a> {
2118    fn clone(&self) -> Self {
2119        Self {
2120            buffer: self.buffer,
2121            offset: self.offset,
2122        }
2123    }
2124}
2125
2126impl<'a> core::fmt::Debug for TraceAggregateDeltaLazy<'a> {
2127    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2128        f.debug_struct("TraceAggregateDeltaLazy")
2129            .finish()
2130    }
2131}
2132
2133impl<'a> PartialEq for TraceAggregateDeltaLazy<'a> {
2134    fn eq(&self, other: &Self) -> bool {
2135        self.start_nanos().unwrap() == other.start_nanos().unwrap()
2136            && self.end_nanos().unwrap() == other.end_nanos().unwrap()&& self.counters().unwrap() == other.counters().unwrap()&& self.metrics().unwrap() == other.metrics().unwrap()
2137    }
2138}
2139
2140#[cfg(any(feature = "std", feature = "alloc"))]
2141#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
2142pub struct TraceAggregateNode {
2143    pub op: TraceOpAggregate,
2144    pub branch_next: Option<u16>,
2145    pub next: Option<u16>,
2146}
2147
2148pub struct TraceAggregateNodeLazy<'a> {
2149    buffer: &'a [u8],
2150    offset: usize,
2151}
2152
2153pub struct TraceAggregateNodeGen<
2154    Op: Encode + Compatible<TraceOpAggregate>,
2155    BranchNext: Encode + Compatible<Option<u16>>,
2156    Next: Encode + Compatible<Option<u16>>,
2157> {
2158    pub op: Op,
2159    pub branch_next: BranchNext,
2160    pub next: Next,
2161}
2162
2163impl<
2164    Op: Encode + Compatible<TraceOpAggregate>,
2165    BranchNext: Encode + Compatible<Option<u16>>,
2166    Next: Encode + Compatible<Option<u16>>
2167> Compatible<TraceAggregateNode> for TraceAggregateNodeGen<Op, BranchNext, Next> { }
2168impl<
2169    Op: Encode + Compatible<TraceOpAggregate>,
2170    BranchNext: Encode + Compatible<Option<u16>>,
2171    Next: Encode + Compatible<Option<u16>>
2172> Compatible<TraceAggregateNodeGen<Op, BranchNext, Next>> for TraceAggregateNode { }
2173
2174impl<
2175    Op: Encode + Compatible<TraceOpAggregate>,
2176    BranchNext: Encode + Compatible<Option<u16>>,
2177    Next: Encode + Compatible<Option<u16>>,
2178> BaseLen for TraceAggregateNodeGen<Op, BranchNext, Next> {
2179    const BASE_LEN: usize = Op::BASE_LEN + BranchNext::BASE_LEN + Next::BASE_LEN;
2180}
2181
2182impl<
2183    Op: Encode + Compatible<TraceOpAggregate>,
2184    BranchNext: Encode + Compatible<Option<u16>>,
2185    Next: Encode + Compatible<Option<u16>>,
2186> Encode for TraceAggregateNodeGen<Op, BranchNext, Next> {
2187    fn scratch_len(&self) -> usize {
2188        self.op.scratch_len() + self.branch_next.scratch_len() + self.next.scratch_len()
2189    }
2190
2191    fn encode(&self, cursor: &mut EncodeCursor) {
2192        self.op.encode(cursor);
2193        self.branch_next.encode(cursor);
2194        self.next.encode(cursor);
2195    }
2196}
2197
2198#[cfg(any(feature = "std", feature = "alloc"))]
2199impl Owned for TraceAggregateNode {
2200    type Lazy<'a> = TraceAggregateNodeLazy<'a>;
2201
2202    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
2203        TryFrom::try_from(lazy)
2204    }
2205}
2206
2207impl<'a> Lazy<'a> for TraceAggregateNodeLazy<'a> {
2208    type Owned = TraceAggregateNode;
2209}
2210
2211impl<'a> Compatible<TraceAggregateNodeLazy<'a>> for TraceAggregateNodeLazy<'a> { }
2212#[cfg(any(feature = "std", feature = "alloc"))]
2213impl<'a> Compatible<TraceAggregateNodeLazy<'a>> for TraceAggregateNode { }
2214#[cfg(any(feature = "std", feature = "alloc"))]
2215impl Compatible<TraceAggregateNode> for TraceAggregateNode { }
2216#[cfg(any(feature = "std", feature = "alloc"))]
2217impl<'a> Compatible<TraceAggregateNode> for TraceAggregateNodeLazy<'a> { }
2218
2219impl<'a> TraceAggregateNodeLazy<'a> {
2220
2221    pub fn op(&self) -> DecodeResult<TraceOpAggregateLazy<'a>> {
2222        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
2223    }
2224
2225    pub fn branch_next(&self) -> DecodeResult<Option<u16>> {
2226        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32)))
2227    }
2228
2229    pub fn next(&self) -> DecodeResult<Option<u16>> {
2230        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 4 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32)))
2231    }
2232}
2233
2234#[cfg(any(feature = "std", feature = "alloc"))]
2235impl BaseLen for TraceAggregateNode {
2236    const BASE_LEN: usize = 7 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32);
2237}
2238
2239impl Encode for TraceAggregateNode {
2240    fn scratch_len(&self) -> usize {
2241        self.op.scratch_len() + self.branch_next.scratch_len() + self.next.scratch_len()
2242    }
2243
2244    fn encode(&self, cursor: &mut EncodeCursor) {
2245        self.op.encode(cursor);
2246        self.branch_next.encode(cursor);
2247        self.next.encode(cursor);
2248    }
2249}
2250
2251#[cfg(any(feature = "std", feature = "alloc"))]
2252impl<'a> Decode<'a> for TraceAggregateNode {
2253    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2254        let op = Decode::decode(cursor)?;
2255        let branch_next = Decode::decode(cursor)?;
2256        let next = Decode::decode(cursor)?;
2257
2258        Ok(TraceAggregateNode {
2259            op,
2260            branch_next,
2261            next,
2262        })
2263    }
2264}
2265
2266impl<'a> BaseLen for TraceAggregateNodeLazy<'a> {
2267    const BASE_LEN: usize = 7 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32);
2268}
2269
2270impl<'a> Encode for TraceAggregateNodeLazy<'a> {
2271    fn scratch_len(&self) -> usize {
2272        let op: TraceOpAggregateLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
2273        let branch_next: Option<u16> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32))).unwrap();
2274        let next: Option<u16> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 4 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32))).unwrap();
2275        op.scratch_len() + branch_next.scratch_len() + next.scratch_len()
2276    }
2277
2278    fn encode(&self, cursor: &mut EncodeCursor) {
2279        let op: TraceOpAggregateLazy<'a> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
2280        let branch_next: Option<u16> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32))).unwrap();
2281        let next: Option<u16> = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 4 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32))).unwrap();
2282        op.encode(cursor);
2283        branch_next.encode(cursor);
2284        next.encode(cursor);
2285    }
2286}
2287
2288impl<'a> Decode<'a> for TraceAggregateNodeLazy<'a> {
2289    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2290        let offset = cursor.offset();
2291        cursor.advance(Self::BASE_LEN);
2292        Ok(TraceAggregateNodeLazy {
2293            buffer: cursor.buffer(),
2294            offset,
2295        })
2296    }
2297}
2298
2299#[cfg(any(feature = "std", feature = "alloc"))]
2300impl<'a> TryFrom<TraceAggregateNodeLazy<'a>> for TraceAggregateNode {
2301    type Error = DecodeError;
2302
2303    fn try_from(other: TraceAggregateNodeLazy<'a>) -> Result<Self, Self::Error> {
2304        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
2305        Decode::decode(&cursor)
2306    }
2307}
2308
2309impl<'a> Copy for TraceAggregateNodeLazy<'a> { }
2310
2311impl<'a> Clone for TraceAggregateNodeLazy<'a> {
2312    fn clone(&self) -> Self {
2313        Self {
2314            buffer: self.buffer,
2315            offset: self.offset,
2316        }
2317    }
2318}
2319
2320impl<'a> core::fmt::Debug for TraceAggregateNodeLazy<'a> {
2321    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
2322        f.debug_struct("TraceAggregateNodeLazy")
2323            .finish()
2324    }
2325}
2326
2327impl<'a> PartialEq for TraceAggregateNodeLazy<'a> {
2328    fn eq(&self, other: &Self) -> bool {
2329        self.op().unwrap() == other.op().unwrap()
2330            && self.branch_next().unwrap() == other.branch_next().unwrap()&& self.next().unwrap() == other.next().unwrap()
2331    }
2332}
2333
2334#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
2335pub enum TraceOp {
2336    CreateSource {
2337        source: SourceId,
2338    },
2339    DeleteSource {
2340        source: SourceId,
2341    },
2342    Call {
2343        source: SourceId,
2344    },
2345    PushScope,
2346    PopScope,
2347    BranchStart,
2348    BranchEnd,
2349    Label,
2350    Tag {
2351        tag: u64,
2352    },
2353    Metric {
2354        value: i64,
2355    },
2356    ChannelSend {
2357        channel: SourceId,
2358    },
2359    ChannelReceive {
2360        channel: SourceId,
2361        sender: TraceCallerId,
2362    },
2363    ChannelTransfer {
2364        from: SourceId,
2365        to: SourceId,
2366    },
2367    GlobalChannelSend {
2368        channel: GlobalSourceId,
2369    },
2370    GlobalChannelReceive {
2371        channel: GlobalSourceId,
2372    },
2373    GlobalChannelTransfer {
2374        from: GlobalSourceId,
2375        to: GlobalSourceId,
2376    },
2377}
2378
2379#[derive(Clone)]
2380pub enum TraceOpLazy<'a> {
2381    CreateSource {
2382        source: SourceIdLazy<'a>,
2383    },
2384    DeleteSource {
2385        source: SourceIdLazy<'a>,
2386    },
2387    Call {
2388        source: SourceIdLazy<'a>,
2389    },
2390    PushScope,
2391    PopScope,
2392    BranchStart,
2393    BranchEnd,
2394    Label,
2395    Tag {
2396        tag: u64,
2397    },
2398    Metric {
2399        value: i64,
2400    },
2401    ChannelSend {
2402        channel: SourceIdLazy<'a>,
2403    },
2404    ChannelReceive {
2405        channel: SourceIdLazy<'a>,
2406        sender: TraceCallerIdLazy<'a>,
2407    },
2408    ChannelTransfer {
2409        from: SourceIdLazy<'a>,
2410        to: SourceIdLazy<'a>,
2411    },
2412    GlobalChannelSend {
2413        channel: GlobalSourceIdLazy<'a>,
2414    },
2415    GlobalChannelReceive {
2416        channel: GlobalSourceIdLazy<'a>,
2417    },
2418    GlobalChannelTransfer {
2419        from: GlobalSourceIdLazy<'a>,
2420        to: GlobalSourceIdLazy<'a>,
2421    },
2422}
2423
2424impl<'a> Compatible<TraceOpLazy<'a>> for TraceOpLazy<'a> { }
2425impl<'a> Compatible<TraceOpLazy<'a>> for TraceOp { }
2426impl<'a> Compatible<TraceOp> for TraceOpLazy<'a> { }
2427impl Compatible<TraceOp> for TraceOp { }
2428
2429impl Owned for TraceOp {
2430    type Lazy<'a> = TraceOpLazy<'a>;
2431
2432    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
2433        TryFrom::try_from(lazy)
2434    }
2435}
2436
2437impl<'a> Lazy<'a> for TraceOpLazy<'a> {
2438    type Owned = TraceOp;
2439}
2440
2441impl BaseLen for TraceOp {
2442    const BASE_LEN: usize = 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 8), 8), 8), 0), 0), 0), 0), 0), 8), 8), 8), 28), 16), 16), 16), 32);
2443}
2444
2445impl Encode for TraceOp {
2446    fn scratch_len(&self) -> usize {
2447        match self {
2448            TraceOp::CreateSource { source } => {
2449                source.scratch_len()
2450            }
2451            TraceOp::DeleteSource { source } => {
2452                source.scratch_len()
2453            }
2454            TraceOp::Call { source } => {
2455                source.scratch_len()
2456            }
2457            TraceOp::PushScope => 0,
2458            TraceOp::PopScope => 0,
2459            TraceOp::BranchStart => 0,
2460            TraceOp::BranchEnd => 0,
2461            TraceOp::Label => 0,
2462            TraceOp::Tag { tag } => {
2463                tag.scratch_len()
2464            }
2465            TraceOp::Metric { value } => {
2466                value.scratch_len()
2467            }
2468            TraceOp::ChannelSend { channel } => {
2469                channel.scratch_len()
2470            }
2471            TraceOp::ChannelReceive { channel, sender } => {
2472                channel.scratch_len() + sender.scratch_len()
2473            }
2474            TraceOp::ChannelTransfer { from, to } => {
2475                from.scratch_len() + to.scratch_len()
2476            }
2477            TraceOp::GlobalChannelSend { channel } => {
2478                channel.scratch_len()
2479            }
2480            TraceOp::GlobalChannelReceive { channel } => {
2481                channel.scratch_len()
2482            }
2483            TraceOp::GlobalChannelTransfer { from, to } => {
2484                from.scratch_len() + to.scratch_len()
2485            }
2486        }
2487    }
2488
2489    fn encode(&self, cursor: &mut EncodeCursor) {
2490        match self {
2491            TraceOp::CreateSource { source } => {
2492                cursor.base(1)[0] = 0;
2493                source.encode(cursor);
2494                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2495            }
2496            TraceOp::DeleteSource { source } => {
2497                cursor.base(1)[0] = 1;
2498                source.encode(cursor);
2499                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2500            }
2501            TraceOp::Call { source } => {
2502                cursor.base(1)[0] = 2;
2503                source.encode(cursor);
2504                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2505            }
2506            TraceOp::PushScope => {
2507                cursor.base(1)[0] = 3;
2508                cursor.base(Self::BASE_LEN - 1).fill(0);
2509            }
2510            TraceOp::PopScope => {
2511                cursor.base(1)[0] = 4;
2512                cursor.base(Self::BASE_LEN - 1).fill(0);
2513            }
2514            TraceOp::BranchStart => {
2515                cursor.base(1)[0] = 5;
2516                cursor.base(Self::BASE_LEN - 1).fill(0);
2517            }
2518            TraceOp::BranchEnd => {
2519                cursor.base(1)[0] = 6;
2520                cursor.base(Self::BASE_LEN - 1).fill(0);
2521            }
2522            TraceOp::Label => {
2523                cursor.base(1)[0] = 7;
2524                cursor.base(Self::BASE_LEN - 1).fill(0);
2525            }
2526            TraceOp::Tag { tag } => {
2527                cursor.base(1)[0] = 8;
2528                tag.encode(cursor);
2529                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2530            }
2531            TraceOp::Metric { value } => {
2532                cursor.base(1)[0] = 9;
2533                value.encode(cursor);
2534                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2535            }
2536            TraceOp::ChannelSend { channel } => {
2537                cursor.base(1)[0] = 10;
2538                channel.encode(cursor);
2539                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2540            }
2541            TraceOp::ChannelReceive { channel, sender } => {
2542                cursor.base(1)[0] = 11;
2543                channel.encode(cursor);
2544                sender.encode(cursor);
2545                cursor.base(Self::BASE_LEN - 1 - (28)).fill(0);
2546            }
2547            TraceOp::ChannelTransfer { from, to } => {
2548                cursor.base(1)[0] = 12;
2549                from.encode(cursor);
2550                to.encode(cursor);
2551                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2552            }
2553            TraceOp::GlobalChannelSend { channel } => {
2554                cursor.base(1)[0] = 13;
2555                channel.encode(cursor);
2556                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2557            }
2558            TraceOp::GlobalChannelReceive { channel } => {
2559                cursor.base(1)[0] = 14;
2560                channel.encode(cursor);
2561                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2562            }
2563            TraceOp::GlobalChannelTransfer { from, to } => {
2564                cursor.base(1)[0] = 15;
2565                from.encode(cursor);
2566                to.encode(cursor);
2567                cursor.base(Self::BASE_LEN - 1 - (32)).fill(0);
2568            }
2569        }
2570    }
2571}
2572
2573impl<'a> Decode<'a> for TraceOp {
2574    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2575        let variant = cursor.base(1)[0];
2576        match variant {
2577            0 => {
2578                let source = Decode::decode(cursor)?;
2579                cursor.advance(Self::BASE_LEN - 1 - (8));
2580                Ok(TraceOp::CreateSource {
2581                    source,
2582                })
2583            }
2584            1 => {
2585                let source = Decode::decode(cursor)?;
2586                cursor.advance(Self::BASE_LEN - 1 - (8));
2587                Ok(TraceOp::DeleteSource {
2588                    source,
2589                })
2590            }
2591            2 => {
2592                let source = Decode::decode(cursor)?;
2593                cursor.advance(Self::BASE_LEN - 1 - (8));
2594                Ok(TraceOp::Call {
2595                    source,
2596                })
2597            }
2598            3 => {
2599                cursor.advance(Self::BASE_LEN - 1);
2600                Ok(TraceOp::PushScope)
2601            }
2602            4 => {
2603                cursor.advance(Self::BASE_LEN - 1);
2604                Ok(TraceOp::PopScope)
2605            }
2606            5 => {
2607                cursor.advance(Self::BASE_LEN - 1);
2608                Ok(TraceOp::BranchStart)
2609            }
2610            6 => {
2611                cursor.advance(Self::BASE_LEN - 1);
2612                Ok(TraceOp::BranchEnd)
2613            }
2614            7 => {
2615                cursor.advance(Self::BASE_LEN - 1);
2616                Ok(TraceOp::Label)
2617            }
2618            8 => {
2619                let tag = Decode::decode(cursor)?;
2620                cursor.advance(Self::BASE_LEN - 1 - (8));
2621                Ok(TraceOp::Tag {
2622                    tag,
2623                })
2624            }
2625            9 => {
2626                let value = Decode::decode(cursor)?;
2627                cursor.advance(Self::BASE_LEN - 1 - (8));
2628                Ok(TraceOp::Metric {
2629                    value,
2630                })
2631            }
2632            10 => {
2633                let channel = Decode::decode(cursor)?;
2634                cursor.advance(Self::BASE_LEN - 1 - (8));
2635                Ok(TraceOp::ChannelSend {
2636                    channel,
2637                })
2638            }
2639            11 => {
2640                let channel = Decode::decode(cursor)?;
2641                let sender = Decode::decode(cursor)?;
2642                cursor.advance(Self::BASE_LEN - 1 - (28));
2643                Ok(TraceOp::ChannelReceive {
2644                    channel,
2645                    sender,
2646                })
2647            }
2648            12 => {
2649                let from = Decode::decode(cursor)?;
2650                let to = Decode::decode(cursor)?;
2651                cursor.advance(Self::BASE_LEN - 1 - (16));
2652                Ok(TraceOp::ChannelTransfer {
2653                    from,
2654                    to,
2655                })
2656            }
2657            13 => {
2658                let channel = Decode::decode(cursor)?;
2659                cursor.advance(Self::BASE_LEN - 1 - (16));
2660                Ok(TraceOp::GlobalChannelSend {
2661                    channel,
2662                })
2663            }
2664            14 => {
2665                let channel = Decode::decode(cursor)?;
2666                cursor.advance(Self::BASE_LEN - 1 - (16));
2667                Ok(TraceOp::GlobalChannelReceive {
2668                    channel,
2669                })
2670            }
2671            15 => {
2672                let from = Decode::decode(cursor)?;
2673                let to = Decode::decode(cursor)?;
2674                cursor.advance(Self::BASE_LEN - 1 - (32));
2675                Ok(TraceOp::GlobalChannelTransfer {
2676                    from,
2677                    to,
2678                })
2679            }
2680            _ => { Err(DecodeError) }
2681        }
2682    }
2683}
2684
2685impl<'a> BaseLen for TraceOpLazy<'a> {
2686    const BASE_LEN: usize = 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 8), 8), 8), 0), 0), 0), 0), 0), 8), 8), 8), 28), 16), 16), 16), 32);
2687}
2688
2689impl<'a> Encode for TraceOpLazy<'a> {
2690    fn scratch_len(&self) -> usize {
2691        match self {
2692            TraceOpLazy::CreateSource { source } => {
2693                source.scratch_len()
2694            }
2695            TraceOpLazy::DeleteSource { source } => {
2696                source.scratch_len()
2697            }
2698            TraceOpLazy::Call { source } => {
2699                source.scratch_len()
2700            }
2701            TraceOpLazy::PushScope => 0,
2702            TraceOpLazy::PopScope => 0,
2703            TraceOpLazy::BranchStart => 0,
2704            TraceOpLazy::BranchEnd => 0,
2705            TraceOpLazy::Label => 0,
2706            TraceOpLazy::Tag { tag } => {
2707                tag.scratch_len()
2708            }
2709            TraceOpLazy::Metric { value } => {
2710                value.scratch_len()
2711            }
2712            TraceOpLazy::ChannelSend { channel } => {
2713                channel.scratch_len()
2714            }
2715            TraceOpLazy::ChannelReceive { channel, sender } => {
2716                channel.scratch_len() + sender.scratch_len()
2717            }
2718            TraceOpLazy::ChannelTransfer { from, to } => {
2719                from.scratch_len() + to.scratch_len()
2720            }
2721            TraceOpLazy::GlobalChannelSend { channel } => {
2722                channel.scratch_len()
2723            }
2724            TraceOpLazy::GlobalChannelReceive { channel } => {
2725                channel.scratch_len()
2726            }
2727            TraceOpLazy::GlobalChannelTransfer { from, to } => {
2728                from.scratch_len() + to.scratch_len()
2729            }
2730        }
2731    }
2732
2733    fn encode(&self, cursor: &mut EncodeCursor) {
2734        match self {
2735            TraceOpLazy::CreateSource { source } => {
2736                cursor.base(1)[0] = 0;
2737                source.encode(cursor);
2738                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2739            }
2740            TraceOpLazy::DeleteSource { source } => {
2741                cursor.base(1)[0] = 1;
2742                source.encode(cursor);
2743                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2744            }
2745            TraceOpLazy::Call { source } => {
2746                cursor.base(1)[0] = 2;
2747                source.encode(cursor);
2748                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2749            }
2750            TraceOpLazy::PushScope => {
2751                cursor.base(1)[0] = 3;
2752                cursor.base(Self::BASE_LEN - 1).fill(0);
2753            }
2754            TraceOpLazy::PopScope => {
2755                cursor.base(1)[0] = 4;
2756                cursor.base(Self::BASE_LEN - 1).fill(0);
2757            }
2758            TraceOpLazy::BranchStart => {
2759                cursor.base(1)[0] = 5;
2760                cursor.base(Self::BASE_LEN - 1).fill(0);
2761            }
2762            TraceOpLazy::BranchEnd => {
2763                cursor.base(1)[0] = 6;
2764                cursor.base(Self::BASE_LEN - 1).fill(0);
2765            }
2766            TraceOpLazy::Label => {
2767                cursor.base(1)[0] = 7;
2768                cursor.base(Self::BASE_LEN - 1).fill(0);
2769            }
2770            TraceOpLazy::Tag { tag } => {
2771                cursor.base(1)[0] = 8;
2772                tag.encode(cursor);
2773                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2774            }
2775            TraceOpLazy::Metric { value } => {
2776                cursor.base(1)[0] = 9;
2777                value.encode(cursor);
2778                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2779            }
2780            TraceOpLazy::ChannelSend { channel } => {
2781                cursor.base(1)[0] = 10;
2782                channel.encode(cursor);
2783                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
2784            }
2785            TraceOpLazy::ChannelReceive { channel, sender } => {
2786                cursor.base(1)[0] = 11;
2787                channel.encode(cursor);
2788                sender.encode(cursor);
2789                cursor.base(Self::BASE_LEN - 1 - (28)).fill(0);
2790            }
2791            TraceOpLazy::ChannelTransfer { from, to } => {
2792                cursor.base(1)[0] = 12;
2793                from.encode(cursor);
2794                to.encode(cursor);
2795                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2796            }
2797            TraceOpLazy::GlobalChannelSend { channel } => {
2798                cursor.base(1)[0] = 13;
2799                channel.encode(cursor);
2800                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2801            }
2802            TraceOpLazy::GlobalChannelReceive { channel } => {
2803                cursor.base(1)[0] = 14;
2804                channel.encode(cursor);
2805                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
2806            }
2807            TraceOpLazy::GlobalChannelTransfer { from, to } => {
2808                cursor.base(1)[0] = 15;
2809                from.encode(cursor);
2810                to.encode(cursor);
2811                cursor.base(Self::BASE_LEN - 1 - (32)).fill(0);
2812            }
2813        }
2814    }
2815}
2816
2817impl<'a> Decode<'a> for TraceOpLazy<'a> {
2818    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
2819        let variant = cursor.base(1)[0];
2820        match variant {
2821            0 => {
2822                let source = Decode::decode(cursor)?;
2823                cursor.advance(Self::BASE_LEN - 1 - (8));
2824                Ok(TraceOpLazy::CreateSource {
2825                    source,
2826                })
2827            }
2828            1 => {
2829                let source = Decode::decode(cursor)?;
2830                cursor.advance(Self::BASE_LEN - 1 - (8));
2831                Ok(TraceOpLazy::DeleteSource {
2832                    source,
2833                })
2834            }
2835            2 => {
2836                let source = Decode::decode(cursor)?;
2837                cursor.advance(Self::BASE_LEN - 1 - (8));
2838                Ok(TraceOpLazy::Call {
2839                    source,
2840                })
2841            }
2842            3 => {
2843                cursor.advance(Self::BASE_LEN - 1);
2844                Ok(TraceOpLazy::PushScope)
2845            }
2846            4 => {
2847                cursor.advance(Self::BASE_LEN - 1);
2848                Ok(TraceOpLazy::PopScope)
2849            }
2850            5 => {
2851                cursor.advance(Self::BASE_LEN - 1);
2852                Ok(TraceOpLazy::BranchStart)
2853            }
2854            6 => {
2855                cursor.advance(Self::BASE_LEN - 1);
2856                Ok(TraceOpLazy::BranchEnd)
2857            }
2858            7 => {
2859                cursor.advance(Self::BASE_LEN - 1);
2860                Ok(TraceOpLazy::Label)
2861            }
2862            8 => {
2863                let tag = Decode::decode(cursor)?;
2864                cursor.advance(Self::BASE_LEN - 1 - (8));
2865                Ok(TraceOpLazy::Tag {
2866                    tag,
2867                })
2868            }
2869            9 => {
2870                let value = Decode::decode(cursor)?;
2871                cursor.advance(Self::BASE_LEN - 1 - (8));
2872                Ok(TraceOpLazy::Metric {
2873                    value,
2874                })
2875            }
2876            10 => {
2877                let channel = Decode::decode(cursor)?;
2878                cursor.advance(Self::BASE_LEN - 1 - (8));
2879                Ok(TraceOpLazy::ChannelSend {
2880                    channel,
2881                })
2882            }
2883            11 => {
2884                let channel = Decode::decode(cursor)?;
2885                let sender = Decode::decode(cursor)?;
2886                cursor.advance(Self::BASE_LEN - 1 - (28));
2887                Ok(TraceOpLazy::ChannelReceive {
2888                    channel,
2889                    sender,
2890                })
2891            }
2892            12 => {
2893                let from = Decode::decode(cursor)?;
2894                let to = Decode::decode(cursor)?;
2895                cursor.advance(Self::BASE_LEN - 1 - (16));
2896                Ok(TraceOpLazy::ChannelTransfer {
2897                    from,
2898                    to,
2899                })
2900            }
2901            13 => {
2902                let channel = Decode::decode(cursor)?;
2903                cursor.advance(Self::BASE_LEN - 1 - (16));
2904                Ok(TraceOpLazy::GlobalChannelSend {
2905                    channel,
2906                })
2907            }
2908            14 => {
2909                let channel = Decode::decode(cursor)?;
2910                cursor.advance(Self::BASE_LEN - 1 - (16));
2911                Ok(TraceOpLazy::GlobalChannelReceive {
2912                    channel,
2913                })
2914            }
2915            15 => {
2916                let from = Decode::decode(cursor)?;
2917                let to = Decode::decode(cursor)?;
2918                cursor.advance(Self::BASE_LEN - 1 - (32));
2919                Ok(TraceOpLazy::GlobalChannelTransfer {
2920                    from,
2921                    to,
2922                })
2923            }
2924            _ => { Err(DecodeError) }
2925        }
2926    }
2927}
2928
2929impl<'a> TryFrom<TraceOpLazy<'a>> for TraceOp {
2930    type Error = DecodeError;
2931
2932    fn try_from(other: TraceOpLazy<'a>) -> Result<Self, Self::Error> {
2933        match other {
2934            TraceOpLazy::CreateSource { source, } => {
2935                Ok(TraceOp::CreateSource {
2936                    source: Owned::lazy_to_owned(source)?,
2937                })
2938            }
2939            TraceOpLazy::DeleteSource { source, } => {
2940                Ok(TraceOp::DeleteSource {
2941                    source: Owned::lazy_to_owned(source)?,
2942                })
2943            }
2944            TraceOpLazy::Call { source, } => {
2945                Ok(TraceOp::Call {
2946                    source: Owned::lazy_to_owned(source)?,
2947                })
2948            }
2949            TraceOpLazy::PushScope => Ok(TraceOp::PushScope),
2950            TraceOpLazy::PopScope => Ok(TraceOp::PopScope),
2951            TraceOpLazy::BranchStart => Ok(TraceOp::BranchStart),
2952            TraceOpLazy::BranchEnd => Ok(TraceOp::BranchEnd),
2953            TraceOpLazy::Label => Ok(TraceOp::Label),
2954            TraceOpLazy::Tag { tag, } => {
2955                Ok(TraceOp::Tag {
2956                    tag: Owned::lazy_to_owned(tag)?,
2957                })
2958            }
2959            TraceOpLazy::Metric { value, } => {
2960                Ok(TraceOp::Metric {
2961                    value: Owned::lazy_to_owned(value)?,
2962                })
2963            }
2964            TraceOpLazy::ChannelSend { channel, } => {
2965                Ok(TraceOp::ChannelSend {
2966                    channel: Owned::lazy_to_owned(channel)?,
2967                })
2968            }
2969            TraceOpLazy::ChannelReceive { channel,sender, } => {
2970                Ok(TraceOp::ChannelReceive {
2971                    channel: Owned::lazy_to_owned(channel)?,
2972                    sender: Owned::lazy_to_owned(sender)?,
2973                })
2974            }
2975            TraceOpLazy::ChannelTransfer { from,to, } => {
2976                Ok(TraceOp::ChannelTransfer {
2977                    from: Owned::lazy_to_owned(from)?,
2978                    to: Owned::lazy_to_owned(to)?,
2979                })
2980            }
2981            TraceOpLazy::GlobalChannelSend { channel, } => {
2982                Ok(TraceOp::GlobalChannelSend {
2983                    channel: Owned::lazy_to_owned(channel)?,
2984                })
2985            }
2986            TraceOpLazy::GlobalChannelReceive { channel, } => {
2987                Ok(TraceOp::GlobalChannelReceive {
2988                    channel: Owned::lazy_to_owned(channel)?,
2989                })
2990            }
2991            TraceOpLazy::GlobalChannelTransfer { from,to, } => {
2992                Ok(TraceOp::GlobalChannelTransfer {
2993                    from: Owned::lazy_to_owned(from)?,
2994                    to: Owned::lazy_to_owned(to)?,
2995                })
2996            }
2997        }
2998    }
2999}
3000
3001impl<'a> Copy for TraceOpLazy<'a> { }
3002
3003impl<'a> core::fmt::Debug for TraceOpLazy<'a> {
3004    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3005        f.debug_struct("TraceOpLazy")
3006            .finish()
3007    }
3008}
3009
3010impl<'a> PartialEq for TraceOpLazy<'a> {
3011    fn eq(&self, other: &Self) -> bool {
3012        match (self, other) {
3013            (
3014                TraceOpLazy::CreateSource {
3015                    source: self_source
3016                },
3017                TraceOpLazy::CreateSource {
3018                    source: other_source
3019                },
3020            ) => {
3021                self_source == other_source
3022            }
3023            (
3024                TraceOpLazy::DeleteSource {
3025                    source: self_source
3026                },
3027                TraceOpLazy::DeleteSource {
3028                    source: other_source
3029                },
3030            ) => {
3031                self_source == other_source
3032            }
3033            (
3034                TraceOpLazy::Call {
3035                    source: self_source
3036                },
3037                TraceOpLazy::Call {
3038                    source: other_source
3039                },
3040            ) => {
3041                self_source == other_source
3042            }
3043            (TraceOpLazy::PushScope, TraceOpLazy::PushScope) => true,
3044            (TraceOpLazy::PopScope, TraceOpLazy::PopScope) => true,
3045            (TraceOpLazy::BranchStart, TraceOpLazy::BranchStart) => true,
3046            (TraceOpLazy::BranchEnd, TraceOpLazy::BranchEnd) => true,
3047            (TraceOpLazy::Label, TraceOpLazy::Label) => true,
3048            (
3049                TraceOpLazy::Tag {
3050                    tag: self_tag
3051                },
3052                TraceOpLazy::Tag {
3053                    tag: other_tag
3054                },
3055            ) => {
3056                self_tag == other_tag
3057            }
3058            (
3059                TraceOpLazy::Metric {
3060                    value: self_value
3061                },
3062                TraceOpLazy::Metric {
3063                    value: other_value
3064                },
3065            ) => {
3066                self_value == other_value
3067            }
3068            (
3069                TraceOpLazy::ChannelSend {
3070                    channel: self_channel
3071                },
3072                TraceOpLazy::ChannelSend {
3073                    channel: other_channel
3074                },
3075            ) => {
3076                self_channel == other_channel
3077            }
3078            (
3079                TraceOpLazy::ChannelReceive {
3080                    channel: self_channel, sender: self_sender
3081                },
3082                TraceOpLazy::ChannelReceive {
3083                    channel: other_channel, sender: other_sender
3084                },
3085            ) => {
3086                self_channel == other_channel
3087                    && self_sender == other_sender
3088            }
3089            (
3090                TraceOpLazy::ChannelTransfer {
3091                    from: self_from, to: self_to
3092                },
3093                TraceOpLazy::ChannelTransfer {
3094                    from: other_from, to: other_to
3095                },
3096            ) => {
3097                self_from == other_from
3098                    && self_to == other_to
3099            }
3100            (
3101                TraceOpLazy::GlobalChannelSend {
3102                    channel: self_channel
3103                },
3104                TraceOpLazy::GlobalChannelSend {
3105                    channel: other_channel
3106                },
3107            ) => {
3108                self_channel == other_channel
3109            }
3110            (
3111                TraceOpLazy::GlobalChannelReceive {
3112                    channel: self_channel
3113                },
3114                TraceOpLazy::GlobalChannelReceive {
3115                    channel: other_channel
3116                },
3117            ) => {
3118                self_channel == other_channel
3119            }
3120            (
3121                TraceOpLazy::GlobalChannelTransfer {
3122                    from: self_from, to: self_to
3123                },
3124                TraceOpLazy::GlobalChannelTransfer {
3125                    from: other_from, to: other_to
3126                },
3127            ) => {
3128                self_from == other_from
3129                    && self_to == other_to
3130            }
3131            #[allow(unreachable_patterns)]
3132            _ => false,
3133        }
3134    }
3135}
3136
3137#[cfg(any(feature = "std", feature = "alloc"))]
3138#[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
3139pub enum TraceOpAggregate {
3140    CreateSource,
3141    DeleteSource,
3142    Call {
3143        source: SourceId,
3144    },
3145    PushScope,
3146    PopScope,
3147    BranchStart {
3148        branch_end: u16,
3149    },
3150    BranchEnd {
3151        parent_branch_end: u16,
3152    },
3153    Label {
3154        label: String,
3155    },
3156    Tag,
3157    Metric {
3158        name: String,
3159        index: u16,
3160    },
3161    ChannelSend {
3162        channel: SourceId,
3163    },
3164    ChannelReceive {
3165        channel: SourceId,
3166    },
3167    ChannelTransfer {
3168        from: SourceId,
3169        to: SourceId,
3170    },
3171    GlobalChannelSend {
3172        channel: GlobalSourceId,
3173    },
3174    GlobalChannelReceive {
3175        channel: GlobalSourceId,
3176    },
3177    GlobalChannelTransfer {
3178        from: GlobalSourceId,
3179        to: GlobalSourceId,
3180    },
3181}
3182
3183#[derive(Clone)]
3184pub enum TraceOpAggregateLazy<'a> {
3185    CreateSource,
3186    DeleteSource,
3187    Call {
3188        source: SourceIdLazy<'a>,
3189    },
3190    PushScope,
3191    PopScope,
3192    BranchStart {
3193        branch_end: u16,
3194    },
3195    BranchEnd {
3196        parent_branch_end: u16,
3197    },
3198    Label {
3199        label: &'a str,
3200    },
3201    Tag,
3202    Metric {
3203        name: &'a str,
3204        index: u16,
3205    },
3206    ChannelSend {
3207        channel: SourceIdLazy<'a>,
3208    },
3209    ChannelReceive {
3210        channel: SourceIdLazy<'a>,
3211    },
3212    ChannelTransfer {
3213        from: SourceIdLazy<'a>,
3214        to: SourceIdLazy<'a>,
3215    },
3216    GlobalChannelSend {
3217        channel: GlobalSourceIdLazy<'a>,
3218    },
3219    GlobalChannelReceive {
3220        channel: GlobalSourceIdLazy<'a>,
3221    },
3222    GlobalChannelTransfer {
3223        from: GlobalSourceIdLazy<'a>,
3224        to: GlobalSourceIdLazy<'a>,
3225    },
3226}
3227
3228impl<'a> Compatible<TraceOpAggregateLazy<'a>> for TraceOpAggregateLazy<'a> { }
3229#[cfg(any(feature = "std", feature = "alloc"))]
3230impl<'a> Compatible<TraceOpAggregateLazy<'a>> for TraceOpAggregate { }
3231#[cfg(any(feature = "std", feature = "alloc"))]
3232impl<'a> Compatible<TraceOpAggregate> for TraceOpAggregateLazy<'a> { }
3233#[cfg(any(feature = "std", feature = "alloc"))]
3234impl Compatible<TraceOpAggregate> for TraceOpAggregate { }
3235
3236#[cfg(any(feature = "std", feature = "alloc"))]
3237impl Owned for TraceOpAggregate {
3238    type Lazy<'a> = TraceOpAggregateLazy<'a>;
3239
3240    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
3241        TryFrom::try_from(lazy)
3242    }
3243}
3244
3245impl<'a> Lazy<'a> for TraceOpAggregateLazy<'a> {
3246    type Owned = TraceOpAggregate;
3247}
3248
3249#[cfg(any(feature = "std", feature = "alloc"))]
3250impl BaseLen for TraceOpAggregate {
3251    const BASE_LEN: usize = 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32);
3252}
3253
3254impl Encode for TraceOpAggregate {
3255    fn scratch_len(&self) -> usize {
3256        match self {
3257            TraceOpAggregate::CreateSource => 0,
3258            TraceOpAggregate::DeleteSource => 0,
3259            TraceOpAggregate::Call { source } => {
3260                source.scratch_len()
3261            }
3262            TraceOpAggregate::PushScope => 0,
3263            TraceOpAggregate::PopScope => 0,
3264            TraceOpAggregate::BranchStart { branch_end } => {
3265                branch_end.scratch_len()
3266            }
3267            TraceOpAggregate::BranchEnd { parent_branch_end } => {
3268                parent_branch_end.scratch_len()
3269            }
3270            TraceOpAggregate::Label { label } => {
3271                label.scratch_len()
3272            }
3273            TraceOpAggregate::Tag => 0,
3274            TraceOpAggregate::Metric { name, index } => {
3275                name.scratch_len() + index.scratch_len()
3276            }
3277            TraceOpAggregate::ChannelSend { channel } => {
3278                channel.scratch_len()
3279            }
3280            TraceOpAggregate::ChannelReceive { channel } => {
3281                channel.scratch_len()
3282            }
3283            TraceOpAggregate::ChannelTransfer { from, to } => {
3284                from.scratch_len() + to.scratch_len()
3285            }
3286            TraceOpAggregate::GlobalChannelSend { channel } => {
3287                channel.scratch_len()
3288            }
3289            TraceOpAggregate::GlobalChannelReceive { channel } => {
3290                channel.scratch_len()
3291            }
3292            TraceOpAggregate::GlobalChannelTransfer { from, to } => {
3293                from.scratch_len() + to.scratch_len()
3294            }
3295        }
3296    }
3297
3298    fn encode(&self, cursor: &mut EncodeCursor) {
3299        match self {
3300            TraceOpAggregate::CreateSource => {
3301                cursor.base(1)[0] = 0;
3302                cursor.base(Self::BASE_LEN - 1).fill(0);
3303            }
3304            TraceOpAggregate::DeleteSource => {
3305                cursor.base(1)[0] = 1;
3306                cursor.base(Self::BASE_LEN - 1).fill(0);
3307            }
3308            TraceOpAggregate::Call { source } => {
3309                cursor.base(1)[0] = 2;
3310                source.encode(cursor);
3311                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3312            }
3313            TraceOpAggregate::PushScope => {
3314                cursor.base(1)[0] = 3;
3315                cursor.base(Self::BASE_LEN - 1).fill(0);
3316            }
3317            TraceOpAggregate::PopScope => {
3318                cursor.base(1)[0] = 4;
3319                cursor.base(Self::BASE_LEN - 1).fill(0);
3320            }
3321            TraceOpAggregate::BranchStart { branch_end } => {
3322                cursor.base(1)[0] = 5;
3323                branch_end.encode(cursor);
3324                cursor.base(Self::BASE_LEN - 1 - (2)).fill(0);
3325            }
3326            TraceOpAggregate::BranchEnd { parent_branch_end } => {
3327                cursor.base(1)[0] = 6;
3328                parent_branch_end.encode(cursor);
3329                cursor.base(Self::BASE_LEN - 1 - (2)).fill(0);
3330            }
3331            TraceOpAggregate::Label { label } => {
3332                cursor.base(1)[0] = 7;
3333                label.encode(cursor);
3334                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3335            }
3336            TraceOpAggregate::Tag => {
3337                cursor.base(1)[0] = 8;
3338                cursor.base(Self::BASE_LEN - 1).fill(0);
3339            }
3340            TraceOpAggregate::Metric { name, index } => {
3341                cursor.base(1)[0] = 9;
3342                name.encode(cursor);
3343                index.encode(cursor);
3344                cursor.base(Self::BASE_LEN - 1 - (10)).fill(0);
3345            }
3346            TraceOpAggregate::ChannelSend { channel } => {
3347                cursor.base(1)[0] = 10;
3348                channel.encode(cursor);
3349                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3350            }
3351            TraceOpAggregate::ChannelReceive { channel } => {
3352                cursor.base(1)[0] = 11;
3353                channel.encode(cursor);
3354                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3355            }
3356            TraceOpAggregate::ChannelTransfer { from, to } => {
3357                cursor.base(1)[0] = 12;
3358                from.encode(cursor);
3359                to.encode(cursor);
3360                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3361            }
3362            TraceOpAggregate::GlobalChannelSend { channel } => {
3363                cursor.base(1)[0] = 13;
3364                channel.encode(cursor);
3365                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3366            }
3367            TraceOpAggregate::GlobalChannelReceive { channel } => {
3368                cursor.base(1)[0] = 14;
3369                channel.encode(cursor);
3370                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3371            }
3372            TraceOpAggregate::GlobalChannelTransfer { from, to } => {
3373                cursor.base(1)[0] = 15;
3374                from.encode(cursor);
3375                to.encode(cursor);
3376                cursor.base(Self::BASE_LEN - 1 - (32)).fill(0);
3377            }
3378        }
3379    }
3380}
3381
3382#[cfg(any(feature = "std", feature = "alloc"))]
3383impl<'a> Decode<'a> for TraceOpAggregate {
3384    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
3385        let variant = cursor.base(1)[0];
3386        match variant {
3387            0 => {
3388                cursor.advance(Self::BASE_LEN - 1);
3389                Ok(TraceOpAggregate::CreateSource)
3390            }
3391            1 => {
3392                cursor.advance(Self::BASE_LEN - 1);
3393                Ok(TraceOpAggregate::DeleteSource)
3394            }
3395            2 => {
3396                let source = Decode::decode(cursor)?;
3397                cursor.advance(Self::BASE_LEN - 1 - (8));
3398                Ok(TraceOpAggregate::Call {
3399                    source,
3400                })
3401            }
3402            3 => {
3403                cursor.advance(Self::BASE_LEN - 1);
3404                Ok(TraceOpAggregate::PushScope)
3405            }
3406            4 => {
3407                cursor.advance(Self::BASE_LEN - 1);
3408                Ok(TraceOpAggregate::PopScope)
3409            }
3410            5 => {
3411                let branch_end = Decode::decode(cursor)?;
3412                cursor.advance(Self::BASE_LEN - 1 - (2));
3413                Ok(TraceOpAggregate::BranchStart {
3414                    branch_end,
3415                })
3416            }
3417            6 => {
3418                let parent_branch_end = Decode::decode(cursor)?;
3419                cursor.advance(Self::BASE_LEN - 1 - (2));
3420                Ok(TraceOpAggregate::BranchEnd {
3421                    parent_branch_end,
3422                })
3423            }
3424            7 => {
3425                let label = Decode::decode(cursor)?;
3426                cursor.advance(Self::BASE_LEN - 1 - (8));
3427                Ok(TraceOpAggregate::Label {
3428                    label,
3429                })
3430            }
3431            8 => {
3432                cursor.advance(Self::BASE_LEN - 1);
3433                Ok(TraceOpAggregate::Tag)
3434            }
3435            9 => {
3436                let name = Decode::decode(cursor)?;
3437                let index = Decode::decode(cursor)?;
3438                cursor.advance(Self::BASE_LEN - 1 - (10));
3439                Ok(TraceOpAggregate::Metric {
3440                    name,
3441                    index,
3442                })
3443            }
3444            10 => {
3445                let channel = Decode::decode(cursor)?;
3446                cursor.advance(Self::BASE_LEN - 1 - (8));
3447                Ok(TraceOpAggregate::ChannelSend {
3448                    channel,
3449                })
3450            }
3451            11 => {
3452                let channel = Decode::decode(cursor)?;
3453                cursor.advance(Self::BASE_LEN - 1 - (8));
3454                Ok(TraceOpAggregate::ChannelReceive {
3455                    channel,
3456                })
3457            }
3458            12 => {
3459                let from = Decode::decode(cursor)?;
3460                let to = Decode::decode(cursor)?;
3461                cursor.advance(Self::BASE_LEN - 1 - (16));
3462                Ok(TraceOpAggregate::ChannelTransfer {
3463                    from,
3464                    to,
3465                })
3466            }
3467            13 => {
3468                let channel = Decode::decode(cursor)?;
3469                cursor.advance(Self::BASE_LEN - 1 - (16));
3470                Ok(TraceOpAggregate::GlobalChannelSend {
3471                    channel,
3472                })
3473            }
3474            14 => {
3475                let channel = Decode::decode(cursor)?;
3476                cursor.advance(Self::BASE_LEN - 1 - (16));
3477                Ok(TraceOpAggregate::GlobalChannelReceive {
3478                    channel,
3479                })
3480            }
3481            15 => {
3482                let from = Decode::decode(cursor)?;
3483                let to = Decode::decode(cursor)?;
3484                cursor.advance(Self::BASE_LEN - 1 - (32));
3485                Ok(TraceOpAggregate::GlobalChannelTransfer {
3486                    from,
3487                    to,
3488                })
3489            }
3490            _ => { Err(DecodeError) }
3491        }
3492    }
3493}
3494
3495impl<'a> BaseLen for TraceOpAggregateLazy<'a> {
3496    const BASE_LEN: usize = 1 + max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(max(0, 0), 0), 8), 0), 0), 2), 2), 8), 0), 10), 8), 8), 16), 16), 16), 32);
3497}
3498
3499impl<'a> Encode for TraceOpAggregateLazy<'a> {
3500    fn scratch_len(&self) -> usize {
3501        match self {
3502            TraceOpAggregateLazy::CreateSource => 0,
3503            TraceOpAggregateLazy::DeleteSource => 0,
3504            TraceOpAggregateLazy::Call { source } => {
3505                source.scratch_len()
3506            }
3507            TraceOpAggregateLazy::PushScope => 0,
3508            TraceOpAggregateLazy::PopScope => 0,
3509            TraceOpAggregateLazy::BranchStart { branch_end } => {
3510                branch_end.scratch_len()
3511            }
3512            TraceOpAggregateLazy::BranchEnd { parent_branch_end } => {
3513                parent_branch_end.scratch_len()
3514            }
3515            TraceOpAggregateLazy::Label { label } => {
3516                label.scratch_len()
3517            }
3518            TraceOpAggregateLazy::Tag => 0,
3519            TraceOpAggregateLazy::Metric { name, index } => {
3520                name.scratch_len() + index.scratch_len()
3521            }
3522            TraceOpAggregateLazy::ChannelSend { channel } => {
3523                channel.scratch_len()
3524            }
3525            TraceOpAggregateLazy::ChannelReceive { channel } => {
3526                channel.scratch_len()
3527            }
3528            TraceOpAggregateLazy::ChannelTransfer { from, to } => {
3529                from.scratch_len() + to.scratch_len()
3530            }
3531            TraceOpAggregateLazy::GlobalChannelSend { channel } => {
3532                channel.scratch_len()
3533            }
3534            TraceOpAggregateLazy::GlobalChannelReceive { channel } => {
3535                channel.scratch_len()
3536            }
3537            TraceOpAggregateLazy::GlobalChannelTransfer { from, to } => {
3538                from.scratch_len() + to.scratch_len()
3539            }
3540        }
3541    }
3542
3543    fn encode(&self, cursor: &mut EncodeCursor) {
3544        match self {
3545            TraceOpAggregateLazy::CreateSource => {
3546                cursor.base(1)[0] = 0;
3547                cursor.base(Self::BASE_LEN - 1).fill(0);
3548            }
3549            TraceOpAggregateLazy::DeleteSource => {
3550                cursor.base(1)[0] = 1;
3551                cursor.base(Self::BASE_LEN - 1).fill(0);
3552            }
3553            TraceOpAggregateLazy::Call { source } => {
3554                cursor.base(1)[0] = 2;
3555                source.encode(cursor);
3556                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3557            }
3558            TraceOpAggregateLazy::PushScope => {
3559                cursor.base(1)[0] = 3;
3560                cursor.base(Self::BASE_LEN - 1).fill(0);
3561            }
3562            TraceOpAggregateLazy::PopScope => {
3563                cursor.base(1)[0] = 4;
3564                cursor.base(Self::BASE_LEN - 1).fill(0);
3565            }
3566            TraceOpAggregateLazy::BranchStart { branch_end } => {
3567                cursor.base(1)[0] = 5;
3568                branch_end.encode(cursor);
3569                cursor.base(Self::BASE_LEN - 1 - (2)).fill(0);
3570            }
3571            TraceOpAggregateLazy::BranchEnd { parent_branch_end } => {
3572                cursor.base(1)[0] = 6;
3573                parent_branch_end.encode(cursor);
3574                cursor.base(Self::BASE_LEN - 1 - (2)).fill(0);
3575            }
3576            TraceOpAggregateLazy::Label { label } => {
3577                cursor.base(1)[0] = 7;
3578                label.encode(cursor);
3579                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3580            }
3581            TraceOpAggregateLazy::Tag => {
3582                cursor.base(1)[0] = 8;
3583                cursor.base(Self::BASE_LEN - 1).fill(0);
3584            }
3585            TraceOpAggregateLazy::Metric { name, index } => {
3586                cursor.base(1)[0] = 9;
3587                name.encode(cursor);
3588                index.encode(cursor);
3589                cursor.base(Self::BASE_LEN - 1 - (10)).fill(0);
3590            }
3591            TraceOpAggregateLazy::ChannelSend { channel } => {
3592                cursor.base(1)[0] = 10;
3593                channel.encode(cursor);
3594                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3595            }
3596            TraceOpAggregateLazy::ChannelReceive { channel } => {
3597                cursor.base(1)[0] = 11;
3598                channel.encode(cursor);
3599                cursor.base(Self::BASE_LEN - 1 - (8)).fill(0);
3600            }
3601            TraceOpAggregateLazy::ChannelTransfer { from, to } => {
3602                cursor.base(1)[0] = 12;
3603                from.encode(cursor);
3604                to.encode(cursor);
3605                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3606            }
3607            TraceOpAggregateLazy::GlobalChannelSend { channel } => {
3608                cursor.base(1)[0] = 13;
3609                channel.encode(cursor);
3610                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3611            }
3612            TraceOpAggregateLazy::GlobalChannelReceive { channel } => {
3613                cursor.base(1)[0] = 14;
3614                channel.encode(cursor);
3615                cursor.base(Self::BASE_LEN - 1 - (16)).fill(0);
3616            }
3617            TraceOpAggregateLazy::GlobalChannelTransfer { from, to } => {
3618                cursor.base(1)[0] = 15;
3619                from.encode(cursor);
3620                to.encode(cursor);
3621                cursor.base(Self::BASE_LEN - 1 - (32)).fill(0);
3622            }
3623        }
3624    }
3625}
3626
3627impl<'a> Decode<'a> for TraceOpAggregateLazy<'a> {
3628    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
3629        let variant = cursor.base(1)[0];
3630        match variant {
3631            0 => {
3632                cursor.advance(Self::BASE_LEN - 1);
3633                Ok(TraceOpAggregateLazy::CreateSource)
3634            }
3635            1 => {
3636                cursor.advance(Self::BASE_LEN - 1);
3637                Ok(TraceOpAggregateLazy::DeleteSource)
3638            }
3639            2 => {
3640                let source = Decode::decode(cursor)?;
3641                cursor.advance(Self::BASE_LEN - 1 - (8));
3642                Ok(TraceOpAggregateLazy::Call {
3643                    source,
3644                })
3645            }
3646            3 => {
3647                cursor.advance(Self::BASE_LEN - 1);
3648                Ok(TraceOpAggregateLazy::PushScope)
3649            }
3650            4 => {
3651                cursor.advance(Self::BASE_LEN - 1);
3652                Ok(TraceOpAggregateLazy::PopScope)
3653            }
3654            5 => {
3655                let branch_end = Decode::decode(cursor)?;
3656                cursor.advance(Self::BASE_LEN - 1 - (2));
3657                Ok(TraceOpAggregateLazy::BranchStart {
3658                    branch_end,
3659                })
3660            }
3661            6 => {
3662                let parent_branch_end = Decode::decode(cursor)?;
3663                cursor.advance(Self::BASE_LEN - 1 - (2));
3664                Ok(TraceOpAggregateLazy::BranchEnd {
3665                    parent_branch_end,
3666                })
3667            }
3668            7 => {
3669                let label = Decode::decode(cursor)?;
3670                cursor.advance(Self::BASE_LEN - 1 - (8));
3671                Ok(TraceOpAggregateLazy::Label {
3672                    label,
3673                })
3674            }
3675            8 => {
3676                cursor.advance(Self::BASE_LEN - 1);
3677                Ok(TraceOpAggregateLazy::Tag)
3678            }
3679            9 => {
3680                let name = Decode::decode(cursor)?;
3681                let index = Decode::decode(cursor)?;
3682                cursor.advance(Self::BASE_LEN - 1 - (10));
3683                Ok(TraceOpAggregateLazy::Metric {
3684                    name,
3685                    index,
3686                })
3687            }
3688            10 => {
3689                let channel = Decode::decode(cursor)?;
3690                cursor.advance(Self::BASE_LEN - 1 - (8));
3691                Ok(TraceOpAggregateLazy::ChannelSend {
3692                    channel,
3693                })
3694            }
3695            11 => {
3696                let channel = Decode::decode(cursor)?;
3697                cursor.advance(Self::BASE_LEN - 1 - (8));
3698                Ok(TraceOpAggregateLazy::ChannelReceive {
3699                    channel,
3700                })
3701            }
3702            12 => {
3703                let from = Decode::decode(cursor)?;
3704                let to = Decode::decode(cursor)?;
3705                cursor.advance(Self::BASE_LEN - 1 - (16));
3706                Ok(TraceOpAggregateLazy::ChannelTransfer {
3707                    from,
3708                    to,
3709                })
3710            }
3711            13 => {
3712                let channel = Decode::decode(cursor)?;
3713                cursor.advance(Self::BASE_LEN - 1 - (16));
3714                Ok(TraceOpAggregateLazy::GlobalChannelSend {
3715                    channel,
3716                })
3717            }
3718            14 => {
3719                let channel = Decode::decode(cursor)?;
3720                cursor.advance(Self::BASE_LEN - 1 - (16));
3721                Ok(TraceOpAggregateLazy::GlobalChannelReceive {
3722                    channel,
3723                })
3724            }
3725            15 => {
3726                let from = Decode::decode(cursor)?;
3727                let to = Decode::decode(cursor)?;
3728                cursor.advance(Self::BASE_LEN - 1 - (32));
3729                Ok(TraceOpAggregateLazy::GlobalChannelTransfer {
3730                    from,
3731                    to,
3732                })
3733            }
3734            _ => { Err(DecodeError) }
3735        }
3736    }
3737}
3738
3739#[cfg(any(feature = "std", feature = "alloc"))]
3740impl<'a> TryFrom<TraceOpAggregateLazy<'a>> for TraceOpAggregate {
3741    type Error = DecodeError;
3742
3743    fn try_from(other: TraceOpAggregateLazy<'a>) -> Result<Self, Self::Error> {
3744        match other {
3745            TraceOpAggregateLazy::CreateSource => Ok(TraceOpAggregate::CreateSource),
3746            TraceOpAggregateLazy::DeleteSource => Ok(TraceOpAggregate::DeleteSource),
3747            TraceOpAggregateLazy::Call { source, } => {
3748                Ok(TraceOpAggregate::Call {
3749                    source: Owned::lazy_to_owned(source)?,
3750                })
3751            }
3752            TraceOpAggregateLazy::PushScope => Ok(TraceOpAggregate::PushScope),
3753            TraceOpAggregateLazy::PopScope => Ok(TraceOpAggregate::PopScope),
3754            TraceOpAggregateLazy::BranchStart { branch_end, } => {
3755                Ok(TraceOpAggregate::BranchStart {
3756                    branch_end: Owned::lazy_to_owned(branch_end)?,
3757                })
3758            }
3759            TraceOpAggregateLazy::BranchEnd { parent_branch_end, } => {
3760                Ok(TraceOpAggregate::BranchEnd {
3761                    parent_branch_end: Owned::lazy_to_owned(parent_branch_end)?,
3762                })
3763            }
3764            TraceOpAggregateLazy::Label { label, } => {
3765                Ok(TraceOpAggregate::Label {
3766                    label: Owned::lazy_to_owned(label)?,
3767                })
3768            }
3769            TraceOpAggregateLazy::Tag => Ok(TraceOpAggregate::Tag),
3770            TraceOpAggregateLazy::Metric { name,index, } => {
3771                Ok(TraceOpAggregate::Metric {
3772                    name: Owned::lazy_to_owned(name)?,
3773                    index: Owned::lazy_to_owned(index)?,
3774                })
3775            }
3776            TraceOpAggregateLazy::ChannelSend { channel, } => {
3777                Ok(TraceOpAggregate::ChannelSend {
3778                    channel: Owned::lazy_to_owned(channel)?,
3779                })
3780            }
3781            TraceOpAggregateLazy::ChannelReceive { channel, } => {
3782                Ok(TraceOpAggregate::ChannelReceive {
3783                    channel: Owned::lazy_to_owned(channel)?,
3784                })
3785            }
3786            TraceOpAggregateLazy::ChannelTransfer { from,to, } => {
3787                Ok(TraceOpAggregate::ChannelTransfer {
3788                    from: Owned::lazy_to_owned(from)?,
3789                    to: Owned::lazy_to_owned(to)?,
3790                })
3791            }
3792            TraceOpAggregateLazy::GlobalChannelSend { channel, } => {
3793                Ok(TraceOpAggregate::GlobalChannelSend {
3794                    channel: Owned::lazy_to_owned(channel)?,
3795                })
3796            }
3797            TraceOpAggregateLazy::GlobalChannelReceive { channel, } => {
3798                Ok(TraceOpAggregate::GlobalChannelReceive {
3799                    channel: Owned::lazy_to_owned(channel)?,
3800                })
3801            }
3802            TraceOpAggregateLazy::GlobalChannelTransfer { from,to, } => {
3803                Ok(TraceOpAggregate::GlobalChannelTransfer {
3804                    from: Owned::lazy_to_owned(from)?,
3805                    to: Owned::lazy_to_owned(to)?,
3806                })
3807            }
3808        }
3809    }
3810}
3811
3812impl<'a> Copy for TraceOpAggregateLazy<'a> { }
3813
3814impl<'a> core::fmt::Debug for TraceOpAggregateLazy<'a> {
3815    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3816        f.debug_struct("TraceOpAggregateLazy")
3817            .finish()
3818    }
3819}
3820
3821impl<'a> PartialEq for TraceOpAggregateLazy<'a> {
3822    fn eq(&self, other: &Self) -> bool {
3823        match (self, other) {
3824            (TraceOpAggregateLazy::CreateSource, TraceOpAggregateLazy::CreateSource) => true,
3825            (TraceOpAggregateLazy::DeleteSource, TraceOpAggregateLazy::DeleteSource) => true,
3826            (
3827                TraceOpAggregateLazy::Call {
3828                    source: self_source
3829                },
3830                TraceOpAggregateLazy::Call {
3831                    source: other_source
3832                },
3833            ) => {
3834                self_source == other_source
3835            }
3836            (TraceOpAggregateLazy::PushScope, TraceOpAggregateLazy::PushScope) => true,
3837            (TraceOpAggregateLazy::PopScope, TraceOpAggregateLazy::PopScope) => true,
3838            (
3839                TraceOpAggregateLazy::BranchStart {
3840                    branch_end: self_branch_end
3841                },
3842                TraceOpAggregateLazy::BranchStart {
3843                    branch_end: other_branch_end
3844                },
3845            ) => {
3846                self_branch_end == other_branch_end
3847            }
3848            (
3849                TraceOpAggregateLazy::BranchEnd {
3850                    parent_branch_end: self_parent_branch_end
3851                },
3852                TraceOpAggregateLazy::BranchEnd {
3853                    parent_branch_end: other_parent_branch_end
3854                },
3855            ) => {
3856                self_parent_branch_end == other_parent_branch_end
3857            }
3858            (
3859                TraceOpAggregateLazy::Label {
3860                    label: self_label
3861                },
3862                TraceOpAggregateLazy::Label {
3863                    label: other_label
3864                },
3865            ) => {
3866                self_label == other_label
3867            }
3868            (TraceOpAggregateLazy::Tag, TraceOpAggregateLazy::Tag) => true,
3869            (
3870                TraceOpAggregateLazy::Metric {
3871                    name: self_name, index: self_index
3872                },
3873                TraceOpAggregateLazy::Metric {
3874                    name: other_name, index: other_index
3875                },
3876            ) => {
3877                self_name == other_name
3878                    && self_index == other_index
3879            }
3880            (
3881                TraceOpAggregateLazy::ChannelSend {
3882                    channel: self_channel
3883                },
3884                TraceOpAggregateLazy::ChannelSend {
3885                    channel: other_channel
3886                },
3887            ) => {
3888                self_channel == other_channel
3889            }
3890            (
3891                TraceOpAggregateLazy::ChannelReceive {
3892                    channel: self_channel
3893                },
3894                TraceOpAggregateLazy::ChannelReceive {
3895                    channel: other_channel
3896                },
3897            ) => {
3898                self_channel == other_channel
3899            }
3900            (
3901                TraceOpAggregateLazy::ChannelTransfer {
3902                    from: self_from, to: self_to
3903                },
3904                TraceOpAggregateLazy::ChannelTransfer {
3905                    from: other_from, to: other_to
3906                },
3907            ) => {
3908                self_from == other_from
3909                    && self_to == other_to
3910            }
3911            (
3912                TraceOpAggregateLazy::GlobalChannelSend {
3913                    channel: self_channel
3914                },
3915                TraceOpAggregateLazy::GlobalChannelSend {
3916                    channel: other_channel
3917                },
3918            ) => {
3919                self_channel == other_channel
3920            }
3921            (
3922                TraceOpAggregateLazy::GlobalChannelReceive {
3923                    channel: self_channel
3924                },
3925                TraceOpAggregateLazy::GlobalChannelReceive {
3926                    channel: other_channel
3927                },
3928            ) => {
3929                self_channel == other_channel
3930            }
3931            (
3932                TraceOpAggregateLazy::GlobalChannelTransfer {
3933                    from: self_from, to: self_to
3934                },
3935                TraceOpAggregateLazy::GlobalChannelTransfer {
3936                    from: other_from, to: other_to
3937                },
3938            ) => {
3939                self_from == other_from
3940                    && self_to == other_to
3941            }
3942            #[allow(unreachable_patterns)]
3943            _ => false,
3944        }
3945    }
3946}
3947
3948#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
3949pub struct MetricAggregate {
3950    pub count: u64,
3951    pub sum: i64,
3952    pub min: i64,
3953    pub max: i64,
3954}
3955
3956pub struct MetricAggregateLazy<'a> {
3957    buffer: &'a [u8],
3958    offset: usize,
3959}
3960
3961pub struct MetricAggregateGen<> {
3962    pub count: u64,
3963    pub sum: i64,
3964    pub min: i64,
3965    pub max: i64,
3966}
3967
3968impl<> Compatible<MetricAggregate> for MetricAggregateGen<> { }
3969impl<> Compatible<MetricAggregateGen<>> for MetricAggregate { }
3970
3971impl<> BaseLen for MetricAggregateGen<> {
3972    const BASE_LEN: usize = 32;
3973}
3974
3975impl<> Encode for MetricAggregateGen<> {
3976    fn scratch_len(&self) -> usize {
3977        self.count.scratch_len() + self.sum.scratch_len() + self.min.scratch_len() + self.max.scratch_len()
3978    }
3979
3980    fn encode(&self, cursor: &mut EncodeCursor) {
3981        self.count.encode(cursor);
3982        self.sum.encode(cursor);
3983        self.min.encode(cursor);
3984        self.max.encode(cursor);
3985    }
3986}
3987
3988impl Owned for MetricAggregate {
3989    type Lazy<'a> = MetricAggregateLazy<'a>;
3990
3991    fn lazy_to_owned(lazy: Self::Lazy<'_>) -> DecodeResult<Self> {
3992        TryFrom::try_from(lazy)
3993    }
3994}
3995
3996impl<'a> Lazy<'a> for MetricAggregateLazy<'a> {
3997    type Owned = MetricAggregate;
3998}
3999
4000impl<'a> Compatible<MetricAggregateLazy<'a>> for MetricAggregateLazy<'a> { }
4001impl<'a> Compatible<MetricAggregateLazy<'a>> for MetricAggregate { }
4002impl Compatible<MetricAggregate> for MetricAggregate { }
4003impl<'a> Compatible<MetricAggregate> for MetricAggregateLazy<'a> { }
4004
4005impl<'a> MetricAggregateLazy<'a> {
4006
4007    pub fn count(&self) -> DecodeResult<u64> {
4008        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0))
4009    }
4010
4011    pub fn sum(&self) -> DecodeResult<i64> {
4012        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8))
4013    }
4014
4015    pub fn min(&self) -> DecodeResult<i64> {
4016        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16))
4017    }
4018
4019    pub fn max(&self) -> DecodeResult<i64> {
4020        Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24))
4021    }
4022}
4023
4024impl BaseLen for MetricAggregate {
4025    const BASE_LEN: usize = 32;
4026}
4027
4028impl Encode for MetricAggregate {
4029    fn scratch_len(&self) -> usize {
4030        self.count.scratch_len() + self.sum.scratch_len() + self.min.scratch_len() + self.max.scratch_len()
4031    }
4032
4033    fn encode(&self, cursor: &mut EncodeCursor) {
4034        self.count.encode(cursor);
4035        self.sum.encode(cursor);
4036        self.min.encode(cursor);
4037        self.max.encode(cursor);
4038    }
4039}
4040
4041impl<'a> Decode<'a> for MetricAggregate {
4042    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
4043        let count = Decode::decode(cursor)?;
4044        let sum = Decode::decode(cursor)?;
4045        let min = Decode::decode(cursor)?;
4046        let max = Decode::decode(cursor)?;
4047
4048        Ok(MetricAggregate {
4049            count,
4050            sum,
4051            min,
4052            max,
4053        })
4054    }
4055}
4056
4057impl<'a> BaseLen for MetricAggregateLazy<'a> {
4058    const BASE_LEN: usize = 32;
4059}
4060
4061impl<'a> Encode for MetricAggregateLazy<'a> {
4062    fn scratch_len(&self) -> usize {
4063        let count: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
4064        let sum: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
4065        let min: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
4066        let max: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
4067        count.scratch_len() + sum.scratch_len() + min.scratch_len() + max.scratch_len()
4068    }
4069
4070    fn encode(&self, cursor: &mut EncodeCursor) {
4071        let count: u64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 0)).unwrap();
4072        let sum: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 8)).unwrap();
4073        let min: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 16)).unwrap();
4074        let max: i64 = Decode::decode(&DecodeCursor::at_offset(self.buffer, self.offset + 24)).unwrap();
4075        count.encode(cursor);
4076        sum.encode(cursor);
4077        min.encode(cursor);
4078        max.encode(cursor);
4079    }
4080}
4081
4082impl<'a> Decode<'a> for MetricAggregateLazy<'a> {
4083    fn decode(cursor: &DecodeCursor<'a>) -> DecodeResult<Self> {
4084        let offset = cursor.offset();
4085        cursor.advance(Self::BASE_LEN);
4086        Ok(MetricAggregateLazy {
4087            buffer: cursor.buffer(),
4088            offset,
4089        })
4090    }
4091}
4092
4093impl<'a> TryFrom<MetricAggregateLazy<'a>> for MetricAggregate {
4094    type Error = DecodeError;
4095
4096    fn try_from(other: MetricAggregateLazy<'a>) -> Result<Self, Self::Error> {
4097        let cursor = DecodeCursor::at_offset(other.buffer, other.offset);
4098        Decode::decode(&cursor)
4099    }
4100}
4101
4102impl<'a> Copy for MetricAggregateLazy<'a> { }
4103
4104impl<'a> Clone for MetricAggregateLazy<'a> {
4105    fn clone(&self) -> Self {
4106        Self {
4107            buffer: self.buffer,
4108            offset: self.offset,
4109        }
4110    }
4111}
4112
4113impl<'a> core::fmt::Debug for MetricAggregateLazy<'a> {
4114    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
4115        f.debug_struct("MetricAggregateLazy")
4116            .finish()
4117    }
4118}
4119
4120impl<'a> PartialEq for MetricAggregateLazy<'a> {
4121    fn eq(&self, other: &Self) -> bool {
4122        self.count().unwrap() == other.count().unwrap()
4123            && self.sum().unwrap() == other.sum().unwrap()&& self.min().unwrap() == other.min().unwrap()&& self.max().unwrap() == other.max().unwrap()
4124    }
4125}