substreams 0.8.0-beta

Substreams SDK - A streaming data engine for The Graph - by StreamingFast
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
// @generated by buffa-codegen. DO NOT EDIT.
// source: sf/substreams/v1/deltas.proto

/** Lazy view of `sf.substreams.v1.StoreDeltas`: nested and repeated message fields are
 recorded as undecoded byte ranges and decoded on access. See
 [`::buffa::LazyMessageView`] for the deferred-validation contract;
 the eager, whole-tree-validated counterpart is named `StoreDeltasView`.

 Oneof variants, map values, groups, and extern-typed fields (e.g.
 well-known types) hold eagerly-decoded `StoreDeltasView`-family
 types; only singular/repeated message fields defer.

 # Examples

 ```rust,ignore
 use buffa::LazyMessageView;

 let view = StoreDeltasLazyView::decode_lazy(&bytes)?;
 ```*/
#[derive(Clone, Debug, Default)]
pub struct StoreDeltasLazyView<'a> {
    /// Field 1: `store_deltas`
    pub store_deltas: ::buffa::LazyRepeatedView<
        'a,
        super::super::__buffa::lazy_view::StoreDeltaLazyView<'a>,
    >,
}
impl<'a> StoreDeltasLazyView<'a> {
    /// Decode from `buf` under the limits carried by `ctx`, recording
    /// nested/repeated message fields as byte ranges.
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _decode_lazy_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let mut view = Self::default();
        view._merge_lazy(buf, ctx)?;
        ::core::result::Result::Ok(view)
    }
    /// Merge fields from `buf` into this view (proto merge semantics;
    /// deferred message fragments accumulate).
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        let _ = ctx;
        #[allow(unused_variables)]
        let view = self;
        let mut cur: &'a [u8] = buf;
        while !cur.is_empty() {
            let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
            match tag.field_number() {
                1u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::LengthDelimited,
                    )?;
                    let __sub_ctx = ctx.descend()?;
                    let sub = ::buffa::types::borrow_bytes(&mut cur)?;
                    ctx.register_element_memory(::core::mem::size_of::<&'a [u8]>())?;
                    view.store_deltas.push_bytes(sub, __sub_ctx);
                }
                _ => {
                    ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
                }
            }
        }
        ::core::result::Result::Ok(())
    }
}
impl<'a> ::buffa::LazyMessageView<'a> for StoreDeltasLazyView<'a> {
    type Owned = super::super::StoreDeltas;
    fn decode_lazy(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
        let __elem = ::core::cell::Cell::new(::buffa::DEFAULT_ELEMENT_MEMORY_LIMIT);
        Self::_decode_lazy_ctx(
            buf,
            ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit)
                .with_element_memory(&__elem),
        )
    }
    fn decode_lazy_with_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        Self::_decode_lazy_ctx(buf, ctx)
    }
    fn merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        self._merge_lazy(buf, ctx)
    }
    #[allow(clippy::useless_conversion, clippy::needless_update)]
    fn to_owned_message(
        &self,
    ) -> ::core::result::Result<super::super::StoreDeltas, ::buffa::DecodeError> {
        #[allow(unused_imports)]
        use ::buffa::alloc::string::ToString as _;
        #[allow(unused_imports)]
        use ::buffa::MessageView as _;
        let __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes> = ::core::option::Option::None;
        let _ = __buffa_src;
        ::core::result::Result::Ok(super::super::StoreDeltas {
            store_deltas: {
                let mut __out = ::buffa::alloc::vec::Vec::with_capacity(
                    self.store_deltas.len(),
                );
                for __r in self.store_deltas.iter() {
                    __out.push(__r?.to_owned_message()?);
                }
                __out
            },
            ..::core::default::Default::default()
        })
    }
}
/// Re-encoding: recorded fragments are replayed byte-for-byte
/// **without validation** — wire-equivalent to the merged value, and
/// a never-accessed malformed deferred field round-trips silently.
/// Inherent rather than [`::buffa::ViewEncode`] (whose `MessageView`
/// supertrait carries the eager whole-tree-validated contract); the
/// fuller `ViewEncode` set (`encode_length_delimited`,
/// `encode_with_cache`) lives on the eager view.
impl<'a> StoreDeltasLazyView<'a> {
    /// Compute the encoded byte size, filling `cache` with
    /// per-message sizes consumed by a following `write_to` call.
    /// Called for that side effect by `encode`; prefer `encoded_len`
    /// when only the size is needed.
    #[allow(clippy::needless_borrow, clippy::let_and_return)]
    pub fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        let mut size = 0u64;
        for __frag in self.store_deltas.raw_elements() {
            size
                += 1u64 + ::buffa::encoding::varint_len(__frag.len() as u64) as u64
                    + __frag.len() as u64;
        }
        ::buffa::saturate_size(size)
    }
    /// Write the encoded bytes to `buf`, reading per-message sizes
    /// from the `cache` filled by a preceding `compute_size` call.
    /// Prefer `encode` unless threading a shared cache.
    #[allow(clippy::needless_borrow)]
    pub fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::EncodeSink,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        for __frag in self.store_deltas.raw_elements() {
            ::buffa::encoding::Tag::new(
                    1u32,
                    ::buffa::encoding::WireType::LengthDelimited,
                )
                .encode(buf);
            ::buffa::encoding::encode_varint(__frag.len() as u64, buf);
            buf.put_slice(__frag);
        }
    }
    /// Compute size, then write. Primary encode entry point.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode`](Self::try_encode) for the error-returning
    /// variant.
    #[inline]
    pub fn encode(&self, buf: &mut impl ::buffa::EncodeSink) {
        self.try_encode(buf).unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encode, returning an error instead of panicking if the
    /// encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// On `Err`, nothing is written to `buf`.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encode(
        &self,
        buf: &mut impl ::buffa::EncodeSink,
    ) -> ::core::result::Result<(), ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        ::buffa::checked_encode_size(self.compute_size(&mut __cache))?;
        self.write_to(&mut __cache, buf);
        ::core::result::Result::Ok(())
    }
    /// Encoded byte size of this view.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encoded_len`](Self::try_encoded_len) for the
    /// error-returning variant.
    #[inline]
    #[must_use]
    pub fn encoded_len(&self) -> u32 {
        self.try_encoded_len().unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encoded byte size, returning an error instead of panicking
    /// if it exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encoded_len(&self) -> ::core::result::Result<u32, ::buffa::EncodeError> {
        ::buffa::checked_encode_size(self.compute_size(&mut ::buffa::SizeCache::new()))
    }
    /// Encode this view to a new `Vec<u8>`.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_vec`](Self::try_encode_to_vec) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_vec(&self) -> ::buffa::alloc::vec::Vec<u8> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf
    }
    /// Encode to a new `Vec<u8>`, returning an error instead of
    /// panicking if the encoded size exceeds the 2 GiB protobuf
    /// limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_vec(
        &self,
    ) -> ::core::result::Result<::buffa::alloc::vec::Vec<u8>, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf)
    }
    /// Encode this view to a new [`::buffa::bytes::Bytes`].
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_bytes`](Self::try_encode_to_bytes) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_bytes(&self) -> ::buffa::bytes::Bytes {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf.freeze()
    }
    /// Encode to a new [`::buffa::bytes::Bytes`], returning an
    /// error instead of panicking if the encoded size exceeds the
    /// 2 GiB protobuf limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_bytes(
        &self,
    ) -> ::core::result::Result<::buffa::bytes::Bytes, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf.freeze())
    }
}
impl<'a> ::buffa::MessageName for StoreDeltasLazyView<'a> {
    const PACKAGE: &'static str = "sf.substreams.v1";
    const NAME: &'static str = "StoreDeltas";
    const FULL_NAME: &'static str = "sf.substreams.v1.StoreDeltas";
    const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.v1.StoreDeltas";
}
/** Lazy view of `sf.substreams.v1.StoreDelta`: nested and repeated message fields are
 recorded as undecoded byte ranges and decoded on access. See
 [`::buffa::LazyMessageView`] for the deferred-validation contract;
 the eager, whole-tree-validated counterpart is named `StoreDeltaView`.

 Oneof variants, map values, groups, and extern-typed fields (e.g.
 well-known types) hold eagerly-decoded `StoreDeltaView`-family
 types; only singular/repeated message fields defer.

 # Examples

 ```rust,ignore
 use buffa::LazyMessageView;

 let view = StoreDeltaLazyView::decode_lazy(&bytes)?;
 ```*/
#[derive(Clone, Debug, Default)]
pub struct StoreDeltaLazyView<'a> {
    /// Field 1: `operation`
    pub operation: ::buffa::EnumValue<super::super::store_delta::Operation>,
    /// Field 2: `ordinal`
    pub ordinal: u64,
    /// Field 3: `key`
    pub key: &'a str,
    /// Field 4: `old_value`
    pub old_value: &'a [u8],
    /// Field 5: `new_value`
    pub new_value: &'a [u8],
}
impl<'a> StoreDeltaLazyView<'a> {
    /// Decode from `buf` under the limits carried by `ctx`, recording
    /// nested/repeated message fields as byte ranges.
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _decode_lazy_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let mut view = Self::default();
        view._merge_lazy(buf, ctx)?;
        ::core::result::Result::Ok(view)
    }
    /// Merge fields from `buf` into this view (proto merge semantics;
    /// deferred message fragments accumulate).
    ///
    /// **Not part of the public API.**
    #[doc(hidden)]
    pub fn _merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        let _ = ctx;
        #[allow(unused_variables)]
        let view = self;
        let mut cur: &'a [u8] = buf;
        while !cur.is_empty() {
            let tag = ::buffa::encoding::Tag::decode(&mut cur)?;
            match tag.field_number() {
                1u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::Varint,
                    )?;
                    view.operation = ::buffa::EnumValue::from(
                        ::buffa::types::decode_int32(&mut cur)?,
                    );
                }
                2u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::Varint,
                    )?;
                    view.ordinal = ::buffa::types::decode_uint64(&mut cur)?;
                }
                3u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::LengthDelimited,
                    )?;
                    view.key = ::buffa::types::borrow_str(&mut cur)?;
                }
                4u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::LengthDelimited,
                    )?;
                    view.old_value = ::buffa::types::borrow_bytes(&mut cur)?;
                }
                5u32 => {
                    ::buffa::encoding::check_wire_type(
                        tag,
                        ::buffa::encoding::WireType::LengthDelimited,
                    )?;
                    view.new_value = ::buffa::types::borrow_bytes(&mut cur)?;
                }
                _ => {
                    ::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
                }
            }
        }
        ::core::result::Result::Ok(())
    }
}
impl<'a> ::buffa::LazyMessageView<'a> for StoreDeltaLazyView<'a> {
    type Owned = super::super::StoreDelta;
    fn decode_lazy(buf: &'a [u8]) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        let __limit = ::core::cell::Cell::new(::buffa::DEFAULT_UNKNOWN_FIELD_LIMIT);
        let __elem = ::core::cell::Cell::new(::buffa::DEFAULT_ELEMENT_MEMORY_LIMIT);
        Self::_decode_lazy_ctx(
            buf,
            ::buffa::DecodeContext::new(::buffa::RECURSION_LIMIT, &__limit)
                .with_element_memory(&__elem),
        )
    }
    fn decode_lazy_with_ctx(
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<Self, ::buffa::DecodeError> {
        Self::_decode_lazy_ctx(buf, ctx)
    }
    fn merge_lazy(
        &mut self,
        buf: &'a [u8],
        ctx: ::buffa::DecodeContext<'_>,
    ) -> ::core::result::Result<(), ::buffa::DecodeError> {
        self._merge_lazy(buf, ctx)
    }
    #[allow(clippy::useless_conversion, clippy::needless_update)]
    fn to_owned_message(
        &self,
    ) -> ::core::result::Result<super::super::StoreDelta, ::buffa::DecodeError> {
        #[allow(unused_imports)]
        use ::buffa::alloc::string::ToString as _;
        #[allow(unused_imports)]
        use ::buffa::MessageView as _;
        let __buffa_src: ::core::option::Option<&::buffa::bytes::Bytes> = ::core::option::Option::None;
        let _ = __buffa_src;
        ::core::result::Result::Ok(super::super::StoreDelta {
            operation: self.operation,
            ordinal: self.ordinal,
            key: self.key.to_string(),
            old_value: (self.old_value).to_vec(),
            new_value: (self.new_value).to_vec(),
            ..::core::default::Default::default()
        })
    }
}
/// Re-encoding: recorded fragments are replayed byte-for-byte
/// **without validation** — wire-equivalent to the merged value, and
/// a never-accessed malformed deferred field round-trips silently.
/// Inherent rather than [`::buffa::ViewEncode`] (whose `MessageView`
/// supertrait carries the eager whole-tree-validated contract); the
/// fuller `ViewEncode` set (`encode_length_delimited`,
/// `encode_with_cache`) lives on the eager view.
impl<'a> StoreDeltaLazyView<'a> {
    /// Compute the encoded byte size, filling `cache` with
    /// per-message sizes consumed by a following `write_to` call.
    /// Called for that side effect by `encode`; prefer `encoded_len`
    /// when only the size is needed.
    #[allow(clippy::needless_borrow, clippy::let_and_return)]
    pub fn compute_size(&self, _cache: &mut ::buffa::SizeCache) -> u32 {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        let mut size = 0u64;
        {
            let val = self.operation.to_i32();
            if val != 0 {
                size += 1u64 + ::buffa::types::int32_encoded_len(val) as u64;
            }
        }
        if self.ordinal != 0u64 {
            size += 1u64 + ::buffa::types::uint64_encoded_len(self.ordinal) as u64;
        }
        if !self.key.is_empty() {
            size += 1u64 + ::buffa::types::string_encoded_len(&self.key) as u64;
        }
        if !self.old_value.is_empty() {
            size += 1u64 + ::buffa::types::bytes_encoded_len(&self.old_value) as u64;
        }
        if !self.new_value.is_empty() {
            size += 1u64 + ::buffa::types::bytes_encoded_len(&self.new_value) as u64;
        }
        ::buffa::saturate_size(size)
    }
    /// Write the encoded bytes to `buf`, reading per-message sizes
    /// from the `cache` filled by a preceding `compute_size` call.
    /// Prefer `encode` unless threading a shared cache.
    #[allow(clippy::needless_borrow)]
    pub fn write_to(
        &self,
        _cache: &mut ::buffa::SizeCache,
        buf: &mut impl ::buffa::EncodeSink,
    ) {
        #[allow(unused_imports)]
        use ::buffa::Enumeration as _;
        #[allow(unused_imports)]
        use ::buffa::ViewEncode as _;
        {
            let val = self.operation.to_i32();
            if val != 0 {
                ::buffa::types::put_int32_field(1u32, val, buf);
            }
        }
        if self.ordinal != 0u64 {
            ::buffa::types::put_uint64_field(2u32, self.ordinal, buf);
        }
        if !self.key.is_empty() {
            ::buffa::types::put_string_field(3u32, &self.key, buf);
        }
        if !self.old_value.is_empty() {
            ::buffa::types::put_shared_bytes_field(4u32, &self.old_value, buf);
        }
        if !self.new_value.is_empty() {
            ::buffa::types::put_shared_bytes_field(5u32, &self.new_value, buf);
        }
    }
    /// Compute size, then write. Primary encode entry point.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode`](Self::try_encode) for the error-returning
    /// variant.
    #[inline]
    pub fn encode(&self, buf: &mut impl ::buffa::EncodeSink) {
        self.try_encode(buf).unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encode, returning an error instead of panicking if the
    /// encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// On `Err`, nothing is written to `buf`.
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encode(
        &self,
        buf: &mut impl ::buffa::EncodeSink,
    ) -> ::core::result::Result<(), ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        ::buffa::checked_encode_size(self.compute_size(&mut __cache))?;
        self.write_to(&mut __cache, buf);
        ::core::result::Result::Ok(())
    }
    /// Encoded byte size of this view.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encoded_len`](Self::try_encoded_len) for the
    /// error-returning variant.
    #[inline]
    #[must_use]
    pub fn encoded_len(&self) -> u32 {
        self.try_encoded_len().unwrap_or_else(|_| ::buffa::encode_size_overflow())
    }
    /// Encoded byte size, returning an error instead of panicking
    /// if it exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    pub fn try_encoded_len(&self) -> ::core::result::Result<u32, ::buffa::EncodeError> {
        ::buffa::checked_encode_size(self.compute_size(&mut ::buffa::SizeCache::new()))
    }
    /// Encode this view to a new `Vec<u8>`.
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_vec`](Self::try_encode_to_vec) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_vec(&self) -> ::buffa::alloc::vec::Vec<u8> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf
    }
    /// Encode to a new `Vec<u8>`, returning an error instead of
    /// panicking if the encoded size exceeds the 2 GiB protobuf
    /// limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_vec(
        &self,
    ) -> ::core::result::Result<::buffa::alloc::vec::Vec<u8>, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::alloc::vec::Vec::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf)
    }
    /// Encode this view to a new [`::buffa::bytes::Bytes`].
    ///
    /// # Panics
    ///
    /// Panics if the encoded size exceeds the 2 GiB protobuf limit
    /// ([`::buffa::MAX_MESSAGE_BYTES`]) — see
    /// [`try_encode_to_bytes`](Self::try_encode_to_bytes) for the
    /// error-returning variant. In debug builds, also panics if the
    /// two encode passes disagree on the byte count.
    #[inline]
    #[must_use]
    pub fn encode_to_bytes(&self) -> ::buffa::bytes::Bytes {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = match ::buffa::checked_encode_size(
            self.compute_size(&mut __cache),
        ) {
            ::core::result::Result::Ok(__size) => __size as usize,
            ::core::result::Result::Err(_) => ::buffa::encode_size_overflow(),
        };
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        __buf.freeze()
    }
    /// Encode to a new [`::buffa::bytes::Bytes`], returning an
    /// error instead of panicking if the encoded size exceeds the
    /// 2 GiB protobuf limit ([`::buffa::MAX_MESSAGE_BYTES`]).
    ///
    /// # Errors
    ///
    /// Returns [`::buffa::EncodeError::MessageTooLarge`] if the
    /// encoded size exceeds the limit.
    ///
    /// # Panics
    ///
    /// In debug builds, panics if the two encode passes disagree
    /// on the byte count.
    pub fn try_encode_to_bytes(
        &self,
    ) -> ::core::result::Result<::buffa::bytes::Bytes, ::buffa::EncodeError> {
        let mut __cache = ::buffa::SizeCache::new();
        let __size = ::buffa::checked_encode_size(self.compute_size(&mut __cache))?
            as usize;
        let mut __buf = ::buffa::bytes::BytesMut::with_capacity(__size);
        self.write_to(&mut __cache, &mut __buf);
        ::buffa::debug_assert_two_pass(__buf.len(), __size);
        ::core::result::Result::Ok(__buf.freeze())
    }
}
impl<'a> ::buffa::MessageName for StoreDeltaLazyView<'a> {
    const PACKAGE: &'static str = "sf.substreams.v1";
    const NAME: &'static str = "StoreDelta";
    const FULL_NAME: &'static str = "sf.substreams.v1.StoreDelta";
    const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.v1.StoreDelta";
}