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
// @generated by buffa-codegen. DO NOT EDIT.
// source: sf/substreams/index/v1/keys.proto
/** Lazy view of `sf.substreams.index.v1.Keys`: 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 `KeysView`.
Oneof variants, map values, groups, and extern-typed fields (e.g.
well-known types) hold eagerly-decoded `KeysView`-family
types; only singular/repeated message fields defer.
# Examples
```rust,ignore
use buffa::LazyMessageView;
let view = KeysLazyView::decode_lazy(&bytes)?;
```*/
#[derive(Clone, Debug, Default)]
pub struct KeysLazyView<'a> {
/// Field 1: `keys`
pub keys: ::buffa::RepeatedView<'a, &'a str>,
}
impl<'a> KeysLazyView<'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 __elem = ::buffa::types::borrow_str(&mut cur)?;
ctx.register_element_memory(
::buffa::__private::element_footprint(&__elem),
)?;
view.keys.push(__elem);
}
_ => {
::buffa::encoding::skip_field_depth(tag, &mut cur, ctx.depth())?;
}
}
}
::core::result::Result::Ok(())
}
}
impl<'a> ::buffa::LazyMessageView<'a> for KeysLazyView<'a> {
type Owned = super::super::Keys;
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::Keys, ::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::Keys {
keys: self.keys.iter().map(|s| s.to_string()).collect(),
..::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> KeysLazyView<'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 v in &self.keys {
size += 1u64 + ::buffa::types::string_encoded_len(v) 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 v in &self.keys {
::buffa::types::put_string_field(1u32, v, 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 KeysLazyView<'a> {
const PACKAGE: &'static str = "sf.substreams.index.v1";
const NAME: &'static str = "Keys";
const FULL_NAME: &'static str = "sf.substreams.index.v1.Keys";
const TYPE_URL: &'static str = "type.googleapis.com/sf.substreams.index.v1.Keys";
}