1use super::blockchain::*;
4use super::fiber::*;
5use molecule::prelude::*;
6#[derive(Clone)]
7pub struct SchnorrSignature(molecule::bytes::Bytes);
8impl ::core::fmt::LowerHex for SchnorrSignature {
9 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10 use molecule::hex_string;
11 if f.alternate() {
12 write!(f, "0x")?;
13 }
14 write!(f, "{}", hex_string(self.as_slice()))
15 }
16}
17impl ::core::fmt::Debug for SchnorrSignature {
18 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
19 write!(f, "{}({:#x})", Self::NAME, self)
20 }
21}
22impl ::core::fmt::Display for SchnorrSignature {
23 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
24 use molecule::hex_string;
25 let raw_data = hex_string(&self.raw_data());
26 write!(f, "{}(0x{})", Self::NAME, raw_data)
27 }
28}
29impl ::core::default::Default for SchnorrSignature {
30 fn default() -> Self {
31 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
32 SchnorrSignature::new_unchecked(v)
33 }
34}
35impl SchnorrSignature {
36 const DEFAULT_VALUE: [u8; 64] = [
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39 0, 0, 0, 0,
40 ];
41 pub const TOTAL_SIZE: usize = 64;
42 pub const ITEM_SIZE: usize = 1;
43 pub const ITEM_COUNT: usize = 64;
44 pub fn nth0(&self) -> Byte {
45 Byte::new_unchecked(self.0.slice(0..1))
46 }
47 pub fn nth1(&self) -> Byte {
48 Byte::new_unchecked(self.0.slice(1..2))
49 }
50 pub fn nth2(&self) -> Byte {
51 Byte::new_unchecked(self.0.slice(2..3))
52 }
53 pub fn nth3(&self) -> Byte {
54 Byte::new_unchecked(self.0.slice(3..4))
55 }
56 pub fn nth4(&self) -> Byte {
57 Byte::new_unchecked(self.0.slice(4..5))
58 }
59 pub fn nth5(&self) -> Byte {
60 Byte::new_unchecked(self.0.slice(5..6))
61 }
62 pub fn nth6(&self) -> Byte {
63 Byte::new_unchecked(self.0.slice(6..7))
64 }
65 pub fn nth7(&self) -> Byte {
66 Byte::new_unchecked(self.0.slice(7..8))
67 }
68 pub fn nth8(&self) -> Byte {
69 Byte::new_unchecked(self.0.slice(8..9))
70 }
71 pub fn nth9(&self) -> Byte {
72 Byte::new_unchecked(self.0.slice(9..10))
73 }
74 pub fn nth10(&self) -> Byte {
75 Byte::new_unchecked(self.0.slice(10..11))
76 }
77 pub fn nth11(&self) -> Byte {
78 Byte::new_unchecked(self.0.slice(11..12))
79 }
80 pub fn nth12(&self) -> Byte {
81 Byte::new_unchecked(self.0.slice(12..13))
82 }
83 pub fn nth13(&self) -> Byte {
84 Byte::new_unchecked(self.0.slice(13..14))
85 }
86 pub fn nth14(&self) -> Byte {
87 Byte::new_unchecked(self.0.slice(14..15))
88 }
89 pub fn nth15(&self) -> Byte {
90 Byte::new_unchecked(self.0.slice(15..16))
91 }
92 pub fn nth16(&self) -> Byte {
93 Byte::new_unchecked(self.0.slice(16..17))
94 }
95 pub fn nth17(&self) -> Byte {
96 Byte::new_unchecked(self.0.slice(17..18))
97 }
98 pub fn nth18(&self) -> Byte {
99 Byte::new_unchecked(self.0.slice(18..19))
100 }
101 pub fn nth19(&self) -> Byte {
102 Byte::new_unchecked(self.0.slice(19..20))
103 }
104 pub fn nth20(&self) -> Byte {
105 Byte::new_unchecked(self.0.slice(20..21))
106 }
107 pub fn nth21(&self) -> Byte {
108 Byte::new_unchecked(self.0.slice(21..22))
109 }
110 pub fn nth22(&self) -> Byte {
111 Byte::new_unchecked(self.0.slice(22..23))
112 }
113 pub fn nth23(&self) -> Byte {
114 Byte::new_unchecked(self.0.slice(23..24))
115 }
116 pub fn nth24(&self) -> Byte {
117 Byte::new_unchecked(self.0.slice(24..25))
118 }
119 pub fn nth25(&self) -> Byte {
120 Byte::new_unchecked(self.0.slice(25..26))
121 }
122 pub fn nth26(&self) -> Byte {
123 Byte::new_unchecked(self.0.slice(26..27))
124 }
125 pub fn nth27(&self) -> Byte {
126 Byte::new_unchecked(self.0.slice(27..28))
127 }
128 pub fn nth28(&self) -> Byte {
129 Byte::new_unchecked(self.0.slice(28..29))
130 }
131 pub fn nth29(&self) -> Byte {
132 Byte::new_unchecked(self.0.slice(29..30))
133 }
134 pub fn nth30(&self) -> Byte {
135 Byte::new_unchecked(self.0.slice(30..31))
136 }
137 pub fn nth31(&self) -> Byte {
138 Byte::new_unchecked(self.0.slice(31..32))
139 }
140 pub fn nth32(&self) -> Byte {
141 Byte::new_unchecked(self.0.slice(32..33))
142 }
143 pub fn nth33(&self) -> Byte {
144 Byte::new_unchecked(self.0.slice(33..34))
145 }
146 pub fn nth34(&self) -> Byte {
147 Byte::new_unchecked(self.0.slice(34..35))
148 }
149 pub fn nth35(&self) -> Byte {
150 Byte::new_unchecked(self.0.slice(35..36))
151 }
152 pub fn nth36(&self) -> Byte {
153 Byte::new_unchecked(self.0.slice(36..37))
154 }
155 pub fn nth37(&self) -> Byte {
156 Byte::new_unchecked(self.0.slice(37..38))
157 }
158 pub fn nth38(&self) -> Byte {
159 Byte::new_unchecked(self.0.slice(38..39))
160 }
161 pub fn nth39(&self) -> Byte {
162 Byte::new_unchecked(self.0.slice(39..40))
163 }
164 pub fn nth40(&self) -> Byte {
165 Byte::new_unchecked(self.0.slice(40..41))
166 }
167 pub fn nth41(&self) -> Byte {
168 Byte::new_unchecked(self.0.slice(41..42))
169 }
170 pub fn nth42(&self) -> Byte {
171 Byte::new_unchecked(self.0.slice(42..43))
172 }
173 pub fn nth43(&self) -> Byte {
174 Byte::new_unchecked(self.0.slice(43..44))
175 }
176 pub fn nth44(&self) -> Byte {
177 Byte::new_unchecked(self.0.slice(44..45))
178 }
179 pub fn nth45(&self) -> Byte {
180 Byte::new_unchecked(self.0.slice(45..46))
181 }
182 pub fn nth46(&self) -> Byte {
183 Byte::new_unchecked(self.0.slice(46..47))
184 }
185 pub fn nth47(&self) -> Byte {
186 Byte::new_unchecked(self.0.slice(47..48))
187 }
188 pub fn nth48(&self) -> Byte {
189 Byte::new_unchecked(self.0.slice(48..49))
190 }
191 pub fn nth49(&self) -> Byte {
192 Byte::new_unchecked(self.0.slice(49..50))
193 }
194 pub fn nth50(&self) -> Byte {
195 Byte::new_unchecked(self.0.slice(50..51))
196 }
197 pub fn nth51(&self) -> Byte {
198 Byte::new_unchecked(self.0.slice(51..52))
199 }
200 pub fn nth52(&self) -> Byte {
201 Byte::new_unchecked(self.0.slice(52..53))
202 }
203 pub fn nth53(&self) -> Byte {
204 Byte::new_unchecked(self.0.slice(53..54))
205 }
206 pub fn nth54(&self) -> Byte {
207 Byte::new_unchecked(self.0.slice(54..55))
208 }
209 pub fn nth55(&self) -> Byte {
210 Byte::new_unchecked(self.0.slice(55..56))
211 }
212 pub fn nth56(&self) -> Byte {
213 Byte::new_unchecked(self.0.slice(56..57))
214 }
215 pub fn nth57(&self) -> Byte {
216 Byte::new_unchecked(self.0.slice(57..58))
217 }
218 pub fn nth58(&self) -> Byte {
219 Byte::new_unchecked(self.0.slice(58..59))
220 }
221 pub fn nth59(&self) -> Byte {
222 Byte::new_unchecked(self.0.slice(59..60))
223 }
224 pub fn nth60(&self) -> Byte {
225 Byte::new_unchecked(self.0.slice(60..61))
226 }
227 pub fn nth61(&self) -> Byte {
228 Byte::new_unchecked(self.0.slice(61..62))
229 }
230 pub fn nth62(&self) -> Byte {
231 Byte::new_unchecked(self.0.slice(62..63))
232 }
233 pub fn nth63(&self) -> Byte {
234 Byte::new_unchecked(self.0.slice(63..64))
235 }
236 pub fn raw_data(&self) -> molecule::bytes::Bytes {
237 self.as_bytes()
238 }
239 pub fn as_reader<'r>(&'r self) -> SchnorrSignatureReader<'r> {
240 SchnorrSignatureReader::new_unchecked(self.as_slice())
241 }
242}
243impl molecule::prelude::Entity for SchnorrSignature {
244 type Builder = SchnorrSignatureBuilder;
245 const NAME: &'static str = "SchnorrSignature";
246 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
247 SchnorrSignature(data)
248 }
249 fn as_bytes(&self) -> molecule::bytes::Bytes {
250 self.0.clone()
251 }
252 fn as_slice(&self) -> &[u8] {
253 &self.0[..]
254 }
255 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
256 SchnorrSignatureReader::from_slice(slice).map(|reader| reader.to_entity())
257 }
258 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
259 SchnorrSignatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
260 }
261 fn new_builder() -> Self::Builder {
262 ::core::default::Default::default()
263 }
264 fn as_builder(self) -> Self::Builder {
265 Self::new_builder().set([
266 self.nth0(),
267 self.nth1(),
268 self.nth2(),
269 self.nth3(),
270 self.nth4(),
271 self.nth5(),
272 self.nth6(),
273 self.nth7(),
274 self.nth8(),
275 self.nth9(),
276 self.nth10(),
277 self.nth11(),
278 self.nth12(),
279 self.nth13(),
280 self.nth14(),
281 self.nth15(),
282 self.nth16(),
283 self.nth17(),
284 self.nth18(),
285 self.nth19(),
286 self.nth20(),
287 self.nth21(),
288 self.nth22(),
289 self.nth23(),
290 self.nth24(),
291 self.nth25(),
292 self.nth26(),
293 self.nth27(),
294 self.nth28(),
295 self.nth29(),
296 self.nth30(),
297 self.nth31(),
298 self.nth32(),
299 self.nth33(),
300 self.nth34(),
301 self.nth35(),
302 self.nth36(),
303 self.nth37(),
304 self.nth38(),
305 self.nth39(),
306 self.nth40(),
307 self.nth41(),
308 self.nth42(),
309 self.nth43(),
310 self.nth44(),
311 self.nth45(),
312 self.nth46(),
313 self.nth47(),
314 self.nth48(),
315 self.nth49(),
316 self.nth50(),
317 self.nth51(),
318 self.nth52(),
319 self.nth53(),
320 self.nth54(),
321 self.nth55(),
322 self.nth56(),
323 self.nth57(),
324 self.nth58(),
325 self.nth59(),
326 self.nth60(),
327 self.nth61(),
328 self.nth62(),
329 self.nth63(),
330 ])
331 }
332}
333#[derive(Clone, Copy)]
334pub struct SchnorrSignatureReader<'r>(&'r [u8]);
335impl<'r> ::core::fmt::LowerHex for SchnorrSignatureReader<'r> {
336 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
337 use molecule::hex_string;
338 if f.alternate() {
339 write!(f, "0x")?;
340 }
341 write!(f, "{}", hex_string(self.as_slice()))
342 }
343}
344impl<'r> ::core::fmt::Debug for SchnorrSignatureReader<'r> {
345 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
346 write!(f, "{}({:#x})", Self::NAME, self)
347 }
348}
349impl<'r> ::core::fmt::Display for SchnorrSignatureReader<'r> {
350 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
351 use molecule::hex_string;
352 let raw_data = hex_string(&self.raw_data());
353 write!(f, "{}(0x{})", Self::NAME, raw_data)
354 }
355}
356impl<'r> SchnorrSignatureReader<'r> {
357 pub const TOTAL_SIZE: usize = 64;
358 pub const ITEM_SIZE: usize = 1;
359 pub const ITEM_COUNT: usize = 64;
360 pub fn nth0(&self) -> ByteReader<'r> {
361 ByteReader::new_unchecked(&self.as_slice()[0..1])
362 }
363 pub fn nth1(&self) -> ByteReader<'r> {
364 ByteReader::new_unchecked(&self.as_slice()[1..2])
365 }
366 pub fn nth2(&self) -> ByteReader<'r> {
367 ByteReader::new_unchecked(&self.as_slice()[2..3])
368 }
369 pub fn nth3(&self) -> ByteReader<'r> {
370 ByteReader::new_unchecked(&self.as_slice()[3..4])
371 }
372 pub fn nth4(&self) -> ByteReader<'r> {
373 ByteReader::new_unchecked(&self.as_slice()[4..5])
374 }
375 pub fn nth5(&self) -> ByteReader<'r> {
376 ByteReader::new_unchecked(&self.as_slice()[5..6])
377 }
378 pub fn nth6(&self) -> ByteReader<'r> {
379 ByteReader::new_unchecked(&self.as_slice()[6..7])
380 }
381 pub fn nth7(&self) -> ByteReader<'r> {
382 ByteReader::new_unchecked(&self.as_slice()[7..8])
383 }
384 pub fn nth8(&self) -> ByteReader<'r> {
385 ByteReader::new_unchecked(&self.as_slice()[8..9])
386 }
387 pub fn nth9(&self) -> ByteReader<'r> {
388 ByteReader::new_unchecked(&self.as_slice()[9..10])
389 }
390 pub fn nth10(&self) -> ByteReader<'r> {
391 ByteReader::new_unchecked(&self.as_slice()[10..11])
392 }
393 pub fn nth11(&self) -> ByteReader<'r> {
394 ByteReader::new_unchecked(&self.as_slice()[11..12])
395 }
396 pub fn nth12(&self) -> ByteReader<'r> {
397 ByteReader::new_unchecked(&self.as_slice()[12..13])
398 }
399 pub fn nth13(&self) -> ByteReader<'r> {
400 ByteReader::new_unchecked(&self.as_slice()[13..14])
401 }
402 pub fn nth14(&self) -> ByteReader<'r> {
403 ByteReader::new_unchecked(&self.as_slice()[14..15])
404 }
405 pub fn nth15(&self) -> ByteReader<'r> {
406 ByteReader::new_unchecked(&self.as_slice()[15..16])
407 }
408 pub fn nth16(&self) -> ByteReader<'r> {
409 ByteReader::new_unchecked(&self.as_slice()[16..17])
410 }
411 pub fn nth17(&self) -> ByteReader<'r> {
412 ByteReader::new_unchecked(&self.as_slice()[17..18])
413 }
414 pub fn nth18(&self) -> ByteReader<'r> {
415 ByteReader::new_unchecked(&self.as_slice()[18..19])
416 }
417 pub fn nth19(&self) -> ByteReader<'r> {
418 ByteReader::new_unchecked(&self.as_slice()[19..20])
419 }
420 pub fn nth20(&self) -> ByteReader<'r> {
421 ByteReader::new_unchecked(&self.as_slice()[20..21])
422 }
423 pub fn nth21(&self) -> ByteReader<'r> {
424 ByteReader::new_unchecked(&self.as_slice()[21..22])
425 }
426 pub fn nth22(&self) -> ByteReader<'r> {
427 ByteReader::new_unchecked(&self.as_slice()[22..23])
428 }
429 pub fn nth23(&self) -> ByteReader<'r> {
430 ByteReader::new_unchecked(&self.as_slice()[23..24])
431 }
432 pub fn nth24(&self) -> ByteReader<'r> {
433 ByteReader::new_unchecked(&self.as_slice()[24..25])
434 }
435 pub fn nth25(&self) -> ByteReader<'r> {
436 ByteReader::new_unchecked(&self.as_slice()[25..26])
437 }
438 pub fn nth26(&self) -> ByteReader<'r> {
439 ByteReader::new_unchecked(&self.as_slice()[26..27])
440 }
441 pub fn nth27(&self) -> ByteReader<'r> {
442 ByteReader::new_unchecked(&self.as_slice()[27..28])
443 }
444 pub fn nth28(&self) -> ByteReader<'r> {
445 ByteReader::new_unchecked(&self.as_slice()[28..29])
446 }
447 pub fn nth29(&self) -> ByteReader<'r> {
448 ByteReader::new_unchecked(&self.as_slice()[29..30])
449 }
450 pub fn nth30(&self) -> ByteReader<'r> {
451 ByteReader::new_unchecked(&self.as_slice()[30..31])
452 }
453 pub fn nth31(&self) -> ByteReader<'r> {
454 ByteReader::new_unchecked(&self.as_slice()[31..32])
455 }
456 pub fn nth32(&self) -> ByteReader<'r> {
457 ByteReader::new_unchecked(&self.as_slice()[32..33])
458 }
459 pub fn nth33(&self) -> ByteReader<'r> {
460 ByteReader::new_unchecked(&self.as_slice()[33..34])
461 }
462 pub fn nth34(&self) -> ByteReader<'r> {
463 ByteReader::new_unchecked(&self.as_slice()[34..35])
464 }
465 pub fn nth35(&self) -> ByteReader<'r> {
466 ByteReader::new_unchecked(&self.as_slice()[35..36])
467 }
468 pub fn nth36(&self) -> ByteReader<'r> {
469 ByteReader::new_unchecked(&self.as_slice()[36..37])
470 }
471 pub fn nth37(&self) -> ByteReader<'r> {
472 ByteReader::new_unchecked(&self.as_slice()[37..38])
473 }
474 pub fn nth38(&self) -> ByteReader<'r> {
475 ByteReader::new_unchecked(&self.as_slice()[38..39])
476 }
477 pub fn nth39(&self) -> ByteReader<'r> {
478 ByteReader::new_unchecked(&self.as_slice()[39..40])
479 }
480 pub fn nth40(&self) -> ByteReader<'r> {
481 ByteReader::new_unchecked(&self.as_slice()[40..41])
482 }
483 pub fn nth41(&self) -> ByteReader<'r> {
484 ByteReader::new_unchecked(&self.as_slice()[41..42])
485 }
486 pub fn nth42(&self) -> ByteReader<'r> {
487 ByteReader::new_unchecked(&self.as_slice()[42..43])
488 }
489 pub fn nth43(&self) -> ByteReader<'r> {
490 ByteReader::new_unchecked(&self.as_slice()[43..44])
491 }
492 pub fn nth44(&self) -> ByteReader<'r> {
493 ByteReader::new_unchecked(&self.as_slice()[44..45])
494 }
495 pub fn nth45(&self) -> ByteReader<'r> {
496 ByteReader::new_unchecked(&self.as_slice()[45..46])
497 }
498 pub fn nth46(&self) -> ByteReader<'r> {
499 ByteReader::new_unchecked(&self.as_slice()[46..47])
500 }
501 pub fn nth47(&self) -> ByteReader<'r> {
502 ByteReader::new_unchecked(&self.as_slice()[47..48])
503 }
504 pub fn nth48(&self) -> ByteReader<'r> {
505 ByteReader::new_unchecked(&self.as_slice()[48..49])
506 }
507 pub fn nth49(&self) -> ByteReader<'r> {
508 ByteReader::new_unchecked(&self.as_slice()[49..50])
509 }
510 pub fn nth50(&self) -> ByteReader<'r> {
511 ByteReader::new_unchecked(&self.as_slice()[50..51])
512 }
513 pub fn nth51(&self) -> ByteReader<'r> {
514 ByteReader::new_unchecked(&self.as_slice()[51..52])
515 }
516 pub fn nth52(&self) -> ByteReader<'r> {
517 ByteReader::new_unchecked(&self.as_slice()[52..53])
518 }
519 pub fn nth53(&self) -> ByteReader<'r> {
520 ByteReader::new_unchecked(&self.as_slice()[53..54])
521 }
522 pub fn nth54(&self) -> ByteReader<'r> {
523 ByteReader::new_unchecked(&self.as_slice()[54..55])
524 }
525 pub fn nth55(&self) -> ByteReader<'r> {
526 ByteReader::new_unchecked(&self.as_slice()[55..56])
527 }
528 pub fn nth56(&self) -> ByteReader<'r> {
529 ByteReader::new_unchecked(&self.as_slice()[56..57])
530 }
531 pub fn nth57(&self) -> ByteReader<'r> {
532 ByteReader::new_unchecked(&self.as_slice()[57..58])
533 }
534 pub fn nth58(&self) -> ByteReader<'r> {
535 ByteReader::new_unchecked(&self.as_slice()[58..59])
536 }
537 pub fn nth59(&self) -> ByteReader<'r> {
538 ByteReader::new_unchecked(&self.as_slice()[59..60])
539 }
540 pub fn nth60(&self) -> ByteReader<'r> {
541 ByteReader::new_unchecked(&self.as_slice()[60..61])
542 }
543 pub fn nth61(&self) -> ByteReader<'r> {
544 ByteReader::new_unchecked(&self.as_slice()[61..62])
545 }
546 pub fn nth62(&self) -> ByteReader<'r> {
547 ByteReader::new_unchecked(&self.as_slice()[62..63])
548 }
549 pub fn nth63(&self) -> ByteReader<'r> {
550 ByteReader::new_unchecked(&self.as_slice()[63..64])
551 }
552 pub fn raw_data(&self) -> &'r [u8] {
553 self.as_slice()
554 }
555}
556impl<'r> molecule::prelude::Reader<'r> for SchnorrSignatureReader<'r> {
557 type Entity = SchnorrSignature;
558 const NAME: &'static str = "SchnorrSignatureReader";
559 fn to_entity(&self) -> Self::Entity {
560 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
561 }
562 fn new_unchecked(slice: &'r [u8]) -> Self {
563 SchnorrSignatureReader(slice)
564 }
565 fn as_slice(&self) -> &'r [u8] {
566 self.0
567 }
568 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
569 use molecule::verification_error as ve;
570 let slice_len = slice.len();
571 if slice_len != Self::TOTAL_SIZE {
572 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
573 }
574 Ok(())
575 }
576}
577#[derive(Clone)]
578pub struct SchnorrSignatureBuilder(pub(crate) [Byte; 64]);
579impl ::core::fmt::Debug for SchnorrSignatureBuilder {
580 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
581 write!(f, "{}({:?})", Self::NAME, &self.0[..])
582 }
583}
584impl ::core::default::Default for SchnorrSignatureBuilder {
585 fn default() -> Self {
586 SchnorrSignatureBuilder([
587 Byte::default(),
588 Byte::default(),
589 Byte::default(),
590 Byte::default(),
591 Byte::default(),
592 Byte::default(),
593 Byte::default(),
594 Byte::default(),
595 Byte::default(),
596 Byte::default(),
597 Byte::default(),
598 Byte::default(),
599 Byte::default(),
600 Byte::default(),
601 Byte::default(),
602 Byte::default(),
603 Byte::default(),
604 Byte::default(),
605 Byte::default(),
606 Byte::default(),
607 Byte::default(),
608 Byte::default(),
609 Byte::default(),
610 Byte::default(),
611 Byte::default(),
612 Byte::default(),
613 Byte::default(),
614 Byte::default(),
615 Byte::default(),
616 Byte::default(),
617 Byte::default(),
618 Byte::default(),
619 Byte::default(),
620 Byte::default(),
621 Byte::default(),
622 Byte::default(),
623 Byte::default(),
624 Byte::default(),
625 Byte::default(),
626 Byte::default(),
627 Byte::default(),
628 Byte::default(),
629 Byte::default(),
630 Byte::default(),
631 Byte::default(),
632 Byte::default(),
633 Byte::default(),
634 Byte::default(),
635 Byte::default(),
636 Byte::default(),
637 Byte::default(),
638 Byte::default(),
639 Byte::default(),
640 Byte::default(),
641 Byte::default(),
642 Byte::default(),
643 Byte::default(),
644 Byte::default(),
645 Byte::default(),
646 Byte::default(),
647 Byte::default(),
648 Byte::default(),
649 Byte::default(),
650 Byte::default(),
651 ])
652 }
653}
654impl SchnorrSignatureBuilder {
655 pub const TOTAL_SIZE: usize = 64;
656 pub const ITEM_SIZE: usize = 1;
657 pub const ITEM_COUNT: usize = 64;
658 pub fn set(mut self, v: [Byte; 64]) -> Self {
659 self.0 = v;
660 self
661 }
662 pub fn nth0(mut self, v: Byte) -> Self {
663 self.0[0] = v;
664 self
665 }
666 pub fn nth1(mut self, v: Byte) -> Self {
667 self.0[1] = v;
668 self
669 }
670 pub fn nth2(mut self, v: Byte) -> Self {
671 self.0[2] = v;
672 self
673 }
674 pub fn nth3(mut self, v: Byte) -> Self {
675 self.0[3] = v;
676 self
677 }
678 pub fn nth4(mut self, v: Byte) -> Self {
679 self.0[4] = v;
680 self
681 }
682 pub fn nth5(mut self, v: Byte) -> Self {
683 self.0[5] = v;
684 self
685 }
686 pub fn nth6(mut self, v: Byte) -> Self {
687 self.0[6] = v;
688 self
689 }
690 pub fn nth7(mut self, v: Byte) -> Self {
691 self.0[7] = v;
692 self
693 }
694 pub fn nth8(mut self, v: Byte) -> Self {
695 self.0[8] = v;
696 self
697 }
698 pub fn nth9(mut self, v: Byte) -> Self {
699 self.0[9] = v;
700 self
701 }
702 pub fn nth10(mut self, v: Byte) -> Self {
703 self.0[10] = v;
704 self
705 }
706 pub fn nth11(mut self, v: Byte) -> Self {
707 self.0[11] = v;
708 self
709 }
710 pub fn nth12(mut self, v: Byte) -> Self {
711 self.0[12] = v;
712 self
713 }
714 pub fn nth13(mut self, v: Byte) -> Self {
715 self.0[13] = v;
716 self
717 }
718 pub fn nth14(mut self, v: Byte) -> Self {
719 self.0[14] = v;
720 self
721 }
722 pub fn nth15(mut self, v: Byte) -> Self {
723 self.0[15] = v;
724 self
725 }
726 pub fn nth16(mut self, v: Byte) -> Self {
727 self.0[16] = v;
728 self
729 }
730 pub fn nth17(mut self, v: Byte) -> Self {
731 self.0[17] = v;
732 self
733 }
734 pub fn nth18(mut self, v: Byte) -> Self {
735 self.0[18] = v;
736 self
737 }
738 pub fn nth19(mut self, v: Byte) -> Self {
739 self.0[19] = v;
740 self
741 }
742 pub fn nth20(mut self, v: Byte) -> Self {
743 self.0[20] = v;
744 self
745 }
746 pub fn nth21(mut self, v: Byte) -> Self {
747 self.0[21] = v;
748 self
749 }
750 pub fn nth22(mut self, v: Byte) -> Self {
751 self.0[22] = v;
752 self
753 }
754 pub fn nth23(mut self, v: Byte) -> Self {
755 self.0[23] = v;
756 self
757 }
758 pub fn nth24(mut self, v: Byte) -> Self {
759 self.0[24] = v;
760 self
761 }
762 pub fn nth25(mut self, v: Byte) -> Self {
763 self.0[25] = v;
764 self
765 }
766 pub fn nth26(mut self, v: Byte) -> Self {
767 self.0[26] = v;
768 self
769 }
770 pub fn nth27(mut self, v: Byte) -> Self {
771 self.0[27] = v;
772 self
773 }
774 pub fn nth28(mut self, v: Byte) -> Self {
775 self.0[28] = v;
776 self
777 }
778 pub fn nth29(mut self, v: Byte) -> Self {
779 self.0[29] = v;
780 self
781 }
782 pub fn nth30(mut self, v: Byte) -> Self {
783 self.0[30] = v;
784 self
785 }
786 pub fn nth31(mut self, v: Byte) -> Self {
787 self.0[31] = v;
788 self
789 }
790 pub fn nth32(mut self, v: Byte) -> Self {
791 self.0[32] = v;
792 self
793 }
794 pub fn nth33(mut self, v: Byte) -> Self {
795 self.0[33] = v;
796 self
797 }
798 pub fn nth34(mut self, v: Byte) -> Self {
799 self.0[34] = v;
800 self
801 }
802 pub fn nth35(mut self, v: Byte) -> Self {
803 self.0[35] = v;
804 self
805 }
806 pub fn nth36(mut self, v: Byte) -> Self {
807 self.0[36] = v;
808 self
809 }
810 pub fn nth37(mut self, v: Byte) -> Self {
811 self.0[37] = v;
812 self
813 }
814 pub fn nth38(mut self, v: Byte) -> Self {
815 self.0[38] = v;
816 self
817 }
818 pub fn nth39(mut self, v: Byte) -> Self {
819 self.0[39] = v;
820 self
821 }
822 pub fn nth40(mut self, v: Byte) -> Self {
823 self.0[40] = v;
824 self
825 }
826 pub fn nth41(mut self, v: Byte) -> Self {
827 self.0[41] = v;
828 self
829 }
830 pub fn nth42(mut self, v: Byte) -> Self {
831 self.0[42] = v;
832 self
833 }
834 pub fn nth43(mut self, v: Byte) -> Self {
835 self.0[43] = v;
836 self
837 }
838 pub fn nth44(mut self, v: Byte) -> Self {
839 self.0[44] = v;
840 self
841 }
842 pub fn nth45(mut self, v: Byte) -> Self {
843 self.0[45] = v;
844 self
845 }
846 pub fn nth46(mut self, v: Byte) -> Self {
847 self.0[46] = v;
848 self
849 }
850 pub fn nth47(mut self, v: Byte) -> Self {
851 self.0[47] = v;
852 self
853 }
854 pub fn nth48(mut self, v: Byte) -> Self {
855 self.0[48] = v;
856 self
857 }
858 pub fn nth49(mut self, v: Byte) -> Self {
859 self.0[49] = v;
860 self
861 }
862 pub fn nth50(mut self, v: Byte) -> Self {
863 self.0[50] = v;
864 self
865 }
866 pub fn nth51(mut self, v: Byte) -> Self {
867 self.0[51] = v;
868 self
869 }
870 pub fn nth52(mut self, v: Byte) -> Self {
871 self.0[52] = v;
872 self
873 }
874 pub fn nth53(mut self, v: Byte) -> Self {
875 self.0[53] = v;
876 self
877 }
878 pub fn nth54(mut self, v: Byte) -> Self {
879 self.0[54] = v;
880 self
881 }
882 pub fn nth55(mut self, v: Byte) -> Self {
883 self.0[55] = v;
884 self
885 }
886 pub fn nth56(mut self, v: Byte) -> Self {
887 self.0[56] = v;
888 self
889 }
890 pub fn nth57(mut self, v: Byte) -> Self {
891 self.0[57] = v;
892 self
893 }
894 pub fn nth58(mut self, v: Byte) -> Self {
895 self.0[58] = v;
896 self
897 }
898 pub fn nth59(mut self, v: Byte) -> Self {
899 self.0[59] = v;
900 self
901 }
902 pub fn nth60(mut self, v: Byte) -> Self {
903 self.0[60] = v;
904 self
905 }
906 pub fn nth61(mut self, v: Byte) -> Self {
907 self.0[61] = v;
908 self
909 }
910 pub fn nth62(mut self, v: Byte) -> Self {
911 self.0[62] = v;
912 self
913 }
914 pub fn nth63(mut self, v: Byte) -> Self {
915 self.0[63] = v;
916 self
917 }
918}
919impl molecule::prelude::Builder for SchnorrSignatureBuilder {
920 type Entity = SchnorrSignature;
921 const NAME: &'static str = "SchnorrSignatureBuilder";
922 fn expected_length(&self) -> usize {
923 Self::TOTAL_SIZE
924 }
925 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
926 writer.write_all(self.0[0].as_slice())?;
927 writer.write_all(self.0[1].as_slice())?;
928 writer.write_all(self.0[2].as_slice())?;
929 writer.write_all(self.0[3].as_slice())?;
930 writer.write_all(self.0[4].as_slice())?;
931 writer.write_all(self.0[5].as_slice())?;
932 writer.write_all(self.0[6].as_slice())?;
933 writer.write_all(self.0[7].as_slice())?;
934 writer.write_all(self.0[8].as_slice())?;
935 writer.write_all(self.0[9].as_slice())?;
936 writer.write_all(self.0[10].as_slice())?;
937 writer.write_all(self.0[11].as_slice())?;
938 writer.write_all(self.0[12].as_slice())?;
939 writer.write_all(self.0[13].as_slice())?;
940 writer.write_all(self.0[14].as_slice())?;
941 writer.write_all(self.0[15].as_slice())?;
942 writer.write_all(self.0[16].as_slice())?;
943 writer.write_all(self.0[17].as_slice())?;
944 writer.write_all(self.0[18].as_slice())?;
945 writer.write_all(self.0[19].as_slice())?;
946 writer.write_all(self.0[20].as_slice())?;
947 writer.write_all(self.0[21].as_slice())?;
948 writer.write_all(self.0[22].as_slice())?;
949 writer.write_all(self.0[23].as_slice())?;
950 writer.write_all(self.0[24].as_slice())?;
951 writer.write_all(self.0[25].as_slice())?;
952 writer.write_all(self.0[26].as_slice())?;
953 writer.write_all(self.0[27].as_slice())?;
954 writer.write_all(self.0[28].as_slice())?;
955 writer.write_all(self.0[29].as_slice())?;
956 writer.write_all(self.0[30].as_slice())?;
957 writer.write_all(self.0[31].as_slice())?;
958 writer.write_all(self.0[32].as_slice())?;
959 writer.write_all(self.0[33].as_slice())?;
960 writer.write_all(self.0[34].as_slice())?;
961 writer.write_all(self.0[35].as_slice())?;
962 writer.write_all(self.0[36].as_slice())?;
963 writer.write_all(self.0[37].as_slice())?;
964 writer.write_all(self.0[38].as_slice())?;
965 writer.write_all(self.0[39].as_slice())?;
966 writer.write_all(self.0[40].as_slice())?;
967 writer.write_all(self.0[41].as_slice())?;
968 writer.write_all(self.0[42].as_slice())?;
969 writer.write_all(self.0[43].as_slice())?;
970 writer.write_all(self.0[44].as_slice())?;
971 writer.write_all(self.0[45].as_slice())?;
972 writer.write_all(self.0[46].as_slice())?;
973 writer.write_all(self.0[47].as_slice())?;
974 writer.write_all(self.0[48].as_slice())?;
975 writer.write_all(self.0[49].as_slice())?;
976 writer.write_all(self.0[50].as_slice())?;
977 writer.write_all(self.0[51].as_slice())?;
978 writer.write_all(self.0[52].as_slice())?;
979 writer.write_all(self.0[53].as_slice())?;
980 writer.write_all(self.0[54].as_slice())?;
981 writer.write_all(self.0[55].as_slice())?;
982 writer.write_all(self.0[56].as_slice())?;
983 writer.write_all(self.0[57].as_slice())?;
984 writer.write_all(self.0[58].as_slice())?;
985 writer.write_all(self.0[59].as_slice())?;
986 writer.write_all(self.0[60].as_slice())?;
987 writer.write_all(self.0[61].as_slice())?;
988 writer.write_all(self.0[62].as_slice())?;
989 writer.write_all(self.0[63].as_slice())?;
990 Ok(())
991 }
992 fn build(&self) -> Self::Entity {
993 let mut inner = Vec::with_capacity(self.expected_length());
994 self.write(&mut inner)
995 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
996 SchnorrSignature::new_unchecked(inner.into())
997 }
998}
999impl From<[Byte; 64usize]> for SchnorrSignature {
1000 fn from(value: [Byte; 64usize]) -> Self {
1001 Self::new_builder().set(value).build()
1002 }
1003}
1004impl ::core::convert::TryFrom<&[Byte]> for SchnorrSignature {
1005 type Error = ::core::array::TryFromSliceError;
1006 fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
1007 Ok(Self::new_builder()
1008 .set(<&[Byte; 64usize]>::try_from(value)?.clone())
1009 .build())
1010 }
1011}
1012impl From<SchnorrSignature> for [Byte; 64usize] {
1013 #[track_caller]
1014 fn from(value: SchnorrSignature) -> Self {
1015 [
1016 value.nth0(),
1017 value.nth1(),
1018 value.nth2(),
1019 value.nth3(),
1020 value.nth4(),
1021 value.nth5(),
1022 value.nth6(),
1023 value.nth7(),
1024 value.nth8(),
1025 value.nth9(),
1026 value.nth10(),
1027 value.nth11(),
1028 value.nth12(),
1029 value.nth13(),
1030 value.nth14(),
1031 value.nth15(),
1032 value.nth16(),
1033 value.nth17(),
1034 value.nth18(),
1035 value.nth19(),
1036 value.nth20(),
1037 value.nth21(),
1038 value.nth22(),
1039 value.nth23(),
1040 value.nth24(),
1041 value.nth25(),
1042 value.nth26(),
1043 value.nth27(),
1044 value.nth28(),
1045 value.nth29(),
1046 value.nth30(),
1047 value.nth31(),
1048 value.nth32(),
1049 value.nth33(),
1050 value.nth34(),
1051 value.nth35(),
1052 value.nth36(),
1053 value.nth37(),
1054 value.nth38(),
1055 value.nth39(),
1056 value.nth40(),
1057 value.nth41(),
1058 value.nth42(),
1059 value.nth43(),
1060 value.nth44(),
1061 value.nth45(),
1062 value.nth46(),
1063 value.nth47(),
1064 value.nth48(),
1065 value.nth49(),
1066 value.nth50(),
1067 value.nth51(),
1068 value.nth52(),
1069 value.nth53(),
1070 value.nth54(),
1071 value.nth55(),
1072 value.nth56(),
1073 value.nth57(),
1074 value.nth58(),
1075 value.nth59(),
1076 value.nth60(),
1077 value.nth61(),
1078 value.nth62(),
1079 value.nth63(),
1080 ]
1081 }
1082}
1083impl From<[u8; 64usize]> for SchnorrSignature {
1084 fn from(value: [u8; 64usize]) -> Self {
1085 SchnorrSignatureReader::new_unchecked(&value).to_entity()
1086 }
1087}
1088impl ::core::convert::TryFrom<&[u8]> for SchnorrSignature {
1089 type Error = ::core::array::TryFromSliceError;
1090 fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
1091 Ok(<[u8; 64usize]>::try_from(value)?.into())
1092 }
1093}
1094impl From<SchnorrSignature> for [u8; 64usize] {
1095 #[track_caller]
1096 fn from(value: SchnorrSignature) -> Self {
1097 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1098 }
1099}
1100impl<'a> From<SchnorrSignatureReader<'a>> for &'a [u8; 64usize] {
1101 #[track_caller]
1102 fn from(value: SchnorrSignatureReader<'a>) -> Self {
1103 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1104 }
1105}
1106impl<'a> From<&'a SchnorrSignatureReader<'a>> for &'a [u8; 64usize] {
1107 #[track_caller]
1108 fn from(value: &'a SchnorrSignatureReader<'a>) -> Self {
1109 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1110 }
1111}
1112#[derive(Clone)]
1113pub struct SchnorrXOnlyPubkey(molecule::bytes::Bytes);
1114impl ::core::fmt::LowerHex for SchnorrXOnlyPubkey {
1115 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1116 use molecule::hex_string;
1117 if f.alternate() {
1118 write!(f, "0x")?;
1119 }
1120 write!(f, "{}", hex_string(self.as_slice()))
1121 }
1122}
1123impl ::core::fmt::Debug for SchnorrXOnlyPubkey {
1124 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1125 write!(f, "{}({:#x})", Self::NAME, self)
1126 }
1127}
1128impl ::core::fmt::Display for SchnorrXOnlyPubkey {
1129 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1130 use molecule::hex_string;
1131 let raw_data = hex_string(&self.raw_data());
1132 write!(f, "{}(0x{})", Self::NAME, raw_data)
1133 }
1134}
1135impl ::core::default::Default for SchnorrXOnlyPubkey {
1136 fn default() -> Self {
1137 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
1138 SchnorrXOnlyPubkey::new_unchecked(v)
1139 }
1140}
1141impl SchnorrXOnlyPubkey {
1142 const DEFAULT_VALUE: [u8; 32] = [
1143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1144 0, 0,
1145 ];
1146 pub const TOTAL_SIZE: usize = 32;
1147 pub const ITEM_SIZE: usize = 1;
1148 pub const ITEM_COUNT: usize = 32;
1149 pub fn nth0(&self) -> Byte {
1150 Byte::new_unchecked(self.0.slice(0..1))
1151 }
1152 pub fn nth1(&self) -> Byte {
1153 Byte::new_unchecked(self.0.slice(1..2))
1154 }
1155 pub fn nth2(&self) -> Byte {
1156 Byte::new_unchecked(self.0.slice(2..3))
1157 }
1158 pub fn nth3(&self) -> Byte {
1159 Byte::new_unchecked(self.0.slice(3..4))
1160 }
1161 pub fn nth4(&self) -> Byte {
1162 Byte::new_unchecked(self.0.slice(4..5))
1163 }
1164 pub fn nth5(&self) -> Byte {
1165 Byte::new_unchecked(self.0.slice(5..6))
1166 }
1167 pub fn nth6(&self) -> Byte {
1168 Byte::new_unchecked(self.0.slice(6..7))
1169 }
1170 pub fn nth7(&self) -> Byte {
1171 Byte::new_unchecked(self.0.slice(7..8))
1172 }
1173 pub fn nth8(&self) -> Byte {
1174 Byte::new_unchecked(self.0.slice(8..9))
1175 }
1176 pub fn nth9(&self) -> Byte {
1177 Byte::new_unchecked(self.0.slice(9..10))
1178 }
1179 pub fn nth10(&self) -> Byte {
1180 Byte::new_unchecked(self.0.slice(10..11))
1181 }
1182 pub fn nth11(&self) -> Byte {
1183 Byte::new_unchecked(self.0.slice(11..12))
1184 }
1185 pub fn nth12(&self) -> Byte {
1186 Byte::new_unchecked(self.0.slice(12..13))
1187 }
1188 pub fn nth13(&self) -> Byte {
1189 Byte::new_unchecked(self.0.slice(13..14))
1190 }
1191 pub fn nth14(&self) -> Byte {
1192 Byte::new_unchecked(self.0.slice(14..15))
1193 }
1194 pub fn nth15(&self) -> Byte {
1195 Byte::new_unchecked(self.0.slice(15..16))
1196 }
1197 pub fn nth16(&self) -> Byte {
1198 Byte::new_unchecked(self.0.slice(16..17))
1199 }
1200 pub fn nth17(&self) -> Byte {
1201 Byte::new_unchecked(self.0.slice(17..18))
1202 }
1203 pub fn nth18(&self) -> Byte {
1204 Byte::new_unchecked(self.0.slice(18..19))
1205 }
1206 pub fn nth19(&self) -> Byte {
1207 Byte::new_unchecked(self.0.slice(19..20))
1208 }
1209 pub fn nth20(&self) -> Byte {
1210 Byte::new_unchecked(self.0.slice(20..21))
1211 }
1212 pub fn nth21(&self) -> Byte {
1213 Byte::new_unchecked(self.0.slice(21..22))
1214 }
1215 pub fn nth22(&self) -> Byte {
1216 Byte::new_unchecked(self.0.slice(22..23))
1217 }
1218 pub fn nth23(&self) -> Byte {
1219 Byte::new_unchecked(self.0.slice(23..24))
1220 }
1221 pub fn nth24(&self) -> Byte {
1222 Byte::new_unchecked(self.0.slice(24..25))
1223 }
1224 pub fn nth25(&self) -> Byte {
1225 Byte::new_unchecked(self.0.slice(25..26))
1226 }
1227 pub fn nth26(&self) -> Byte {
1228 Byte::new_unchecked(self.0.slice(26..27))
1229 }
1230 pub fn nth27(&self) -> Byte {
1231 Byte::new_unchecked(self.0.slice(27..28))
1232 }
1233 pub fn nth28(&self) -> Byte {
1234 Byte::new_unchecked(self.0.slice(28..29))
1235 }
1236 pub fn nth29(&self) -> Byte {
1237 Byte::new_unchecked(self.0.slice(29..30))
1238 }
1239 pub fn nth30(&self) -> Byte {
1240 Byte::new_unchecked(self.0.slice(30..31))
1241 }
1242 pub fn nth31(&self) -> Byte {
1243 Byte::new_unchecked(self.0.slice(31..32))
1244 }
1245 pub fn raw_data(&self) -> molecule::bytes::Bytes {
1246 self.as_bytes()
1247 }
1248 pub fn as_reader<'r>(&'r self) -> SchnorrXOnlyPubkeyReader<'r> {
1249 SchnorrXOnlyPubkeyReader::new_unchecked(self.as_slice())
1250 }
1251}
1252impl molecule::prelude::Entity for SchnorrXOnlyPubkey {
1253 type Builder = SchnorrXOnlyPubkeyBuilder;
1254 const NAME: &'static str = "SchnorrXOnlyPubkey";
1255 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
1256 SchnorrXOnlyPubkey(data)
1257 }
1258 fn as_bytes(&self) -> molecule::bytes::Bytes {
1259 self.0.clone()
1260 }
1261 fn as_slice(&self) -> &[u8] {
1262 &self.0[..]
1263 }
1264 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1265 SchnorrXOnlyPubkeyReader::from_slice(slice).map(|reader| reader.to_entity())
1266 }
1267 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1268 SchnorrXOnlyPubkeyReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
1269 }
1270 fn new_builder() -> Self::Builder {
1271 ::core::default::Default::default()
1272 }
1273 fn as_builder(self) -> Self::Builder {
1274 Self::new_builder().set([
1275 self.nth0(),
1276 self.nth1(),
1277 self.nth2(),
1278 self.nth3(),
1279 self.nth4(),
1280 self.nth5(),
1281 self.nth6(),
1282 self.nth7(),
1283 self.nth8(),
1284 self.nth9(),
1285 self.nth10(),
1286 self.nth11(),
1287 self.nth12(),
1288 self.nth13(),
1289 self.nth14(),
1290 self.nth15(),
1291 self.nth16(),
1292 self.nth17(),
1293 self.nth18(),
1294 self.nth19(),
1295 self.nth20(),
1296 self.nth21(),
1297 self.nth22(),
1298 self.nth23(),
1299 self.nth24(),
1300 self.nth25(),
1301 self.nth26(),
1302 self.nth27(),
1303 self.nth28(),
1304 self.nth29(),
1305 self.nth30(),
1306 self.nth31(),
1307 ])
1308 }
1309}
1310#[derive(Clone, Copy)]
1311pub struct SchnorrXOnlyPubkeyReader<'r>(&'r [u8]);
1312impl<'r> ::core::fmt::LowerHex for SchnorrXOnlyPubkeyReader<'r> {
1313 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1314 use molecule::hex_string;
1315 if f.alternate() {
1316 write!(f, "0x")?;
1317 }
1318 write!(f, "{}", hex_string(self.as_slice()))
1319 }
1320}
1321impl<'r> ::core::fmt::Debug for SchnorrXOnlyPubkeyReader<'r> {
1322 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1323 write!(f, "{}({:#x})", Self::NAME, self)
1324 }
1325}
1326impl<'r> ::core::fmt::Display for SchnorrXOnlyPubkeyReader<'r> {
1327 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1328 use molecule::hex_string;
1329 let raw_data = hex_string(&self.raw_data());
1330 write!(f, "{}(0x{})", Self::NAME, raw_data)
1331 }
1332}
1333impl<'r> SchnorrXOnlyPubkeyReader<'r> {
1334 pub const TOTAL_SIZE: usize = 32;
1335 pub const ITEM_SIZE: usize = 1;
1336 pub const ITEM_COUNT: usize = 32;
1337 pub fn nth0(&self) -> ByteReader<'r> {
1338 ByteReader::new_unchecked(&self.as_slice()[0..1])
1339 }
1340 pub fn nth1(&self) -> ByteReader<'r> {
1341 ByteReader::new_unchecked(&self.as_slice()[1..2])
1342 }
1343 pub fn nth2(&self) -> ByteReader<'r> {
1344 ByteReader::new_unchecked(&self.as_slice()[2..3])
1345 }
1346 pub fn nth3(&self) -> ByteReader<'r> {
1347 ByteReader::new_unchecked(&self.as_slice()[3..4])
1348 }
1349 pub fn nth4(&self) -> ByteReader<'r> {
1350 ByteReader::new_unchecked(&self.as_slice()[4..5])
1351 }
1352 pub fn nth5(&self) -> ByteReader<'r> {
1353 ByteReader::new_unchecked(&self.as_slice()[5..6])
1354 }
1355 pub fn nth6(&self) -> ByteReader<'r> {
1356 ByteReader::new_unchecked(&self.as_slice()[6..7])
1357 }
1358 pub fn nth7(&self) -> ByteReader<'r> {
1359 ByteReader::new_unchecked(&self.as_slice()[7..8])
1360 }
1361 pub fn nth8(&self) -> ByteReader<'r> {
1362 ByteReader::new_unchecked(&self.as_slice()[8..9])
1363 }
1364 pub fn nth9(&self) -> ByteReader<'r> {
1365 ByteReader::new_unchecked(&self.as_slice()[9..10])
1366 }
1367 pub fn nth10(&self) -> ByteReader<'r> {
1368 ByteReader::new_unchecked(&self.as_slice()[10..11])
1369 }
1370 pub fn nth11(&self) -> ByteReader<'r> {
1371 ByteReader::new_unchecked(&self.as_slice()[11..12])
1372 }
1373 pub fn nth12(&self) -> ByteReader<'r> {
1374 ByteReader::new_unchecked(&self.as_slice()[12..13])
1375 }
1376 pub fn nth13(&self) -> ByteReader<'r> {
1377 ByteReader::new_unchecked(&self.as_slice()[13..14])
1378 }
1379 pub fn nth14(&self) -> ByteReader<'r> {
1380 ByteReader::new_unchecked(&self.as_slice()[14..15])
1381 }
1382 pub fn nth15(&self) -> ByteReader<'r> {
1383 ByteReader::new_unchecked(&self.as_slice()[15..16])
1384 }
1385 pub fn nth16(&self) -> ByteReader<'r> {
1386 ByteReader::new_unchecked(&self.as_slice()[16..17])
1387 }
1388 pub fn nth17(&self) -> ByteReader<'r> {
1389 ByteReader::new_unchecked(&self.as_slice()[17..18])
1390 }
1391 pub fn nth18(&self) -> ByteReader<'r> {
1392 ByteReader::new_unchecked(&self.as_slice()[18..19])
1393 }
1394 pub fn nth19(&self) -> ByteReader<'r> {
1395 ByteReader::new_unchecked(&self.as_slice()[19..20])
1396 }
1397 pub fn nth20(&self) -> ByteReader<'r> {
1398 ByteReader::new_unchecked(&self.as_slice()[20..21])
1399 }
1400 pub fn nth21(&self) -> ByteReader<'r> {
1401 ByteReader::new_unchecked(&self.as_slice()[21..22])
1402 }
1403 pub fn nth22(&self) -> ByteReader<'r> {
1404 ByteReader::new_unchecked(&self.as_slice()[22..23])
1405 }
1406 pub fn nth23(&self) -> ByteReader<'r> {
1407 ByteReader::new_unchecked(&self.as_slice()[23..24])
1408 }
1409 pub fn nth24(&self) -> ByteReader<'r> {
1410 ByteReader::new_unchecked(&self.as_slice()[24..25])
1411 }
1412 pub fn nth25(&self) -> ByteReader<'r> {
1413 ByteReader::new_unchecked(&self.as_slice()[25..26])
1414 }
1415 pub fn nth26(&self) -> ByteReader<'r> {
1416 ByteReader::new_unchecked(&self.as_slice()[26..27])
1417 }
1418 pub fn nth27(&self) -> ByteReader<'r> {
1419 ByteReader::new_unchecked(&self.as_slice()[27..28])
1420 }
1421 pub fn nth28(&self) -> ByteReader<'r> {
1422 ByteReader::new_unchecked(&self.as_slice()[28..29])
1423 }
1424 pub fn nth29(&self) -> ByteReader<'r> {
1425 ByteReader::new_unchecked(&self.as_slice()[29..30])
1426 }
1427 pub fn nth30(&self) -> ByteReader<'r> {
1428 ByteReader::new_unchecked(&self.as_slice()[30..31])
1429 }
1430 pub fn nth31(&self) -> ByteReader<'r> {
1431 ByteReader::new_unchecked(&self.as_slice()[31..32])
1432 }
1433 pub fn raw_data(&self) -> &'r [u8] {
1434 self.as_slice()
1435 }
1436}
1437impl<'r> molecule::prelude::Reader<'r> for SchnorrXOnlyPubkeyReader<'r> {
1438 type Entity = SchnorrXOnlyPubkey;
1439 const NAME: &'static str = "SchnorrXOnlyPubkeyReader";
1440 fn to_entity(&self) -> Self::Entity {
1441 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
1442 }
1443 fn new_unchecked(slice: &'r [u8]) -> Self {
1444 SchnorrXOnlyPubkeyReader(slice)
1445 }
1446 fn as_slice(&self) -> &'r [u8] {
1447 self.0
1448 }
1449 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
1450 use molecule::verification_error as ve;
1451 let slice_len = slice.len();
1452 if slice_len != Self::TOTAL_SIZE {
1453 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
1454 }
1455 Ok(())
1456 }
1457}
1458#[derive(Clone)]
1459pub struct SchnorrXOnlyPubkeyBuilder(pub(crate) [Byte; 32]);
1460impl ::core::fmt::Debug for SchnorrXOnlyPubkeyBuilder {
1461 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1462 write!(f, "{}({:?})", Self::NAME, &self.0[..])
1463 }
1464}
1465impl ::core::default::Default for SchnorrXOnlyPubkeyBuilder {
1466 fn default() -> Self {
1467 SchnorrXOnlyPubkeyBuilder([
1468 Byte::default(),
1469 Byte::default(),
1470 Byte::default(),
1471 Byte::default(),
1472 Byte::default(),
1473 Byte::default(),
1474 Byte::default(),
1475 Byte::default(),
1476 Byte::default(),
1477 Byte::default(),
1478 Byte::default(),
1479 Byte::default(),
1480 Byte::default(),
1481 Byte::default(),
1482 Byte::default(),
1483 Byte::default(),
1484 Byte::default(),
1485 Byte::default(),
1486 Byte::default(),
1487 Byte::default(),
1488 Byte::default(),
1489 Byte::default(),
1490 Byte::default(),
1491 Byte::default(),
1492 Byte::default(),
1493 Byte::default(),
1494 Byte::default(),
1495 Byte::default(),
1496 Byte::default(),
1497 Byte::default(),
1498 Byte::default(),
1499 Byte::default(),
1500 ])
1501 }
1502}
1503impl SchnorrXOnlyPubkeyBuilder {
1504 pub const TOTAL_SIZE: usize = 32;
1505 pub const ITEM_SIZE: usize = 1;
1506 pub const ITEM_COUNT: usize = 32;
1507 pub fn set(mut self, v: [Byte; 32]) -> Self {
1508 self.0 = v;
1509 self
1510 }
1511 pub fn nth0(mut self, v: Byte) -> Self {
1512 self.0[0] = v;
1513 self
1514 }
1515 pub fn nth1(mut self, v: Byte) -> Self {
1516 self.0[1] = v;
1517 self
1518 }
1519 pub fn nth2(mut self, v: Byte) -> Self {
1520 self.0[2] = v;
1521 self
1522 }
1523 pub fn nth3(mut self, v: Byte) -> Self {
1524 self.0[3] = v;
1525 self
1526 }
1527 pub fn nth4(mut self, v: Byte) -> Self {
1528 self.0[4] = v;
1529 self
1530 }
1531 pub fn nth5(mut self, v: Byte) -> Self {
1532 self.0[5] = v;
1533 self
1534 }
1535 pub fn nth6(mut self, v: Byte) -> Self {
1536 self.0[6] = v;
1537 self
1538 }
1539 pub fn nth7(mut self, v: Byte) -> Self {
1540 self.0[7] = v;
1541 self
1542 }
1543 pub fn nth8(mut self, v: Byte) -> Self {
1544 self.0[8] = v;
1545 self
1546 }
1547 pub fn nth9(mut self, v: Byte) -> Self {
1548 self.0[9] = v;
1549 self
1550 }
1551 pub fn nth10(mut self, v: Byte) -> Self {
1552 self.0[10] = v;
1553 self
1554 }
1555 pub fn nth11(mut self, v: Byte) -> Self {
1556 self.0[11] = v;
1557 self
1558 }
1559 pub fn nth12(mut self, v: Byte) -> Self {
1560 self.0[12] = v;
1561 self
1562 }
1563 pub fn nth13(mut self, v: Byte) -> Self {
1564 self.0[13] = v;
1565 self
1566 }
1567 pub fn nth14(mut self, v: Byte) -> Self {
1568 self.0[14] = v;
1569 self
1570 }
1571 pub fn nth15(mut self, v: Byte) -> Self {
1572 self.0[15] = v;
1573 self
1574 }
1575 pub fn nth16(mut self, v: Byte) -> Self {
1576 self.0[16] = v;
1577 self
1578 }
1579 pub fn nth17(mut self, v: Byte) -> Self {
1580 self.0[17] = v;
1581 self
1582 }
1583 pub fn nth18(mut self, v: Byte) -> Self {
1584 self.0[18] = v;
1585 self
1586 }
1587 pub fn nth19(mut self, v: Byte) -> Self {
1588 self.0[19] = v;
1589 self
1590 }
1591 pub fn nth20(mut self, v: Byte) -> Self {
1592 self.0[20] = v;
1593 self
1594 }
1595 pub fn nth21(mut self, v: Byte) -> Self {
1596 self.0[21] = v;
1597 self
1598 }
1599 pub fn nth22(mut self, v: Byte) -> Self {
1600 self.0[22] = v;
1601 self
1602 }
1603 pub fn nth23(mut self, v: Byte) -> Self {
1604 self.0[23] = v;
1605 self
1606 }
1607 pub fn nth24(mut self, v: Byte) -> Self {
1608 self.0[24] = v;
1609 self
1610 }
1611 pub fn nth25(mut self, v: Byte) -> Self {
1612 self.0[25] = v;
1613 self
1614 }
1615 pub fn nth26(mut self, v: Byte) -> Self {
1616 self.0[26] = v;
1617 self
1618 }
1619 pub fn nth27(mut self, v: Byte) -> Self {
1620 self.0[27] = v;
1621 self
1622 }
1623 pub fn nth28(mut self, v: Byte) -> Self {
1624 self.0[28] = v;
1625 self
1626 }
1627 pub fn nth29(mut self, v: Byte) -> Self {
1628 self.0[29] = v;
1629 self
1630 }
1631 pub fn nth30(mut self, v: Byte) -> Self {
1632 self.0[30] = v;
1633 self
1634 }
1635 pub fn nth31(mut self, v: Byte) -> Self {
1636 self.0[31] = v;
1637 self
1638 }
1639}
1640impl molecule::prelude::Builder for SchnorrXOnlyPubkeyBuilder {
1641 type Entity = SchnorrXOnlyPubkey;
1642 const NAME: &'static str = "SchnorrXOnlyPubkeyBuilder";
1643 fn expected_length(&self) -> usize {
1644 Self::TOTAL_SIZE
1645 }
1646 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
1647 writer.write_all(self.0[0].as_slice())?;
1648 writer.write_all(self.0[1].as_slice())?;
1649 writer.write_all(self.0[2].as_slice())?;
1650 writer.write_all(self.0[3].as_slice())?;
1651 writer.write_all(self.0[4].as_slice())?;
1652 writer.write_all(self.0[5].as_slice())?;
1653 writer.write_all(self.0[6].as_slice())?;
1654 writer.write_all(self.0[7].as_slice())?;
1655 writer.write_all(self.0[8].as_slice())?;
1656 writer.write_all(self.0[9].as_slice())?;
1657 writer.write_all(self.0[10].as_slice())?;
1658 writer.write_all(self.0[11].as_slice())?;
1659 writer.write_all(self.0[12].as_slice())?;
1660 writer.write_all(self.0[13].as_slice())?;
1661 writer.write_all(self.0[14].as_slice())?;
1662 writer.write_all(self.0[15].as_slice())?;
1663 writer.write_all(self.0[16].as_slice())?;
1664 writer.write_all(self.0[17].as_slice())?;
1665 writer.write_all(self.0[18].as_slice())?;
1666 writer.write_all(self.0[19].as_slice())?;
1667 writer.write_all(self.0[20].as_slice())?;
1668 writer.write_all(self.0[21].as_slice())?;
1669 writer.write_all(self.0[22].as_slice())?;
1670 writer.write_all(self.0[23].as_slice())?;
1671 writer.write_all(self.0[24].as_slice())?;
1672 writer.write_all(self.0[25].as_slice())?;
1673 writer.write_all(self.0[26].as_slice())?;
1674 writer.write_all(self.0[27].as_slice())?;
1675 writer.write_all(self.0[28].as_slice())?;
1676 writer.write_all(self.0[29].as_slice())?;
1677 writer.write_all(self.0[30].as_slice())?;
1678 writer.write_all(self.0[31].as_slice())?;
1679 Ok(())
1680 }
1681 fn build(&self) -> Self::Entity {
1682 let mut inner = Vec::with_capacity(self.expected_length());
1683 self.write(&mut inner)
1684 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
1685 SchnorrXOnlyPubkey::new_unchecked(inner.into())
1686 }
1687}
1688impl From<[Byte; 32usize]> for SchnorrXOnlyPubkey {
1689 fn from(value: [Byte; 32usize]) -> Self {
1690 Self::new_builder().set(value).build()
1691 }
1692}
1693impl ::core::convert::TryFrom<&[Byte]> for SchnorrXOnlyPubkey {
1694 type Error = ::core::array::TryFromSliceError;
1695 fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
1696 Ok(Self::new_builder()
1697 .set(<&[Byte; 32usize]>::try_from(value)?.clone())
1698 .build())
1699 }
1700}
1701impl From<SchnorrXOnlyPubkey> for [Byte; 32usize] {
1702 #[track_caller]
1703 fn from(value: SchnorrXOnlyPubkey) -> Self {
1704 [
1705 value.nth0(),
1706 value.nth1(),
1707 value.nth2(),
1708 value.nth3(),
1709 value.nth4(),
1710 value.nth5(),
1711 value.nth6(),
1712 value.nth7(),
1713 value.nth8(),
1714 value.nth9(),
1715 value.nth10(),
1716 value.nth11(),
1717 value.nth12(),
1718 value.nth13(),
1719 value.nth14(),
1720 value.nth15(),
1721 value.nth16(),
1722 value.nth17(),
1723 value.nth18(),
1724 value.nth19(),
1725 value.nth20(),
1726 value.nth21(),
1727 value.nth22(),
1728 value.nth23(),
1729 value.nth24(),
1730 value.nth25(),
1731 value.nth26(),
1732 value.nth27(),
1733 value.nth28(),
1734 value.nth29(),
1735 value.nth30(),
1736 value.nth31(),
1737 ]
1738 }
1739}
1740impl From<[u8; 32usize]> for SchnorrXOnlyPubkey {
1741 fn from(value: [u8; 32usize]) -> Self {
1742 SchnorrXOnlyPubkeyReader::new_unchecked(&value).to_entity()
1743 }
1744}
1745impl ::core::convert::TryFrom<&[u8]> for SchnorrXOnlyPubkey {
1746 type Error = ::core::array::TryFromSliceError;
1747 fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
1748 Ok(<[u8; 32usize]>::try_from(value)?.into())
1749 }
1750}
1751impl From<SchnorrXOnlyPubkey> for [u8; 32usize] {
1752 #[track_caller]
1753 fn from(value: SchnorrXOnlyPubkey) -> Self {
1754 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1755 }
1756}
1757impl<'a> From<SchnorrXOnlyPubkeyReader<'a>> for &'a [u8; 32usize] {
1758 #[track_caller]
1759 fn from(value: SchnorrXOnlyPubkeyReader<'a>) -> Self {
1760 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1761 }
1762}
1763impl<'a> From<&'a SchnorrXOnlyPubkeyReader<'a>> for &'a [u8; 32usize] {
1764 #[track_caller]
1765 fn from(value: &'a SchnorrXOnlyPubkeyReader<'a>) -> Self {
1766 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1767 }
1768}
1769#[derive(Clone)]
1770pub struct Cursor(molecule::bytes::Bytes);
1771impl ::core::fmt::LowerHex for Cursor {
1772 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1773 use molecule::hex_string;
1774 if f.alternate() {
1775 write!(f, "0x")?;
1776 }
1777 write!(f, "{}", hex_string(self.as_slice()))
1778 }
1779}
1780impl ::core::fmt::Debug for Cursor {
1781 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1782 write!(f, "{}({:#x})", Self::NAME, self)
1783 }
1784}
1785impl ::core::fmt::Display for Cursor {
1786 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1787 use molecule::hex_string;
1788 let raw_data = hex_string(&self.raw_data());
1789 write!(f, "{}(0x{})", Self::NAME, raw_data)
1790 }
1791}
1792impl ::core::default::Default for Cursor {
1793 fn default() -> Self {
1794 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
1795 Cursor::new_unchecked(v)
1796 }
1797}
1798impl Cursor {
1799 const DEFAULT_VALUE: [u8; 45] = [
1800 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1801 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1802 ];
1803 pub const TOTAL_SIZE: usize = 45;
1804 pub const ITEM_SIZE: usize = 1;
1805 pub const ITEM_COUNT: usize = 45;
1806 pub fn nth0(&self) -> Byte {
1807 Byte::new_unchecked(self.0.slice(0..1))
1808 }
1809 pub fn nth1(&self) -> Byte {
1810 Byte::new_unchecked(self.0.slice(1..2))
1811 }
1812 pub fn nth2(&self) -> Byte {
1813 Byte::new_unchecked(self.0.slice(2..3))
1814 }
1815 pub fn nth3(&self) -> Byte {
1816 Byte::new_unchecked(self.0.slice(3..4))
1817 }
1818 pub fn nth4(&self) -> Byte {
1819 Byte::new_unchecked(self.0.slice(4..5))
1820 }
1821 pub fn nth5(&self) -> Byte {
1822 Byte::new_unchecked(self.0.slice(5..6))
1823 }
1824 pub fn nth6(&self) -> Byte {
1825 Byte::new_unchecked(self.0.slice(6..7))
1826 }
1827 pub fn nth7(&self) -> Byte {
1828 Byte::new_unchecked(self.0.slice(7..8))
1829 }
1830 pub fn nth8(&self) -> Byte {
1831 Byte::new_unchecked(self.0.slice(8..9))
1832 }
1833 pub fn nth9(&self) -> Byte {
1834 Byte::new_unchecked(self.0.slice(9..10))
1835 }
1836 pub fn nth10(&self) -> Byte {
1837 Byte::new_unchecked(self.0.slice(10..11))
1838 }
1839 pub fn nth11(&self) -> Byte {
1840 Byte::new_unchecked(self.0.slice(11..12))
1841 }
1842 pub fn nth12(&self) -> Byte {
1843 Byte::new_unchecked(self.0.slice(12..13))
1844 }
1845 pub fn nth13(&self) -> Byte {
1846 Byte::new_unchecked(self.0.slice(13..14))
1847 }
1848 pub fn nth14(&self) -> Byte {
1849 Byte::new_unchecked(self.0.slice(14..15))
1850 }
1851 pub fn nth15(&self) -> Byte {
1852 Byte::new_unchecked(self.0.slice(15..16))
1853 }
1854 pub fn nth16(&self) -> Byte {
1855 Byte::new_unchecked(self.0.slice(16..17))
1856 }
1857 pub fn nth17(&self) -> Byte {
1858 Byte::new_unchecked(self.0.slice(17..18))
1859 }
1860 pub fn nth18(&self) -> Byte {
1861 Byte::new_unchecked(self.0.slice(18..19))
1862 }
1863 pub fn nth19(&self) -> Byte {
1864 Byte::new_unchecked(self.0.slice(19..20))
1865 }
1866 pub fn nth20(&self) -> Byte {
1867 Byte::new_unchecked(self.0.slice(20..21))
1868 }
1869 pub fn nth21(&self) -> Byte {
1870 Byte::new_unchecked(self.0.slice(21..22))
1871 }
1872 pub fn nth22(&self) -> Byte {
1873 Byte::new_unchecked(self.0.slice(22..23))
1874 }
1875 pub fn nth23(&self) -> Byte {
1876 Byte::new_unchecked(self.0.slice(23..24))
1877 }
1878 pub fn nth24(&self) -> Byte {
1879 Byte::new_unchecked(self.0.slice(24..25))
1880 }
1881 pub fn nth25(&self) -> Byte {
1882 Byte::new_unchecked(self.0.slice(25..26))
1883 }
1884 pub fn nth26(&self) -> Byte {
1885 Byte::new_unchecked(self.0.slice(26..27))
1886 }
1887 pub fn nth27(&self) -> Byte {
1888 Byte::new_unchecked(self.0.slice(27..28))
1889 }
1890 pub fn nth28(&self) -> Byte {
1891 Byte::new_unchecked(self.0.slice(28..29))
1892 }
1893 pub fn nth29(&self) -> Byte {
1894 Byte::new_unchecked(self.0.slice(29..30))
1895 }
1896 pub fn nth30(&self) -> Byte {
1897 Byte::new_unchecked(self.0.slice(30..31))
1898 }
1899 pub fn nth31(&self) -> Byte {
1900 Byte::new_unchecked(self.0.slice(31..32))
1901 }
1902 pub fn nth32(&self) -> Byte {
1903 Byte::new_unchecked(self.0.slice(32..33))
1904 }
1905 pub fn nth33(&self) -> Byte {
1906 Byte::new_unchecked(self.0.slice(33..34))
1907 }
1908 pub fn nth34(&self) -> Byte {
1909 Byte::new_unchecked(self.0.slice(34..35))
1910 }
1911 pub fn nth35(&self) -> Byte {
1912 Byte::new_unchecked(self.0.slice(35..36))
1913 }
1914 pub fn nth36(&self) -> Byte {
1915 Byte::new_unchecked(self.0.slice(36..37))
1916 }
1917 pub fn nth37(&self) -> Byte {
1918 Byte::new_unchecked(self.0.slice(37..38))
1919 }
1920 pub fn nth38(&self) -> Byte {
1921 Byte::new_unchecked(self.0.slice(38..39))
1922 }
1923 pub fn nth39(&self) -> Byte {
1924 Byte::new_unchecked(self.0.slice(39..40))
1925 }
1926 pub fn nth40(&self) -> Byte {
1927 Byte::new_unchecked(self.0.slice(40..41))
1928 }
1929 pub fn nth41(&self) -> Byte {
1930 Byte::new_unchecked(self.0.slice(41..42))
1931 }
1932 pub fn nth42(&self) -> Byte {
1933 Byte::new_unchecked(self.0.slice(42..43))
1934 }
1935 pub fn nth43(&self) -> Byte {
1936 Byte::new_unchecked(self.0.slice(43..44))
1937 }
1938 pub fn nth44(&self) -> Byte {
1939 Byte::new_unchecked(self.0.slice(44..45))
1940 }
1941 pub fn raw_data(&self) -> molecule::bytes::Bytes {
1942 self.as_bytes()
1943 }
1944 pub fn as_reader<'r>(&'r self) -> CursorReader<'r> {
1945 CursorReader::new_unchecked(self.as_slice())
1946 }
1947}
1948impl molecule::prelude::Entity for Cursor {
1949 type Builder = CursorBuilder;
1950 const NAME: &'static str = "Cursor";
1951 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
1952 Cursor(data)
1953 }
1954 fn as_bytes(&self) -> molecule::bytes::Bytes {
1955 self.0.clone()
1956 }
1957 fn as_slice(&self) -> &[u8] {
1958 &self.0[..]
1959 }
1960 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1961 CursorReader::from_slice(slice).map(|reader| reader.to_entity())
1962 }
1963 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1964 CursorReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
1965 }
1966 fn new_builder() -> Self::Builder {
1967 ::core::default::Default::default()
1968 }
1969 fn as_builder(self) -> Self::Builder {
1970 Self::new_builder().set([
1971 self.nth0(),
1972 self.nth1(),
1973 self.nth2(),
1974 self.nth3(),
1975 self.nth4(),
1976 self.nth5(),
1977 self.nth6(),
1978 self.nth7(),
1979 self.nth8(),
1980 self.nth9(),
1981 self.nth10(),
1982 self.nth11(),
1983 self.nth12(),
1984 self.nth13(),
1985 self.nth14(),
1986 self.nth15(),
1987 self.nth16(),
1988 self.nth17(),
1989 self.nth18(),
1990 self.nth19(),
1991 self.nth20(),
1992 self.nth21(),
1993 self.nth22(),
1994 self.nth23(),
1995 self.nth24(),
1996 self.nth25(),
1997 self.nth26(),
1998 self.nth27(),
1999 self.nth28(),
2000 self.nth29(),
2001 self.nth30(),
2002 self.nth31(),
2003 self.nth32(),
2004 self.nth33(),
2005 self.nth34(),
2006 self.nth35(),
2007 self.nth36(),
2008 self.nth37(),
2009 self.nth38(),
2010 self.nth39(),
2011 self.nth40(),
2012 self.nth41(),
2013 self.nth42(),
2014 self.nth43(),
2015 self.nth44(),
2016 ])
2017 }
2018}
2019#[derive(Clone, Copy)]
2020pub struct CursorReader<'r>(&'r [u8]);
2021impl<'r> ::core::fmt::LowerHex for CursorReader<'r> {
2022 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2023 use molecule::hex_string;
2024 if f.alternate() {
2025 write!(f, "0x")?;
2026 }
2027 write!(f, "{}", hex_string(self.as_slice()))
2028 }
2029}
2030impl<'r> ::core::fmt::Debug for CursorReader<'r> {
2031 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2032 write!(f, "{}({:#x})", Self::NAME, self)
2033 }
2034}
2035impl<'r> ::core::fmt::Display for CursorReader<'r> {
2036 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2037 use molecule::hex_string;
2038 let raw_data = hex_string(&self.raw_data());
2039 write!(f, "{}(0x{})", Self::NAME, raw_data)
2040 }
2041}
2042impl<'r> CursorReader<'r> {
2043 pub const TOTAL_SIZE: usize = 45;
2044 pub const ITEM_SIZE: usize = 1;
2045 pub const ITEM_COUNT: usize = 45;
2046 pub fn nth0(&self) -> ByteReader<'r> {
2047 ByteReader::new_unchecked(&self.as_slice()[0..1])
2048 }
2049 pub fn nth1(&self) -> ByteReader<'r> {
2050 ByteReader::new_unchecked(&self.as_slice()[1..2])
2051 }
2052 pub fn nth2(&self) -> ByteReader<'r> {
2053 ByteReader::new_unchecked(&self.as_slice()[2..3])
2054 }
2055 pub fn nth3(&self) -> ByteReader<'r> {
2056 ByteReader::new_unchecked(&self.as_slice()[3..4])
2057 }
2058 pub fn nth4(&self) -> ByteReader<'r> {
2059 ByteReader::new_unchecked(&self.as_slice()[4..5])
2060 }
2061 pub fn nth5(&self) -> ByteReader<'r> {
2062 ByteReader::new_unchecked(&self.as_slice()[5..6])
2063 }
2064 pub fn nth6(&self) -> ByteReader<'r> {
2065 ByteReader::new_unchecked(&self.as_slice()[6..7])
2066 }
2067 pub fn nth7(&self) -> ByteReader<'r> {
2068 ByteReader::new_unchecked(&self.as_slice()[7..8])
2069 }
2070 pub fn nth8(&self) -> ByteReader<'r> {
2071 ByteReader::new_unchecked(&self.as_slice()[8..9])
2072 }
2073 pub fn nth9(&self) -> ByteReader<'r> {
2074 ByteReader::new_unchecked(&self.as_slice()[9..10])
2075 }
2076 pub fn nth10(&self) -> ByteReader<'r> {
2077 ByteReader::new_unchecked(&self.as_slice()[10..11])
2078 }
2079 pub fn nth11(&self) -> ByteReader<'r> {
2080 ByteReader::new_unchecked(&self.as_slice()[11..12])
2081 }
2082 pub fn nth12(&self) -> ByteReader<'r> {
2083 ByteReader::new_unchecked(&self.as_slice()[12..13])
2084 }
2085 pub fn nth13(&self) -> ByteReader<'r> {
2086 ByteReader::new_unchecked(&self.as_slice()[13..14])
2087 }
2088 pub fn nth14(&self) -> ByteReader<'r> {
2089 ByteReader::new_unchecked(&self.as_slice()[14..15])
2090 }
2091 pub fn nth15(&self) -> ByteReader<'r> {
2092 ByteReader::new_unchecked(&self.as_slice()[15..16])
2093 }
2094 pub fn nth16(&self) -> ByteReader<'r> {
2095 ByteReader::new_unchecked(&self.as_slice()[16..17])
2096 }
2097 pub fn nth17(&self) -> ByteReader<'r> {
2098 ByteReader::new_unchecked(&self.as_slice()[17..18])
2099 }
2100 pub fn nth18(&self) -> ByteReader<'r> {
2101 ByteReader::new_unchecked(&self.as_slice()[18..19])
2102 }
2103 pub fn nth19(&self) -> ByteReader<'r> {
2104 ByteReader::new_unchecked(&self.as_slice()[19..20])
2105 }
2106 pub fn nth20(&self) -> ByteReader<'r> {
2107 ByteReader::new_unchecked(&self.as_slice()[20..21])
2108 }
2109 pub fn nth21(&self) -> ByteReader<'r> {
2110 ByteReader::new_unchecked(&self.as_slice()[21..22])
2111 }
2112 pub fn nth22(&self) -> ByteReader<'r> {
2113 ByteReader::new_unchecked(&self.as_slice()[22..23])
2114 }
2115 pub fn nth23(&self) -> ByteReader<'r> {
2116 ByteReader::new_unchecked(&self.as_slice()[23..24])
2117 }
2118 pub fn nth24(&self) -> ByteReader<'r> {
2119 ByteReader::new_unchecked(&self.as_slice()[24..25])
2120 }
2121 pub fn nth25(&self) -> ByteReader<'r> {
2122 ByteReader::new_unchecked(&self.as_slice()[25..26])
2123 }
2124 pub fn nth26(&self) -> ByteReader<'r> {
2125 ByteReader::new_unchecked(&self.as_slice()[26..27])
2126 }
2127 pub fn nth27(&self) -> ByteReader<'r> {
2128 ByteReader::new_unchecked(&self.as_slice()[27..28])
2129 }
2130 pub fn nth28(&self) -> ByteReader<'r> {
2131 ByteReader::new_unchecked(&self.as_slice()[28..29])
2132 }
2133 pub fn nth29(&self) -> ByteReader<'r> {
2134 ByteReader::new_unchecked(&self.as_slice()[29..30])
2135 }
2136 pub fn nth30(&self) -> ByteReader<'r> {
2137 ByteReader::new_unchecked(&self.as_slice()[30..31])
2138 }
2139 pub fn nth31(&self) -> ByteReader<'r> {
2140 ByteReader::new_unchecked(&self.as_slice()[31..32])
2141 }
2142 pub fn nth32(&self) -> ByteReader<'r> {
2143 ByteReader::new_unchecked(&self.as_slice()[32..33])
2144 }
2145 pub fn nth33(&self) -> ByteReader<'r> {
2146 ByteReader::new_unchecked(&self.as_slice()[33..34])
2147 }
2148 pub fn nth34(&self) -> ByteReader<'r> {
2149 ByteReader::new_unchecked(&self.as_slice()[34..35])
2150 }
2151 pub fn nth35(&self) -> ByteReader<'r> {
2152 ByteReader::new_unchecked(&self.as_slice()[35..36])
2153 }
2154 pub fn nth36(&self) -> ByteReader<'r> {
2155 ByteReader::new_unchecked(&self.as_slice()[36..37])
2156 }
2157 pub fn nth37(&self) -> ByteReader<'r> {
2158 ByteReader::new_unchecked(&self.as_slice()[37..38])
2159 }
2160 pub fn nth38(&self) -> ByteReader<'r> {
2161 ByteReader::new_unchecked(&self.as_slice()[38..39])
2162 }
2163 pub fn nth39(&self) -> ByteReader<'r> {
2164 ByteReader::new_unchecked(&self.as_slice()[39..40])
2165 }
2166 pub fn nth40(&self) -> ByteReader<'r> {
2167 ByteReader::new_unchecked(&self.as_slice()[40..41])
2168 }
2169 pub fn nth41(&self) -> ByteReader<'r> {
2170 ByteReader::new_unchecked(&self.as_slice()[41..42])
2171 }
2172 pub fn nth42(&self) -> ByteReader<'r> {
2173 ByteReader::new_unchecked(&self.as_slice()[42..43])
2174 }
2175 pub fn nth43(&self) -> ByteReader<'r> {
2176 ByteReader::new_unchecked(&self.as_slice()[43..44])
2177 }
2178 pub fn nth44(&self) -> ByteReader<'r> {
2179 ByteReader::new_unchecked(&self.as_slice()[44..45])
2180 }
2181 pub fn raw_data(&self) -> &'r [u8] {
2182 self.as_slice()
2183 }
2184}
2185impl<'r> molecule::prelude::Reader<'r> for CursorReader<'r> {
2186 type Entity = Cursor;
2187 const NAME: &'static str = "CursorReader";
2188 fn to_entity(&self) -> Self::Entity {
2189 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2190 }
2191 fn new_unchecked(slice: &'r [u8]) -> Self {
2192 CursorReader(slice)
2193 }
2194 fn as_slice(&self) -> &'r [u8] {
2195 self.0
2196 }
2197 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2198 use molecule::verification_error as ve;
2199 let slice_len = slice.len();
2200 if slice_len != Self::TOTAL_SIZE {
2201 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
2202 }
2203 Ok(())
2204 }
2205}
2206#[derive(Clone)]
2207pub struct CursorBuilder(pub(crate) [Byte; 45]);
2208impl ::core::fmt::Debug for CursorBuilder {
2209 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2210 write!(f, "{}({:?})", Self::NAME, &self.0[..])
2211 }
2212}
2213impl ::core::default::Default for CursorBuilder {
2214 fn default() -> Self {
2215 CursorBuilder([
2216 Byte::default(),
2217 Byte::default(),
2218 Byte::default(),
2219 Byte::default(),
2220 Byte::default(),
2221 Byte::default(),
2222 Byte::default(),
2223 Byte::default(),
2224 Byte::default(),
2225 Byte::default(),
2226 Byte::default(),
2227 Byte::default(),
2228 Byte::default(),
2229 Byte::default(),
2230 Byte::default(),
2231 Byte::default(),
2232 Byte::default(),
2233 Byte::default(),
2234 Byte::default(),
2235 Byte::default(),
2236 Byte::default(),
2237 Byte::default(),
2238 Byte::default(),
2239 Byte::default(),
2240 Byte::default(),
2241 Byte::default(),
2242 Byte::default(),
2243 Byte::default(),
2244 Byte::default(),
2245 Byte::default(),
2246 Byte::default(),
2247 Byte::default(),
2248 Byte::default(),
2249 Byte::default(),
2250 Byte::default(),
2251 Byte::default(),
2252 Byte::default(),
2253 Byte::default(),
2254 Byte::default(),
2255 Byte::default(),
2256 Byte::default(),
2257 Byte::default(),
2258 Byte::default(),
2259 Byte::default(),
2260 Byte::default(),
2261 ])
2262 }
2263}
2264impl CursorBuilder {
2265 pub const TOTAL_SIZE: usize = 45;
2266 pub const ITEM_SIZE: usize = 1;
2267 pub const ITEM_COUNT: usize = 45;
2268 pub fn set(mut self, v: [Byte; 45]) -> Self {
2269 self.0 = v;
2270 self
2271 }
2272 pub fn nth0(mut self, v: Byte) -> Self {
2273 self.0[0] = v;
2274 self
2275 }
2276 pub fn nth1(mut self, v: Byte) -> Self {
2277 self.0[1] = v;
2278 self
2279 }
2280 pub fn nth2(mut self, v: Byte) -> Self {
2281 self.0[2] = v;
2282 self
2283 }
2284 pub fn nth3(mut self, v: Byte) -> Self {
2285 self.0[3] = v;
2286 self
2287 }
2288 pub fn nth4(mut self, v: Byte) -> Self {
2289 self.0[4] = v;
2290 self
2291 }
2292 pub fn nth5(mut self, v: Byte) -> Self {
2293 self.0[5] = v;
2294 self
2295 }
2296 pub fn nth6(mut self, v: Byte) -> Self {
2297 self.0[6] = v;
2298 self
2299 }
2300 pub fn nth7(mut self, v: Byte) -> Self {
2301 self.0[7] = v;
2302 self
2303 }
2304 pub fn nth8(mut self, v: Byte) -> Self {
2305 self.0[8] = v;
2306 self
2307 }
2308 pub fn nth9(mut self, v: Byte) -> Self {
2309 self.0[9] = v;
2310 self
2311 }
2312 pub fn nth10(mut self, v: Byte) -> Self {
2313 self.0[10] = v;
2314 self
2315 }
2316 pub fn nth11(mut self, v: Byte) -> Self {
2317 self.0[11] = v;
2318 self
2319 }
2320 pub fn nth12(mut self, v: Byte) -> Self {
2321 self.0[12] = v;
2322 self
2323 }
2324 pub fn nth13(mut self, v: Byte) -> Self {
2325 self.0[13] = v;
2326 self
2327 }
2328 pub fn nth14(mut self, v: Byte) -> Self {
2329 self.0[14] = v;
2330 self
2331 }
2332 pub fn nth15(mut self, v: Byte) -> Self {
2333 self.0[15] = v;
2334 self
2335 }
2336 pub fn nth16(mut self, v: Byte) -> Self {
2337 self.0[16] = v;
2338 self
2339 }
2340 pub fn nth17(mut self, v: Byte) -> Self {
2341 self.0[17] = v;
2342 self
2343 }
2344 pub fn nth18(mut self, v: Byte) -> Self {
2345 self.0[18] = v;
2346 self
2347 }
2348 pub fn nth19(mut self, v: Byte) -> Self {
2349 self.0[19] = v;
2350 self
2351 }
2352 pub fn nth20(mut self, v: Byte) -> Self {
2353 self.0[20] = v;
2354 self
2355 }
2356 pub fn nth21(mut self, v: Byte) -> Self {
2357 self.0[21] = v;
2358 self
2359 }
2360 pub fn nth22(mut self, v: Byte) -> Self {
2361 self.0[22] = v;
2362 self
2363 }
2364 pub fn nth23(mut self, v: Byte) -> Self {
2365 self.0[23] = v;
2366 self
2367 }
2368 pub fn nth24(mut self, v: Byte) -> Self {
2369 self.0[24] = v;
2370 self
2371 }
2372 pub fn nth25(mut self, v: Byte) -> Self {
2373 self.0[25] = v;
2374 self
2375 }
2376 pub fn nth26(mut self, v: Byte) -> Self {
2377 self.0[26] = v;
2378 self
2379 }
2380 pub fn nth27(mut self, v: Byte) -> Self {
2381 self.0[27] = v;
2382 self
2383 }
2384 pub fn nth28(mut self, v: Byte) -> Self {
2385 self.0[28] = v;
2386 self
2387 }
2388 pub fn nth29(mut self, v: Byte) -> Self {
2389 self.0[29] = v;
2390 self
2391 }
2392 pub fn nth30(mut self, v: Byte) -> Self {
2393 self.0[30] = v;
2394 self
2395 }
2396 pub fn nth31(mut self, v: Byte) -> Self {
2397 self.0[31] = v;
2398 self
2399 }
2400 pub fn nth32(mut self, v: Byte) -> Self {
2401 self.0[32] = v;
2402 self
2403 }
2404 pub fn nth33(mut self, v: Byte) -> Self {
2405 self.0[33] = v;
2406 self
2407 }
2408 pub fn nth34(mut self, v: Byte) -> Self {
2409 self.0[34] = v;
2410 self
2411 }
2412 pub fn nth35(mut self, v: Byte) -> Self {
2413 self.0[35] = v;
2414 self
2415 }
2416 pub fn nth36(mut self, v: Byte) -> Self {
2417 self.0[36] = v;
2418 self
2419 }
2420 pub fn nth37(mut self, v: Byte) -> Self {
2421 self.0[37] = v;
2422 self
2423 }
2424 pub fn nth38(mut self, v: Byte) -> Self {
2425 self.0[38] = v;
2426 self
2427 }
2428 pub fn nth39(mut self, v: Byte) -> Self {
2429 self.0[39] = v;
2430 self
2431 }
2432 pub fn nth40(mut self, v: Byte) -> Self {
2433 self.0[40] = v;
2434 self
2435 }
2436 pub fn nth41(mut self, v: Byte) -> Self {
2437 self.0[41] = v;
2438 self
2439 }
2440 pub fn nth42(mut self, v: Byte) -> Self {
2441 self.0[42] = v;
2442 self
2443 }
2444 pub fn nth43(mut self, v: Byte) -> Self {
2445 self.0[43] = v;
2446 self
2447 }
2448 pub fn nth44(mut self, v: Byte) -> Self {
2449 self.0[44] = v;
2450 self
2451 }
2452}
2453impl molecule::prelude::Builder for CursorBuilder {
2454 type Entity = Cursor;
2455 const NAME: &'static str = "CursorBuilder";
2456 fn expected_length(&self) -> usize {
2457 Self::TOTAL_SIZE
2458 }
2459 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2460 writer.write_all(self.0[0].as_slice())?;
2461 writer.write_all(self.0[1].as_slice())?;
2462 writer.write_all(self.0[2].as_slice())?;
2463 writer.write_all(self.0[3].as_slice())?;
2464 writer.write_all(self.0[4].as_slice())?;
2465 writer.write_all(self.0[5].as_slice())?;
2466 writer.write_all(self.0[6].as_slice())?;
2467 writer.write_all(self.0[7].as_slice())?;
2468 writer.write_all(self.0[8].as_slice())?;
2469 writer.write_all(self.0[9].as_slice())?;
2470 writer.write_all(self.0[10].as_slice())?;
2471 writer.write_all(self.0[11].as_slice())?;
2472 writer.write_all(self.0[12].as_slice())?;
2473 writer.write_all(self.0[13].as_slice())?;
2474 writer.write_all(self.0[14].as_slice())?;
2475 writer.write_all(self.0[15].as_slice())?;
2476 writer.write_all(self.0[16].as_slice())?;
2477 writer.write_all(self.0[17].as_slice())?;
2478 writer.write_all(self.0[18].as_slice())?;
2479 writer.write_all(self.0[19].as_slice())?;
2480 writer.write_all(self.0[20].as_slice())?;
2481 writer.write_all(self.0[21].as_slice())?;
2482 writer.write_all(self.0[22].as_slice())?;
2483 writer.write_all(self.0[23].as_slice())?;
2484 writer.write_all(self.0[24].as_slice())?;
2485 writer.write_all(self.0[25].as_slice())?;
2486 writer.write_all(self.0[26].as_slice())?;
2487 writer.write_all(self.0[27].as_slice())?;
2488 writer.write_all(self.0[28].as_slice())?;
2489 writer.write_all(self.0[29].as_slice())?;
2490 writer.write_all(self.0[30].as_slice())?;
2491 writer.write_all(self.0[31].as_slice())?;
2492 writer.write_all(self.0[32].as_slice())?;
2493 writer.write_all(self.0[33].as_slice())?;
2494 writer.write_all(self.0[34].as_slice())?;
2495 writer.write_all(self.0[35].as_slice())?;
2496 writer.write_all(self.0[36].as_slice())?;
2497 writer.write_all(self.0[37].as_slice())?;
2498 writer.write_all(self.0[38].as_slice())?;
2499 writer.write_all(self.0[39].as_slice())?;
2500 writer.write_all(self.0[40].as_slice())?;
2501 writer.write_all(self.0[41].as_slice())?;
2502 writer.write_all(self.0[42].as_slice())?;
2503 writer.write_all(self.0[43].as_slice())?;
2504 writer.write_all(self.0[44].as_slice())?;
2505 Ok(())
2506 }
2507 fn build(&self) -> Self::Entity {
2508 let mut inner = Vec::with_capacity(self.expected_length());
2509 self.write(&mut inner)
2510 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2511 Cursor::new_unchecked(inner.into())
2512 }
2513}
2514impl From<[Byte; 45usize]> for Cursor {
2515 fn from(value: [Byte; 45usize]) -> Self {
2516 Self::new_builder().set(value).build()
2517 }
2518}
2519impl ::core::convert::TryFrom<&[Byte]> for Cursor {
2520 type Error = ::core::array::TryFromSliceError;
2521 fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
2522 Ok(Self::new_builder()
2523 .set(<&[Byte; 45usize]>::try_from(value)?.clone())
2524 .build())
2525 }
2526}
2527impl From<Cursor> for [Byte; 45usize] {
2528 #[track_caller]
2529 fn from(value: Cursor) -> Self {
2530 [
2531 value.nth0(),
2532 value.nth1(),
2533 value.nth2(),
2534 value.nth3(),
2535 value.nth4(),
2536 value.nth5(),
2537 value.nth6(),
2538 value.nth7(),
2539 value.nth8(),
2540 value.nth9(),
2541 value.nth10(),
2542 value.nth11(),
2543 value.nth12(),
2544 value.nth13(),
2545 value.nth14(),
2546 value.nth15(),
2547 value.nth16(),
2548 value.nth17(),
2549 value.nth18(),
2550 value.nth19(),
2551 value.nth20(),
2552 value.nth21(),
2553 value.nth22(),
2554 value.nth23(),
2555 value.nth24(),
2556 value.nth25(),
2557 value.nth26(),
2558 value.nth27(),
2559 value.nth28(),
2560 value.nth29(),
2561 value.nth30(),
2562 value.nth31(),
2563 value.nth32(),
2564 value.nth33(),
2565 value.nth34(),
2566 value.nth35(),
2567 value.nth36(),
2568 value.nth37(),
2569 value.nth38(),
2570 value.nth39(),
2571 value.nth40(),
2572 value.nth41(),
2573 value.nth42(),
2574 value.nth43(),
2575 value.nth44(),
2576 ]
2577 }
2578}
2579impl From<[u8; 45usize]> for Cursor {
2580 fn from(value: [u8; 45usize]) -> Self {
2581 CursorReader::new_unchecked(&value).to_entity()
2582 }
2583}
2584impl ::core::convert::TryFrom<&[u8]> for Cursor {
2585 type Error = ::core::array::TryFromSliceError;
2586 fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
2587 Ok(<[u8; 45usize]>::try_from(value)?.into())
2588 }
2589}
2590impl From<Cursor> for [u8; 45usize] {
2591 #[track_caller]
2592 fn from(value: Cursor) -> Self {
2593 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2594 }
2595}
2596impl<'a> From<CursorReader<'a>> for &'a [u8; 45usize] {
2597 #[track_caller]
2598 fn from(value: CursorReader<'a>) -> Self {
2599 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2600 }
2601}
2602impl<'a> From<&'a CursorReader<'a>> for &'a [u8; 45usize] {
2603 #[track_caller]
2604 fn from(value: &'a CursorReader<'a>) -> Self {
2605 ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2606 }
2607}
2608#[derive(Clone)]
2609pub struct BroadcastMessageQuery(molecule::bytes::Bytes);
2610impl ::core::fmt::LowerHex for BroadcastMessageQuery {
2611 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2612 use molecule::hex_string;
2613 if f.alternate() {
2614 write!(f, "0x")?;
2615 }
2616 write!(f, "{}", hex_string(self.as_slice()))
2617 }
2618}
2619impl ::core::fmt::Debug for BroadcastMessageQuery {
2620 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2621 write!(f, "{}({:#x})", Self::NAME, self)
2622 }
2623}
2624impl ::core::fmt::Display for BroadcastMessageQuery {
2625 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2626 write!(f, "{} {{ ", Self::NAME)?;
2627 write!(f, "{}: {}", "channel_outpoint", self.channel_outpoint())?;
2628 write!(f, ", {}: {}", "flags", self.flags())?;
2629 write!(f, " }}")
2630 }
2631}
2632impl ::core::default::Default for BroadcastMessageQuery {
2633 fn default() -> Self {
2634 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2635 BroadcastMessageQuery::new_unchecked(v)
2636 }
2637}
2638impl BroadcastMessageQuery {
2639 const DEFAULT_VALUE: [u8; 37] = [
2640 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2641 0, 0, 0, 0, 0, 0, 0,
2642 ];
2643 pub const TOTAL_SIZE: usize = 37;
2644 pub const FIELD_SIZES: [usize; 2] = [36, 1];
2645 pub const FIELD_COUNT: usize = 2;
2646 pub fn channel_outpoint(&self) -> OutPoint {
2647 OutPoint::new_unchecked(self.0.slice(0..36))
2648 }
2649 pub fn flags(&self) -> Byte {
2650 Byte::new_unchecked(self.0.slice(36..37))
2651 }
2652 pub fn as_reader<'r>(&'r self) -> BroadcastMessageQueryReader<'r> {
2653 BroadcastMessageQueryReader::new_unchecked(self.as_slice())
2654 }
2655}
2656impl molecule::prelude::Entity for BroadcastMessageQuery {
2657 type Builder = BroadcastMessageQueryBuilder;
2658 const NAME: &'static str = "BroadcastMessageQuery";
2659 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2660 BroadcastMessageQuery(data)
2661 }
2662 fn as_bytes(&self) -> molecule::bytes::Bytes {
2663 self.0.clone()
2664 }
2665 fn as_slice(&self) -> &[u8] {
2666 &self.0[..]
2667 }
2668 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2669 BroadcastMessageQueryReader::from_slice(slice).map(|reader| reader.to_entity())
2670 }
2671 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2672 BroadcastMessageQueryReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2673 }
2674 fn new_builder() -> Self::Builder {
2675 ::core::default::Default::default()
2676 }
2677 fn as_builder(self) -> Self::Builder {
2678 Self::new_builder()
2679 .channel_outpoint(self.channel_outpoint())
2680 .flags(self.flags())
2681 }
2682}
2683#[derive(Clone, Copy)]
2684pub struct BroadcastMessageQueryReader<'r>(&'r [u8]);
2685impl<'r> ::core::fmt::LowerHex for BroadcastMessageQueryReader<'r> {
2686 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2687 use molecule::hex_string;
2688 if f.alternate() {
2689 write!(f, "0x")?;
2690 }
2691 write!(f, "{}", hex_string(self.as_slice()))
2692 }
2693}
2694impl<'r> ::core::fmt::Debug for BroadcastMessageQueryReader<'r> {
2695 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2696 write!(f, "{}({:#x})", Self::NAME, self)
2697 }
2698}
2699impl<'r> ::core::fmt::Display for BroadcastMessageQueryReader<'r> {
2700 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2701 write!(f, "{} {{ ", Self::NAME)?;
2702 write!(f, "{}: {}", "channel_outpoint", self.channel_outpoint())?;
2703 write!(f, ", {}: {}", "flags", self.flags())?;
2704 write!(f, " }}")
2705 }
2706}
2707impl<'r> BroadcastMessageQueryReader<'r> {
2708 pub const TOTAL_SIZE: usize = 37;
2709 pub const FIELD_SIZES: [usize; 2] = [36, 1];
2710 pub const FIELD_COUNT: usize = 2;
2711 pub fn channel_outpoint(&self) -> OutPointReader<'r> {
2712 OutPointReader::new_unchecked(&self.as_slice()[0..36])
2713 }
2714 pub fn flags(&self) -> ByteReader<'r> {
2715 ByteReader::new_unchecked(&self.as_slice()[36..37])
2716 }
2717}
2718impl<'r> molecule::prelude::Reader<'r> for BroadcastMessageQueryReader<'r> {
2719 type Entity = BroadcastMessageQuery;
2720 const NAME: &'static str = "BroadcastMessageQueryReader";
2721 fn to_entity(&self) -> Self::Entity {
2722 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2723 }
2724 fn new_unchecked(slice: &'r [u8]) -> Self {
2725 BroadcastMessageQueryReader(slice)
2726 }
2727 fn as_slice(&self) -> &'r [u8] {
2728 self.0
2729 }
2730 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2731 use molecule::verification_error as ve;
2732 let slice_len = slice.len();
2733 if slice_len != Self::TOTAL_SIZE {
2734 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
2735 }
2736 Ok(())
2737 }
2738}
2739#[derive(Clone, Debug, Default)]
2740pub struct BroadcastMessageQueryBuilder {
2741 pub(crate) channel_outpoint: OutPoint,
2742 pub(crate) flags: Byte,
2743}
2744impl BroadcastMessageQueryBuilder {
2745 pub const TOTAL_SIZE: usize = 37;
2746 pub const FIELD_SIZES: [usize; 2] = [36, 1];
2747 pub const FIELD_COUNT: usize = 2;
2748 pub fn channel_outpoint(mut self, v: OutPoint) -> Self {
2749 self.channel_outpoint = v;
2750 self
2751 }
2752 pub fn flags(mut self, v: Byte) -> Self {
2753 self.flags = v;
2754 self
2755 }
2756}
2757impl molecule::prelude::Builder for BroadcastMessageQueryBuilder {
2758 type Entity = BroadcastMessageQuery;
2759 const NAME: &'static str = "BroadcastMessageQueryBuilder";
2760 fn expected_length(&self) -> usize {
2761 Self::TOTAL_SIZE
2762 }
2763 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2764 writer.write_all(self.channel_outpoint.as_slice())?;
2765 writer.write_all(self.flags.as_slice())?;
2766 Ok(())
2767 }
2768 fn build(&self) -> Self::Entity {
2769 let mut inner = Vec::with_capacity(self.expected_length());
2770 self.write(&mut inner)
2771 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2772 BroadcastMessageQuery::new_unchecked(inner.into())
2773 }
2774}
2775#[derive(Clone)]
2776pub struct BroadcastMessageQueries(molecule::bytes::Bytes);
2777impl ::core::fmt::LowerHex for BroadcastMessageQueries {
2778 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2779 use molecule::hex_string;
2780 if f.alternate() {
2781 write!(f, "0x")?;
2782 }
2783 write!(f, "{}", hex_string(self.as_slice()))
2784 }
2785}
2786impl ::core::fmt::Debug for BroadcastMessageQueries {
2787 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2788 write!(f, "{}({:#x})", Self::NAME, self)
2789 }
2790}
2791impl ::core::fmt::Display for BroadcastMessageQueries {
2792 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2793 write!(f, "{} [", Self::NAME)?;
2794 for i in 0..self.len() {
2795 if i == 0 {
2796 write!(f, "{}", self.get_unchecked(i))?;
2797 } else {
2798 write!(f, ", {}", self.get_unchecked(i))?;
2799 }
2800 }
2801 write!(f, "]")
2802 }
2803}
2804impl ::core::default::Default for BroadcastMessageQueries {
2805 fn default() -> Self {
2806 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2807 BroadcastMessageQueries::new_unchecked(v)
2808 }
2809}
2810impl BroadcastMessageQueries {
2811 const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0];
2812 pub const ITEM_SIZE: usize = 37;
2813 pub fn total_size(&self) -> usize {
2814 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count()
2815 }
2816 pub fn item_count(&self) -> usize {
2817 molecule::unpack_number(self.as_slice()) as usize
2818 }
2819 pub fn len(&self) -> usize {
2820 self.item_count()
2821 }
2822 pub fn is_empty(&self) -> bool {
2823 self.len() == 0
2824 }
2825 pub fn get(&self, idx: usize) -> Option<BroadcastMessageQuery> {
2826 if idx >= self.len() {
2827 None
2828 } else {
2829 Some(self.get_unchecked(idx))
2830 }
2831 }
2832 pub fn get_unchecked(&self, idx: usize) -> BroadcastMessageQuery {
2833 let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
2834 let end = start + Self::ITEM_SIZE;
2835 BroadcastMessageQuery::new_unchecked(self.0.slice(start..end))
2836 }
2837 pub fn as_reader<'r>(&'r self) -> BroadcastMessageQueriesReader<'r> {
2838 BroadcastMessageQueriesReader::new_unchecked(self.as_slice())
2839 }
2840}
2841impl molecule::prelude::Entity for BroadcastMessageQueries {
2842 type Builder = BroadcastMessageQueriesBuilder;
2843 const NAME: &'static str = "BroadcastMessageQueries";
2844 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2845 BroadcastMessageQueries(data)
2846 }
2847 fn as_bytes(&self) -> molecule::bytes::Bytes {
2848 self.0.clone()
2849 }
2850 fn as_slice(&self) -> &[u8] {
2851 &self.0[..]
2852 }
2853 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2854 BroadcastMessageQueriesReader::from_slice(slice).map(|reader| reader.to_entity())
2855 }
2856 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2857 BroadcastMessageQueriesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2858 }
2859 fn new_builder() -> Self::Builder {
2860 ::core::default::Default::default()
2861 }
2862 fn as_builder(self) -> Self::Builder {
2863 Self::new_builder().extend(self.into_iter())
2864 }
2865}
2866#[derive(Clone, Copy)]
2867pub struct BroadcastMessageQueriesReader<'r>(&'r [u8]);
2868impl<'r> ::core::fmt::LowerHex for BroadcastMessageQueriesReader<'r> {
2869 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2870 use molecule::hex_string;
2871 if f.alternate() {
2872 write!(f, "0x")?;
2873 }
2874 write!(f, "{}", hex_string(self.as_slice()))
2875 }
2876}
2877impl<'r> ::core::fmt::Debug for BroadcastMessageQueriesReader<'r> {
2878 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2879 write!(f, "{}({:#x})", Self::NAME, self)
2880 }
2881}
2882impl<'r> ::core::fmt::Display for BroadcastMessageQueriesReader<'r> {
2883 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2884 write!(f, "{} [", Self::NAME)?;
2885 for i in 0..self.len() {
2886 if i == 0 {
2887 write!(f, "{}", self.get_unchecked(i))?;
2888 } else {
2889 write!(f, ", {}", self.get_unchecked(i))?;
2890 }
2891 }
2892 write!(f, "]")
2893 }
2894}
2895impl<'r> BroadcastMessageQueriesReader<'r> {
2896 pub const ITEM_SIZE: usize = 37;
2897 pub fn total_size(&self) -> usize {
2898 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count()
2899 }
2900 pub fn item_count(&self) -> usize {
2901 molecule::unpack_number(self.as_slice()) as usize
2902 }
2903 pub fn len(&self) -> usize {
2904 self.item_count()
2905 }
2906 pub fn is_empty(&self) -> bool {
2907 self.len() == 0
2908 }
2909 pub fn get(&self, idx: usize) -> Option<BroadcastMessageQueryReader<'r>> {
2910 if idx >= self.len() {
2911 None
2912 } else {
2913 Some(self.get_unchecked(idx))
2914 }
2915 }
2916 pub fn get_unchecked(&self, idx: usize) -> BroadcastMessageQueryReader<'r> {
2917 let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
2918 let end = start + Self::ITEM_SIZE;
2919 BroadcastMessageQueryReader::new_unchecked(&self.as_slice()[start..end])
2920 }
2921}
2922impl<'r> molecule::prelude::Reader<'r> for BroadcastMessageQueriesReader<'r> {
2923 type Entity = BroadcastMessageQueries;
2924 const NAME: &'static str = "BroadcastMessageQueriesReader";
2925 fn to_entity(&self) -> Self::Entity {
2926 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2927 }
2928 fn new_unchecked(slice: &'r [u8]) -> Self {
2929 BroadcastMessageQueriesReader(slice)
2930 }
2931 fn as_slice(&self) -> &'r [u8] {
2932 self.0
2933 }
2934 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2935 use molecule::verification_error as ve;
2936 let slice_len = slice.len();
2937 if slice_len < molecule::NUMBER_SIZE {
2938 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
2939 }
2940 let item_count = molecule::unpack_number(slice) as usize;
2941 if item_count == 0 {
2942 if slice_len != molecule::NUMBER_SIZE {
2943 return ve!(Self, TotalSizeNotMatch, molecule::NUMBER_SIZE, slice_len);
2944 }
2945 return Ok(());
2946 }
2947 let total_size = molecule::NUMBER_SIZE + Self::ITEM_SIZE * item_count;
2948 if slice_len != total_size {
2949 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
2950 }
2951 Ok(())
2952 }
2953}
2954#[derive(Clone, Debug, Default)]
2955pub struct BroadcastMessageQueriesBuilder(pub(crate) Vec<BroadcastMessageQuery>);
2956impl BroadcastMessageQueriesBuilder {
2957 pub const ITEM_SIZE: usize = 37;
2958 pub fn set(mut self, v: Vec<BroadcastMessageQuery>) -> Self {
2959 self.0 = v;
2960 self
2961 }
2962 pub fn push(mut self, v: BroadcastMessageQuery) -> Self {
2963 self.0.push(v);
2964 self
2965 }
2966 pub fn extend<T: ::core::iter::IntoIterator<Item = BroadcastMessageQuery>>(
2967 mut self,
2968 iter: T,
2969 ) -> Self {
2970 for elem in iter {
2971 self.0.push(elem);
2972 }
2973 self
2974 }
2975 pub fn replace(
2976 &mut self,
2977 index: usize,
2978 v: BroadcastMessageQuery,
2979 ) -> Option<BroadcastMessageQuery> {
2980 self.0
2981 .get_mut(index)
2982 .map(|item| ::core::mem::replace(item, v))
2983 }
2984}
2985impl molecule::prelude::Builder for BroadcastMessageQueriesBuilder {
2986 type Entity = BroadcastMessageQueries;
2987 const NAME: &'static str = "BroadcastMessageQueriesBuilder";
2988 fn expected_length(&self) -> usize {
2989 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len()
2990 }
2991 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2992 writer.write_all(&molecule::pack_number(self.0.len() as molecule::Number))?;
2993 for inner in &self.0[..] {
2994 writer.write_all(inner.as_slice())?;
2995 }
2996 Ok(())
2997 }
2998 fn build(&self) -> Self::Entity {
2999 let mut inner = Vec::with_capacity(self.expected_length());
3000 self.write(&mut inner)
3001 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3002 BroadcastMessageQueries::new_unchecked(inner.into())
3003 }
3004}
3005pub struct BroadcastMessageQueriesIterator(BroadcastMessageQueries, usize, usize);
3006impl ::core::iter::Iterator for BroadcastMessageQueriesIterator {
3007 type Item = BroadcastMessageQuery;
3008 fn next(&mut self) -> Option<Self::Item> {
3009 if self.1 >= self.2 {
3010 None
3011 } else {
3012 let ret = self.0.get_unchecked(self.1);
3013 self.1 += 1;
3014 Some(ret)
3015 }
3016 }
3017}
3018impl ::core::iter::ExactSizeIterator for BroadcastMessageQueriesIterator {
3019 fn len(&self) -> usize {
3020 self.2 - self.1
3021 }
3022}
3023impl ::core::iter::IntoIterator for BroadcastMessageQueries {
3024 type Item = BroadcastMessageQuery;
3025 type IntoIter = BroadcastMessageQueriesIterator;
3026 fn into_iter(self) -> Self::IntoIter {
3027 let len = self.len();
3028 BroadcastMessageQueriesIterator(self, 0, len)
3029 }
3030}
3031impl<'r> BroadcastMessageQueriesReader<'r> {
3032 pub fn iter<'t>(&'t self) -> BroadcastMessageQueriesReaderIterator<'t, 'r> {
3033 BroadcastMessageQueriesReaderIterator(&self, 0, self.len())
3034 }
3035}
3036pub struct BroadcastMessageQueriesReaderIterator<'t, 'r>(
3037 &'t BroadcastMessageQueriesReader<'r>,
3038 usize,
3039 usize,
3040);
3041impl<'t: 'r, 'r> ::core::iter::Iterator for BroadcastMessageQueriesReaderIterator<'t, 'r> {
3042 type Item = BroadcastMessageQueryReader<'t>;
3043 fn next(&mut self) -> Option<Self::Item> {
3044 if self.1 >= self.2 {
3045 None
3046 } else {
3047 let ret = self.0.get_unchecked(self.1);
3048 self.1 += 1;
3049 Some(ret)
3050 }
3051 }
3052}
3053impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for BroadcastMessageQueriesReaderIterator<'t, 'r> {
3054 fn len(&self) -> usize {
3055 self.2 - self.1
3056 }
3057}
3058impl ::core::iter::FromIterator<BroadcastMessageQuery> for BroadcastMessageQueries {
3059 fn from_iter<T: IntoIterator<Item = BroadcastMessageQuery>>(iter: T) -> Self {
3060 Self::new_builder().extend(iter).build()
3061 }
3062}
3063#[derive(Clone)]
3064pub struct NodeAnnouncement(molecule::bytes::Bytes);
3065impl ::core::fmt::LowerHex for NodeAnnouncement {
3066 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3067 use molecule::hex_string;
3068 if f.alternate() {
3069 write!(f, "0x")?;
3070 }
3071 write!(f, "{}", hex_string(self.as_slice()))
3072 }
3073}
3074impl ::core::fmt::Debug for NodeAnnouncement {
3075 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3076 write!(f, "{}({:#x})", Self::NAME, self)
3077 }
3078}
3079impl ::core::fmt::Display for NodeAnnouncement {
3080 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3081 write!(f, "{} {{ ", Self::NAME)?;
3082 write!(f, "{}: {}", "signature", self.signature())?;
3083 write!(f, ", {}: {}", "features", self.features())?;
3084 write!(f, ", {}: {}", "timestamp", self.timestamp())?;
3085 write!(f, ", {}: {}", "node_id", self.node_id())?;
3086 write!(f, ", {}: {}", "version", self.version())?;
3087 write!(f, ", {}: {}", "node_name", self.node_name())?;
3088 write!(f, ", {}: {}", "address", self.address())?;
3089 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
3090 write!(
3091 f,
3092 ", {}: {}",
3093 "auto_accept_min_ckb_funding_amount",
3094 self.auto_accept_min_ckb_funding_amount()
3095 )?;
3096 write!(f, ", {}: {}", "udt_cfg_infos", self.udt_cfg_infos())?;
3097 let extra_count = self.count_extra_fields();
3098 if extra_count != 0 {
3099 write!(f, ", .. ({} fields)", extra_count)?;
3100 }
3101 write!(f, " }}")
3102 }
3103}
3104impl ::core::default::Default for NodeAnnouncement {
3105 fn default() -> Self {
3106 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3107 NodeAnnouncement::new_unchecked(v)
3108 }
3109}
3110impl NodeAnnouncement {
3111 const DEFAULT_VALUE: [u8; 237] = [
3112 237, 0, 0, 0, 44, 0, 0, 0, 108, 0, 0, 0, 112, 0, 0, 0, 120, 0, 0, 0, 153, 0, 0, 0, 157, 0,
3113 0, 0, 189, 0, 0, 0, 193, 0, 0, 0, 225, 0, 0, 0, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4,
3120 0, 0, 0,
3121 ];
3122 pub const FIELD_COUNT: usize = 10;
3123 pub fn total_size(&self) -> usize {
3124 molecule::unpack_number(self.as_slice()) as usize
3125 }
3126 pub fn field_count(&self) -> usize {
3127 if self.total_size() == molecule::NUMBER_SIZE {
3128 0
3129 } else {
3130 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3131 }
3132 }
3133 pub fn count_extra_fields(&self) -> usize {
3134 self.field_count() - Self::FIELD_COUNT
3135 }
3136 pub fn has_extra_fields(&self) -> bool {
3137 Self::FIELD_COUNT != self.field_count()
3138 }
3139 pub fn signature(&self) -> EcdsaSignature {
3140 let slice = self.as_slice();
3141 let start = molecule::unpack_number(&slice[4..]) as usize;
3142 let end = molecule::unpack_number(&slice[8..]) as usize;
3143 EcdsaSignature::new_unchecked(self.0.slice(start..end))
3144 }
3145 pub fn features(&self) -> Bytes {
3146 let slice = self.as_slice();
3147 let start = molecule::unpack_number(&slice[8..]) as usize;
3148 let end = molecule::unpack_number(&slice[12..]) as usize;
3149 Bytes::new_unchecked(self.0.slice(start..end))
3150 }
3151 pub fn timestamp(&self) -> Uint64 {
3152 let slice = self.as_slice();
3153 let start = molecule::unpack_number(&slice[12..]) as usize;
3154 let end = molecule::unpack_number(&slice[16..]) as usize;
3155 Uint64::new_unchecked(self.0.slice(start..end))
3156 }
3157 pub fn node_id(&self) -> Pubkey {
3158 let slice = self.as_slice();
3159 let start = molecule::unpack_number(&slice[16..]) as usize;
3160 let end = molecule::unpack_number(&slice[20..]) as usize;
3161 Pubkey::new_unchecked(self.0.slice(start..end))
3162 }
3163 pub fn version(&self) -> Bytes {
3164 let slice = self.as_slice();
3165 let start = molecule::unpack_number(&slice[20..]) as usize;
3166 let end = molecule::unpack_number(&slice[24..]) as usize;
3167 Bytes::new_unchecked(self.0.slice(start..end))
3168 }
3169 pub fn node_name(&self) -> Byte32 {
3170 let slice = self.as_slice();
3171 let start = molecule::unpack_number(&slice[24..]) as usize;
3172 let end = molecule::unpack_number(&slice[28..]) as usize;
3173 Byte32::new_unchecked(self.0.slice(start..end))
3174 }
3175 pub fn address(&self) -> BytesVec {
3176 let slice = self.as_slice();
3177 let start = molecule::unpack_number(&slice[28..]) as usize;
3178 let end = molecule::unpack_number(&slice[32..]) as usize;
3179 BytesVec::new_unchecked(self.0.slice(start..end))
3180 }
3181 pub fn chain_hash(&self) -> Byte32 {
3182 let slice = self.as_slice();
3183 let start = molecule::unpack_number(&slice[32..]) as usize;
3184 let end = molecule::unpack_number(&slice[36..]) as usize;
3185 Byte32::new_unchecked(self.0.slice(start..end))
3186 }
3187 pub fn auto_accept_min_ckb_funding_amount(&self) -> Uint64 {
3188 let slice = self.as_slice();
3189 let start = molecule::unpack_number(&slice[36..]) as usize;
3190 let end = molecule::unpack_number(&slice[40..]) as usize;
3191 Uint64::new_unchecked(self.0.slice(start..end))
3192 }
3193 pub fn udt_cfg_infos(&self) -> UdtCfgInfos {
3194 let slice = self.as_slice();
3195 let start = molecule::unpack_number(&slice[40..]) as usize;
3196 if self.has_extra_fields() {
3197 let end = molecule::unpack_number(&slice[44..]) as usize;
3198 UdtCfgInfos::new_unchecked(self.0.slice(start..end))
3199 } else {
3200 UdtCfgInfos::new_unchecked(self.0.slice(start..))
3201 }
3202 }
3203 pub fn as_reader<'r>(&'r self) -> NodeAnnouncementReader<'r> {
3204 NodeAnnouncementReader::new_unchecked(self.as_slice())
3205 }
3206}
3207impl molecule::prelude::Entity for NodeAnnouncement {
3208 type Builder = NodeAnnouncementBuilder;
3209 const NAME: &'static str = "NodeAnnouncement";
3210 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3211 NodeAnnouncement(data)
3212 }
3213 fn as_bytes(&self) -> molecule::bytes::Bytes {
3214 self.0.clone()
3215 }
3216 fn as_slice(&self) -> &[u8] {
3217 &self.0[..]
3218 }
3219 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3220 NodeAnnouncementReader::from_slice(slice).map(|reader| reader.to_entity())
3221 }
3222 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3223 NodeAnnouncementReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3224 }
3225 fn new_builder() -> Self::Builder {
3226 ::core::default::Default::default()
3227 }
3228 fn as_builder(self) -> Self::Builder {
3229 Self::new_builder()
3230 .signature(self.signature())
3231 .features(self.features())
3232 .timestamp(self.timestamp())
3233 .node_id(self.node_id())
3234 .version(self.version())
3235 .node_name(self.node_name())
3236 .address(self.address())
3237 .chain_hash(self.chain_hash())
3238 .auto_accept_min_ckb_funding_amount(self.auto_accept_min_ckb_funding_amount())
3239 .udt_cfg_infos(self.udt_cfg_infos())
3240 }
3241}
3242#[derive(Clone, Copy)]
3243pub struct NodeAnnouncementReader<'r>(&'r [u8]);
3244impl<'r> ::core::fmt::LowerHex for NodeAnnouncementReader<'r> {
3245 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3246 use molecule::hex_string;
3247 if f.alternate() {
3248 write!(f, "0x")?;
3249 }
3250 write!(f, "{}", hex_string(self.as_slice()))
3251 }
3252}
3253impl<'r> ::core::fmt::Debug for NodeAnnouncementReader<'r> {
3254 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3255 write!(f, "{}({:#x})", Self::NAME, self)
3256 }
3257}
3258impl<'r> ::core::fmt::Display for NodeAnnouncementReader<'r> {
3259 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3260 write!(f, "{} {{ ", Self::NAME)?;
3261 write!(f, "{}: {}", "signature", self.signature())?;
3262 write!(f, ", {}: {}", "features", self.features())?;
3263 write!(f, ", {}: {}", "timestamp", self.timestamp())?;
3264 write!(f, ", {}: {}", "node_id", self.node_id())?;
3265 write!(f, ", {}: {}", "version", self.version())?;
3266 write!(f, ", {}: {}", "node_name", self.node_name())?;
3267 write!(f, ", {}: {}", "address", self.address())?;
3268 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
3269 write!(
3270 f,
3271 ", {}: {}",
3272 "auto_accept_min_ckb_funding_amount",
3273 self.auto_accept_min_ckb_funding_amount()
3274 )?;
3275 write!(f, ", {}: {}", "udt_cfg_infos", self.udt_cfg_infos())?;
3276 let extra_count = self.count_extra_fields();
3277 if extra_count != 0 {
3278 write!(f, ", .. ({} fields)", extra_count)?;
3279 }
3280 write!(f, " }}")
3281 }
3282}
3283impl<'r> NodeAnnouncementReader<'r> {
3284 pub const FIELD_COUNT: usize = 10;
3285 pub fn total_size(&self) -> usize {
3286 molecule::unpack_number(self.as_slice()) as usize
3287 }
3288 pub fn field_count(&self) -> usize {
3289 if self.total_size() == molecule::NUMBER_SIZE {
3290 0
3291 } else {
3292 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3293 }
3294 }
3295 pub fn count_extra_fields(&self) -> usize {
3296 self.field_count() - Self::FIELD_COUNT
3297 }
3298 pub fn has_extra_fields(&self) -> bool {
3299 Self::FIELD_COUNT != self.field_count()
3300 }
3301 pub fn signature(&self) -> EcdsaSignatureReader<'r> {
3302 let slice = self.as_slice();
3303 let start = molecule::unpack_number(&slice[4..]) as usize;
3304 let end = molecule::unpack_number(&slice[8..]) as usize;
3305 EcdsaSignatureReader::new_unchecked(&self.as_slice()[start..end])
3306 }
3307 pub fn features(&self) -> BytesReader<'r> {
3308 let slice = self.as_slice();
3309 let start = molecule::unpack_number(&slice[8..]) as usize;
3310 let end = molecule::unpack_number(&slice[12..]) as usize;
3311 BytesReader::new_unchecked(&self.as_slice()[start..end])
3312 }
3313 pub fn timestamp(&self) -> Uint64Reader<'r> {
3314 let slice = self.as_slice();
3315 let start = molecule::unpack_number(&slice[12..]) as usize;
3316 let end = molecule::unpack_number(&slice[16..]) as usize;
3317 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
3318 }
3319 pub fn node_id(&self) -> PubkeyReader<'r> {
3320 let slice = self.as_slice();
3321 let start = molecule::unpack_number(&slice[16..]) as usize;
3322 let end = molecule::unpack_number(&slice[20..]) as usize;
3323 PubkeyReader::new_unchecked(&self.as_slice()[start..end])
3324 }
3325 pub fn version(&self) -> BytesReader<'r> {
3326 let slice = self.as_slice();
3327 let start = molecule::unpack_number(&slice[20..]) as usize;
3328 let end = molecule::unpack_number(&slice[24..]) as usize;
3329 BytesReader::new_unchecked(&self.as_slice()[start..end])
3330 }
3331 pub fn node_name(&self) -> Byte32Reader<'r> {
3332 let slice = self.as_slice();
3333 let start = molecule::unpack_number(&slice[24..]) as usize;
3334 let end = molecule::unpack_number(&slice[28..]) as usize;
3335 Byte32Reader::new_unchecked(&self.as_slice()[start..end])
3336 }
3337 pub fn address(&self) -> BytesVecReader<'r> {
3338 let slice = self.as_slice();
3339 let start = molecule::unpack_number(&slice[28..]) as usize;
3340 let end = molecule::unpack_number(&slice[32..]) as usize;
3341 BytesVecReader::new_unchecked(&self.as_slice()[start..end])
3342 }
3343 pub fn chain_hash(&self) -> Byte32Reader<'r> {
3344 let slice = self.as_slice();
3345 let start = molecule::unpack_number(&slice[32..]) as usize;
3346 let end = molecule::unpack_number(&slice[36..]) as usize;
3347 Byte32Reader::new_unchecked(&self.as_slice()[start..end])
3348 }
3349 pub fn auto_accept_min_ckb_funding_amount(&self) -> Uint64Reader<'r> {
3350 let slice = self.as_slice();
3351 let start = molecule::unpack_number(&slice[36..]) as usize;
3352 let end = molecule::unpack_number(&slice[40..]) as usize;
3353 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
3354 }
3355 pub fn udt_cfg_infos(&self) -> UdtCfgInfosReader<'r> {
3356 let slice = self.as_slice();
3357 let start = molecule::unpack_number(&slice[40..]) as usize;
3358 if self.has_extra_fields() {
3359 let end = molecule::unpack_number(&slice[44..]) as usize;
3360 UdtCfgInfosReader::new_unchecked(&self.as_slice()[start..end])
3361 } else {
3362 UdtCfgInfosReader::new_unchecked(&self.as_slice()[start..])
3363 }
3364 }
3365}
3366impl<'r> molecule::prelude::Reader<'r> for NodeAnnouncementReader<'r> {
3367 type Entity = NodeAnnouncement;
3368 const NAME: &'static str = "NodeAnnouncementReader";
3369 fn to_entity(&self) -> Self::Entity {
3370 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3371 }
3372 fn new_unchecked(slice: &'r [u8]) -> Self {
3373 NodeAnnouncementReader(slice)
3374 }
3375 fn as_slice(&self) -> &'r [u8] {
3376 self.0
3377 }
3378 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3379 use molecule::verification_error as ve;
3380 let slice_len = slice.len();
3381 if slice_len < molecule::NUMBER_SIZE {
3382 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3383 }
3384 let total_size = molecule::unpack_number(slice) as usize;
3385 if slice_len != total_size {
3386 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3387 }
3388 if slice_len < molecule::NUMBER_SIZE * 2 {
3389 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3390 }
3391 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3392 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3393 return ve!(Self, OffsetsNotMatch);
3394 }
3395 if slice_len < offset_first {
3396 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3397 }
3398 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3399 if field_count < Self::FIELD_COUNT {
3400 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3401 } else if !compatible && field_count > Self::FIELD_COUNT {
3402 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3403 };
3404 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
3405 .chunks_exact(molecule::NUMBER_SIZE)
3406 .map(|x| molecule::unpack_number(x) as usize)
3407 .collect();
3408 offsets.push(total_size);
3409 if offsets.windows(2).any(|i| i[0] > i[1]) {
3410 return ve!(Self, OffsetsNotMatch);
3411 }
3412 EcdsaSignatureReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
3413 BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
3414 Uint64Reader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
3415 PubkeyReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
3416 BytesReader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
3417 Byte32Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
3418 BytesVecReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
3419 Byte32Reader::verify(&slice[offsets[7]..offsets[8]], compatible)?;
3420 Uint64Reader::verify(&slice[offsets[8]..offsets[9]], compatible)?;
3421 UdtCfgInfosReader::verify(&slice[offsets[9]..offsets[10]], compatible)?;
3422 Ok(())
3423 }
3424}
3425#[derive(Clone, Debug, Default)]
3426pub struct NodeAnnouncementBuilder {
3427 pub(crate) signature: EcdsaSignature,
3428 pub(crate) features: Bytes,
3429 pub(crate) timestamp: Uint64,
3430 pub(crate) node_id: Pubkey,
3431 pub(crate) version: Bytes,
3432 pub(crate) node_name: Byte32,
3433 pub(crate) address: BytesVec,
3434 pub(crate) chain_hash: Byte32,
3435 pub(crate) auto_accept_min_ckb_funding_amount: Uint64,
3436 pub(crate) udt_cfg_infos: UdtCfgInfos,
3437}
3438impl NodeAnnouncementBuilder {
3439 pub const FIELD_COUNT: usize = 10;
3440 pub fn signature(mut self, v: EcdsaSignature) -> Self {
3441 self.signature = v;
3442 self
3443 }
3444 pub fn features(mut self, v: Bytes) -> Self {
3445 self.features = v;
3446 self
3447 }
3448 pub fn timestamp(mut self, v: Uint64) -> Self {
3449 self.timestamp = v;
3450 self
3451 }
3452 pub fn node_id(mut self, v: Pubkey) -> Self {
3453 self.node_id = v;
3454 self
3455 }
3456 pub fn version(mut self, v: Bytes) -> Self {
3457 self.version = v;
3458 self
3459 }
3460 pub fn node_name(mut self, v: Byte32) -> Self {
3461 self.node_name = v;
3462 self
3463 }
3464 pub fn address(mut self, v: BytesVec) -> Self {
3465 self.address = v;
3466 self
3467 }
3468 pub fn chain_hash(mut self, v: Byte32) -> Self {
3469 self.chain_hash = v;
3470 self
3471 }
3472 pub fn auto_accept_min_ckb_funding_amount(mut self, v: Uint64) -> Self {
3473 self.auto_accept_min_ckb_funding_amount = v;
3474 self
3475 }
3476 pub fn udt_cfg_infos(mut self, v: UdtCfgInfos) -> Self {
3477 self.udt_cfg_infos = v;
3478 self
3479 }
3480}
3481impl molecule::prelude::Builder for NodeAnnouncementBuilder {
3482 type Entity = NodeAnnouncement;
3483 const NAME: &'static str = "NodeAnnouncementBuilder";
3484 fn expected_length(&self) -> usize {
3485 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
3486 + self.signature.as_slice().len()
3487 + self.features.as_slice().len()
3488 + self.timestamp.as_slice().len()
3489 + self.node_id.as_slice().len()
3490 + self.version.as_slice().len()
3491 + self.node_name.as_slice().len()
3492 + self.address.as_slice().len()
3493 + self.chain_hash.as_slice().len()
3494 + self.auto_accept_min_ckb_funding_amount.as_slice().len()
3495 + self.udt_cfg_infos.as_slice().len()
3496 }
3497 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3498 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
3499 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
3500 offsets.push(total_size);
3501 total_size += self.signature.as_slice().len();
3502 offsets.push(total_size);
3503 total_size += self.features.as_slice().len();
3504 offsets.push(total_size);
3505 total_size += self.timestamp.as_slice().len();
3506 offsets.push(total_size);
3507 total_size += self.node_id.as_slice().len();
3508 offsets.push(total_size);
3509 total_size += self.version.as_slice().len();
3510 offsets.push(total_size);
3511 total_size += self.node_name.as_slice().len();
3512 offsets.push(total_size);
3513 total_size += self.address.as_slice().len();
3514 offsets.push(total_size);
3515 total_size += self.chain_hash.as_slice().len();
3516 offsets.push(total_size);
3517 total_size += self.auto_accept_min_ckb_funding_amount.as_slice().len();
3518 offsets.push(total_size);
3519 total_size += self.udt_cfg_infos.as_slice().len();
3520 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
3521 for offset in offsets.into_iter() {
3522 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
3523 }
3524 writer.write_all(self.signature.as_slice())?;
3525 writer.write_all(self.features.as_slice())?;
3526 writer.write_all(self.timestamp.as_slice())?;
3527 writer.write_all(self.node_id.as_slice())?;
3528 writer.write_all(self.version.as_slice())?;
3529 writer.write_all(self.node_name.as_slice())?;
3530 writer.write_all(self.address.as_slice())?;
3531 writer.write_all(self.chain_hash.as_slice())?;
3532 writer.write_all(self.auto_accept_min_ckb_funding_amount.as_slice())?;
3533 writer.write_all(self.udt_cfg_infos.as_slice())?;
3534 Ok(())
3535 }
3536 fn build(&self) -> Self::Entity {
3537 let mut inner = Vec::with_capacity(self.expected_length());
3538 self.write(&mut inner)
3539 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3540 NodeAnnouncement::new_unchecked(inner.into())
3541 }
3542}
3543#[derive(Clone)]
3544pub struct ChannelAnnouncement(molecule::bytes::Bytes);
3545impl ::core::fmt::LowerHex for ChannelAnnouncement {
3546 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3547 use molecule::hex_string;
3548 if f.alternate() {
3549 write!(f, "0x")?;
3550 }
3551 write!(f, "{}", hex_string(self.as_slice()))
3552 }
3553}
3554impl ::core::fmt::Debug for ChannelAnnouncement {
3555 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3556 write!(f, "{}({:#x})", Self::NAME, self)
3557 }
3558}
3559impl ::core::fmt::Display for ChannelAnnouncement {
3560 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3561 write!(f, "{} {{ ", Self::NAME)?;
3562 write!(f, "{}: {}", "node1_signature", self.node1_signature())?;
3563 write!(f, ", {}: {}", "node2_signature", self.node2_signature())?;
3564 write!(f, ", {}: {}", "ckb_signature", self.ckb_signature())?;
3565 write!(f, ", {}: {}", "features", self.features())?;
3566 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
3567 write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
3568 write!(f, ", {}: {}", "node1_id", self.node1_id())?;
3569 write!(f, ", {}: {}", "node2_id", self.node2_id())?;
3570 write!(f, ", {}: {}", "ckb_key", self.ckb_key())?;
3571 write!(f, ", {}: {}", "capacity", self.capacity())?;
3572 write!(f, ", {}: {}", "udt_type_script", self.udt_type_script())?;
3573 let extra_count = self.count_extra_fields();
3574 if extra_count != 0 {
3575 write!(f, ", .. ({} fields)", extra_count)?;
3576 }
3577 write!(f, " }}")
3578 }
3579}
3580impl ::core::default::Default for ChannelAnnouncement {
3581 fn default() -> Self {
3582 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3583 ChannelAnnouncement::new_unchecked(v)
3584 }
3585}
3586impl ChannelAnnouncement {
3587 const DEFAULT_VALUE: [u8; 430] = [
3588 174, 1, 0, 0, 48, 0, 0, 0, 112, 0, 0, 0, 176, 0, 0, 0, 240, 0, 0, 0, 248, 0, 0, 0, 24, 1,
3589 0, 0, 60, 1, 0, 0, 93, 1, 0, 0, 126, 1, 0, 0, 158, 1, 0, 0, 174, 1, 0, 0, 0, 0, 0, 0, 0, 0,
3590 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3591 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3592 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3593 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3594 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3595 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3596 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3597 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3598 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3599 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3600 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3601 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3602 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3603 ];
3604 pub const FIELD_COUNT: usize = 11;
3605 pub fn total_size(&self) -> usize {
3606 molecule::unpack_number(self.as_slice()) as usize
3607 }
3608 pub fn field_count(&self) -> usize {
3609 if self.total_size() == molecule::NUMBER_SIZE {
3610 0
3611 } else {
3612 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3613 }
3614 }
3615 pub fn count_extra_fields(&self) -> usize {
3616 self.field_count() - Self::FIELD_COUNT
3617 }
3618 pub fn has_extra_fields(&self) -> bool {
3619 Self::FIELD_COUNT != self.field_count()
3620 }
3621 pub fn node1_signature(&self) -> EcdsaSignature {
3622 let slice = self.as_slice();
3623 let start = molecule::unpack_number(&slice[4..]) as usize;
3624 let end = molecule::unpack_number(&slice[8..]) as usize;
3625 EcdsaSignature::new_unchecked(self.0.slice(start..end))
3626 }
3627 pub fn node2_signature(&self) -> EcdsaSignature {
3628 let slice = self.as_slice();
3629 let start = molecule::unpack_number(&slice[8..]) as usize;
3630 let end = molecule::unpack_number(&slice[12..]) as usize;
3631 EcdsaSignature::new_unchecked(self.0.slice(start..end))
3632 }
3633 pub fn ckb_signature(&self) -> SchnorrSignature {
3634 let slice = self.as_slice();
3635 let start = molecule::unpack_number(&slice[12..]) as usize;
3636 let end = molecule::unpack_number(&slice[16..]) as usize;
3637 SchnorrSignature::new_unchecked(self.0.slice(start..end))
3638 }
3639 pub fn features(&self) -> Uint64 {
3640 let slice = self.as_slice();
3641 let start = molecule::unpack_number(&slice[16..]) as usize;
3642 let end = molecule::unpack_number(&slice[20..]) as usize;
3643 Uint64::new_unchecked(self.0.slice(start..end))
3644 }
3645 pub fn chain_hash(&self) -> Byte32 {
3646 let slice = self.as_slice();
3647 let start = molecule::unpack_number(&slice[20..]) as usize;
3648 let end = molecule::unpack_number(&slice[24..]) as usize;
3649 Byte32::new_unchecked(self.0.slice(start..end))
3650 }
3651 pub fn channel_outpoint(&self) -> OutPoint {
3652 let slice = self.as_slice();
3653 let start = molecule::unpack_number(&slice[24..]) as usize;
3654 let end = molecule::unpack_number(&slice[28..]) as usize;
3655 OutPoint::new_unchecked(self.0.slice(start..end))
3656 }
3657 pub fn node1_id(&self) -> Pubkey {
3658 let slice = self.as_slice();
3659 let start = molecule::unpack_number(&slice[28..]) as usize;
3660 let end = molecule::unpack_number(&slice[32..]) as usize;
3661 Pubkey::new_unchecked(self.0.slice(start..end))
3662 }
3663 pub fn node2_id(&self) -> Pubkey {
3664 let slice = self.as_slice();
3665 let start = molecule::unpack_number(&slice[32..]) as usize;
3666 let end = molecule::unpack_number(&slice[36..]) as usize;
3667 Pubkey::new_unchecked(self.0.slice(start..end))
3668 }
3669 pub fn ckb_key(&self) -> SchnorrXOnlyPubkey {
3670 let slice = self.as_slice();
3671 let start = molecule::unpack_number(&slice[36..]) as usize;
3672 let end = molecule::unpack_number(&slice[40..]) as usize;
3673 SchnorrXOnlyPubkey::new_unchecked(self.0.slice(start..end))
3674 }
3675 pub fn capacity(&self) -> Uint128 {
3676 let slice = self.as_slice();
3677 let start = molecule::unpack_number(&slice[40..]) as usize;
3678 let end = molecule::unpack_number(&slice[44..]) as usize;
3679 Uint128::new_unchecked(self.0.slice(start..end))
3680 }
3681 pub fn udt_type_script(&self) -> ScriptOpt {
3682 let slice = self.as_slice();
3683 let start = molecule::unpack_number(&slice[44..]) as usize;
3684 if self.has_extra_fields() {
3685 let end = molecule::unpack_number(&slice[48..]) as usize;
3686 ScriptOpt::new_unchecked(self.0.slice(start..end))
3687 } else {
3688 ScriptOpt::new_unchecked(self.0.slice(start..))
3689 }
3690 }
3691 pub fn as_reader<'r>(&'r self) -> ChannelAnnouncementReader<'r> {
3692 ChannelAnnouncementReader::new_unchecked(self.as_slice())
3693 }
3694}
3695impl molecule::prelude::Entity for ChannelAnnouncement {
3696 type Builder = ChannelAnnouncementBuilder;
3697 const NAME: &'static str = "ChannelAnnouncement";
3698 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3699 ChannelAnnouncement(data)
3700 }
3701 fn as_bytes(&self) -> molecule::bytes::Bytes {
3702 self.0.clone()
3703 }
3704 fn as_slice(&self) -> &[u8] {
3705 &self.0[..]
3706 }
3707 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3708 ChannelAnnouncementReader::from_slice(slice).map(|reader| reader.to_entity())
3709 }
3710 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3711 ChannelAnnouncementReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3712 }
3713 fn new_builder() -> Self::Builder {
3714 ::core::default::Default::default()
3715 }
3716 fn as_builder(self) -> Self::Builder {
3717 Self::new_builder()
3718 .node1_signature(self.node1_signature())
3719 .node2_signature(self.node2_signature())
3720 .ckb_signature(self.ckb_signature())
3721 .features(self.features())
3722 .chain_hash(self.chain_hash())
3723 .channel_outpoint(self.channel_outpoint())
3724 .node1_id(self.node1_id())
3725 .node2_id(self.node2_id())
3726 .ckb_key(self.ckb_key())
3727 .capacity(self.capacity())
3728 .udt_type_script(self.udt_type_script())
3729 }
3730}
3731#[derive(Clone, Copy)]
3732pub struct ChannelAnnouncementReader<'r>(&'r [u8]);
3733impl<'r> ::core::fmt::LowerHex for ChannelAnnouncementReader<'r> {
3734 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3735 use molecule::hex_string;
3736 if f.alternate() {
3737 write!(f, "0x")?;
3738 }
3739 write!(f, "{}", hex_string(self.as_slice()))
3740 }
3741}
3742impl<'r> ::core::fmt::Debug for ChannelAnnouncementReader<'r> {
3743 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3744 write!(f, "{}({:#x})", Self::NAME, self)
3745 }
3746}
3747impl<'r> ::core::fmt::Display for ChannelAnnouncementReader<'r> {
3748 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3749 write!(f, "{} {{ ", Self::NAME)?;
3750 write!(f, "{}: {}", "node1_signature", self.node1_signature())?;
3751 write!(f, ", {}: {}", "node2_signature", self.node2_signature())?;
3752 write!(f, ", {}: {}", "ckb_signature", self.ckb_signature())?;
3753 write!(f, ", {}: {}", "features", self.features())?;
3754 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
3755 write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
3756 write!(f, ", {}: {}", "node1_id", self.node1_id())?;
3757 write!(f, ", {}: {}", "node2_id", self.node2_id())?;
3758 write!(f, ", {}: {}", "ckb_key", self.ckb_key())?;
3759 write!(f, ", {}: {}", "capacity", self.capacity())?;
3760 write!(f, ", {}: {}", "udt_type_script", self.udt_type_script())?;
3761 let extra_count = self.count_extra_fields();
3762 if extra_count != 0 {
3763 write!(f, ", .. ({} fields)", extra_count)?;
3764 }
3765 write!(f, " }}")
3766 }
3767}
3768impl<'r> ChannelAnnouncementReader<'r> {
3769 pub const FIELD_COUNT: usize = 11;
3770 pub fn total_size(&self) -> usize {
3771 molecule::unpack_number(self.as_slice()) as usize
3772 }
3773 pub fn field_count(&self) -> usize {
3774 if self.total_size() == molecule::NUMBER_SIZE {
3775 0
3776 } else {
3777 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3778 }
3779 }
3780 pub fn count_extra_fields(&self) -> usize {
3781 self.field_count() - Self::FIELD_COUNT
3782 }
3783 pub fn has_extra_fields(&self) -> bool {
3784 Self::FIELD_COUNT != self.field_count()
3785 }
3786 pub fn node1_signature(&self) -> EcdsaSignatureReader<'r> {
3787 let slice = self.as_slice();
3788 let start = molecule::unpack_number(&slice[4..]) as usize;
3789 let end = molecule::unpack_number(&slice[8..]) as usize;
3790 EcdsaSignatureReader::new_unchecked(&self.as_slice()[start..end])
3791 }
3792 pub fn node2_signature(&self) -> EcdsaSignatureReader<'r> {
3793 let slice = self.as_slice();
3794 let start = molecule::unpack_number(&slice[8..]) as usize;
3795 let end = molecule::unpack_number(&slice[12..]) as usize;
3796 EcdsaSignatureReader::new_unchecked(&self.as_slice()[start..end])
3797 }
3798 pub fn ckb_signature(&self) -> SchnorrSignatureReader<'r> {
3799 let slice = self.as_slice();
3800 let start = molecule::unpack_number(&slice[12..]) as usize;
3801 let end = molecule::unpack_number(&slice[16..]) as usize;
3802 SchnorrSignatureReader::new_unchecked(&self.as_slice()[start..end])
3803 }
3804 pub fn features(&self) -> Uint64Reader<'r> {
3805 let slice = self.as_slice();
3806 let start = molecule::unpack_number(&slice[16..]) as usize;
3807 let end = molecule::unpack_number(&slice[20..]) as usize;
3808 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
3809 }
3810 pub fn chain_hash(&self) -> Byte32Reader<'r> {
3811 let slice = self.as_slice();
3812 let start = molecule::unpack_number(&slice[20..]) as usize;
3813 let end = molecule::unpack_number(&slice[24..]) as usize;
3814 Byte32Reader::new_unchecked(&self.as_slice()[start..end])
3815 }
3816 pub fn channel_outpoint(&self) -> OutPointReader<'r> {
3817 let slice = self.as_slice();
3818 let start = molecule::unpack_number(&slice[24..]) as usize;
3819 let end = molecule::unpack_number(&slice[28..]) as usize;
3820 OutPointReader::new_unchecked(&self.as_slice()[start..end])
3821 }
3822 pub fn node1_id(&self) -> PubkeyReader<'r> {
3823 let slice = self.as_slice();
3824 let start = molecule::unpack_number(&slice[28..]) as usize;
3825 let end = molecule::unpack_number(&slice[32..]) as usize;
3826 PubkeyReader::new_unchecked(&self.as_slice()[start..end])
3827 }
3828 pub fn node2_id(&self) -> PubkeyReader<'r> {
3829 let slice = self.as_slice();
3830 let start = molecule::unpack_number(&slice[32..]) as usize;
3831 let end = molecule::unpack_number(&slice[36..]) as usize;
3832 PubkeyReader::new_unchecked(&self.as_slice()[start..end])
3833 }
3834 pub fn ckb_key(&self) -> SchnorrXOnlyPubkeyReader<'r> {
3835 let slice = self.as_slice();
3836 let start = molecule::unpack_number(&slice[36..]) as usize;
3837 let end = molecule::unpack_number(&slice[40..]) as usize;
3838 SchnorrXOnlyPubkeyReader::new_unchecked(&self.as_slice()[start..end])
3839 }
3840 pub fn capacity(&self) -> Uint128Reader<'r> {
3841 let slice = self.as_slice();
3842 let start = molecule::unpack_number(&slice[40..]) as usize;
3843 let end = molecule::unpack_number(&slice[44..]) as usize;
3844 Uint128Reader::new_unchecked(&self.as_slice()[start..end])
3845 }
3846 pub fn udt_type_script(&self) -> ScriptOptReader<'r> {
3847 let slice = self.as_slice();
3848 let start = molecule::unpack_number(&slice[44..]) as usize;
3849 if self.has_extra_fields() {
3850 let end = molecule::unpack_number(&slice[48..]) as usize;
3851 ScriptOptReader::new_unchecked(&self.as_slice()[start..end])
3852 } else {
3853 ScriptOptReader::new_unchecked(&self.as_slice()[start..])
3854 }
3855 }
3856}
3857impl<'r> molecule::prelude::Reader<'r> for ChannelAnnouncementReader<'r> {
3858 type Entity = ChannelAnnouncement;
3859 const NAME: &'static str = "ChannelAnnouncementReader";
3860 fn to_entity(&self) -> Self::Entity {
3861 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3862 }
3863 fn new_unchecked(slice: &'r [u8]) -> Self {
3864 ChannelAnnouncementReader(slice)
3865 }
3866 fn as_slice(&self) -> &'r [u8] {
3867 self.0
3868 }
3869 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3870 use molecule::verification_error as ve;
3871 let slice_len = slice.len();
3872 if slice_len < molecule::NUMBER_SIZE {
3873 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3874 }
3875 let total_size = molecule::unpack_number(slice) as usize;
3876 if slice_len != total_size {
3877 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3878 }
3879 if slice_len < molecule::NUMBER_SIZE * 2 {
3880 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3881 }
3882 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3883 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3884 return ve!(Self, OffsetsNotMatch);
3885 }
3886 if slice_len < offset_first {
3887 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3888 }
3889 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3890 if field_count < Self::FIELD_COUNT {
3891 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3892 } else if !compatible && field_count > Self::FIELD_COUNT {
3893 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3894 };
3895 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
3896 .chunks_exact(molecule::NUMBER_SIZE)
3897 .map(|x| molecule::unpack_number(x) as usize)
3898 .collect();
3899 offsets.push(total_size);
3900 if offsets.windows(2).any(|i| i[0] > i[1]) {
3901 return ve!(Self, OffsetsNotMatch);
3902 }
3903 EcdsaSignatureReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
3904 EcdsaSignatureReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
3905 SchnorrSignatureReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
3906 Uint64Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
3907 Byte32Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
3908 OutPointReader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
3909 PubkeyReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
3910 PubkeyReader::verify(&slice[offsets[7]..offsets[8]], compatible)?;
3911 SchnorrXOnlyPubkeyReader::verify(&slice[offsets[8]..offsets[9]], compatible)?;
3912 Uint128Reader::verify(&slice[offsets[9]..offsets[10]], compatible)?;
3913 ScriptOptReader::verify(&slice[offsets[10]..offsets[11]], compatible)?;
3914 Ok(())
3915 }
3916}
3917#[derive(Clone, Debug, Default)]
3918pub struct ChannelAnnouncementBuilder {
3919 pub(crate) node1_signature: EcdsaSignature,
3920 pub(crate) node2_signature: EcdsaSignature,
3921 pub(crate) ckb_signature: SchnorrSignature,
3922 pub(crate) features: Uint64,
3923 pub(crate) chain_hash: Byte32,
3924 pub(crate) channel_outpoint: OutPoint,
3925 pub(crate) node1_id: Pubkey,
3926 pub(crate) node2_id: Pubkey,
3927 pub(crate) ckb_key: SchnorrXOnlyPubkey,
3928 pub(crate) capacity: Uint128,
3929 pub(crate) udt_type_script: ScriptOpt,
3930}
3931impl ChannelAnnouncementBuilder {
3932 pub const FIELD_COUNT: usize = 11;
3933 pub fn node1_signature(mut self, v: EcdsaSignature) -> Self {
3934 self.node1_signature = v;
3935 self
3936 }
3937 pub fn node2_signature(mut self, v: EcdsaSignature) -> Self {
3938 self.node2_signature = v;
3939 self
3940 }
3941 pub fn ckb_signature(mut self, v: SchnorrSignature) -> Self {
3942 self.ckb_signature = v;
3943 self
3944 }
3945 pub fn features(mut self, v: Uint64) -> Self {
3946 self.features = v;
3947 self
3948 }
3949 pub fn chain_hash(mut self, v: Byte32) -> Self {
3950 self.chain_hash = v;
3951 self
3952 }
3953 pub fn channel_outpoint(mut self, v: OutPoint) -> Self {
3954 self.channel_outpoint = v;
3955 self
3956 }
3957 pub fn node1_id(mut self, v: Pubkey) -> Self {
3958 self.node1_id = v;
3959 self
3960 }
3961 pub fn node2_id(mut self, v: Pubkey) -> Self {
3962 self.node2_id = v;
3963 self
3964 }
3965 pub fn ckb_key(mut self, v: SchnorrXOnlyPubkey) -> Self {
3966 self.ckb_key = v;
3967 self
3968 }
3969 pub fn capacity(mut self, v: Uint128) -> Self {
3970 self.capacity = v;
3971 self
3972 }
3973 pub fn udt_type_script(mut self, v: ScriptOpt) -> Self {
3974 self.udt_type_script = v;
3975 self
3976 }
3977}
3978impl molecule::prelude::Builder for ChannelAnnouncementBuilder {
3979 type Entity = ChannelAnnouncement;
3980 const NAME: &'static str = "ChannelAnnouncementBuilder";
3981 fn expected_length(&self) -> usize {
3982 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
3983 + self.node1_signature.as_slice().len()
3984 + self.node2_signature.as_slice().len()
3985 + self.ckb_signature.as_slice().len()
3986 + self.features.as_slice().len()
3987 + self.chain_hash.as_slice().len()
3988 + self.channel_outpoint.as_slice().len()
3989 + self.node1_id.as_slice().len()
3990 + self.node2_id.as_slice().len()
3991 + self.ckb_key.as_slice().len()
3992 + self.capacity.as_slice().len()
3993 + self.udt_type_script.as_slice().len()
3994 }
3995 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3996 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
3997 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
3998 offsets.push(total_size);
3999 total_size += self.node1_signature.as_slice().len();
4000 offsets.push(total_size);
4001 total_size += self.node2_signature.as_slice().len();
4002 offsets.push(total_size);
4003 total_size += self.ckb_signature.as_slice().len();
4004 offsets.push(total_size);
4005 total_size += self.features.as_slice().len();
4006 offsets.push(total_size);
4007 total_size += self.chain_hash.as_slice().len();
4008 offsets.push(total_size);
4009 total_size += self.channel_outpoint.as_slice().len();
4010 offsets.push(total_size);
4011 total_size += self.node1_id.as_slice().len();
4012 offsets.push(total_size);
4013 total_size += self.node2_id.as_slice().len();
4014 offsets.push(total_size);
4015 total_size += self.ckb_key.as_slice().len();
4016 offsets.push(total_size);
4017 total_size += self.capacity.as_slice().len();
4018 offsets.push(total_size);
4019 total_size += self.udt_type_script.as_slice().len();
4020 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4021 for offset in offsets.into_iter() {
4022 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4023 }
4024 writer.write_all(self.node1_signature.as_slice())?;
4025 writer.write_all(self.node2_signature.as_slice())?;
4026 writer.write_all(self.ckb_signature.as_slice())?;
4027 writer.write_all(self.features.as_slice())?;
4028 writer.write_all(self.chain_hash.as_slice())?;
4029 writer.write_all(self.channel_outpoint.as_slice())?;
4030 writer.write_all(self.node1_id.as_slice())?;
4031 writer.write_all(self.node2_id.as_slice())?;
4032 writer.write_all(self.ckb_key.as_slice())?;
4033 writer.write_all(self.capacity.as_slice())?;
4034 writer.write_all(self.udt_type_script.as_slice())?;
4035 Ok(())
4036 }
4037 fn build(&self) -> Self::Entity {
4038 let mut inner = Vec::with_capacity(self.expected_length());
4039 self.write(&mut inner)
4040 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4041 ChannelAnnouncement::new_unchecked(inner.into())
4042 }
4043}
4044#[derive(Clone)]
4045pub struct BroadcastMessage(molecule::bytes::Bytes);
4046impl ::core::fmt::LowerHex for BroadcastMessage {
4047 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4048 use molecule::hex_string;
4049 if f.alternate() {
4050 write!(f, "0x")?;
4051 }
4052 write!(f, "{}", hex_string(self.as_slice()))
4053 }
4054}
4055impl ::core::fmt::Debug for BroadcastMessage {
4056 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4057 write!(f, "{}({:#x})", Self::NAME, self)
4058 }
4059}
4060impl ::core::fmt::Display for BroadcastMessage {
4061 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4062 write!(f, "{}(", Self::NAME)?;
4063 self.to_enum().display_inner(f)?;
4064 write!(f, ")")
4065 }
4066}
4067impl ::core::default::Default for BroadcastMessage {
4068 fn default() -> Self {
4069 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4070 BroadcastMessage::new_unchecked(v)
4071 }
4072}
4073impl BroadcastMessage {
4074 const DEFAULT_VALUE: [u8; 241] = [
4075 0, 0, 0, 0, 237, 0, 0, 0, 44, 0, 0, 0, 108, 0, 0, 0, 112, 0, 0, 0, 120, 0, 0, 0, 153, 0, 0,
4076 0, 157, 0, 0, 0, 189, 0, 0, 0, 193, 0, 0, 0, 225, 0, 0, 0, 233, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4077 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4078 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4079 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4080 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4081 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4082 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4083 0, 0, 0, 4, 0, 0, 0,
4084 ];
4085 pub const ITEMS_COUNT: usize = 3;
4086 pub fn item_id(&self) -> molecule::Number {
4087 molecule::unpack_number(self.as_slice())
4088 }
4089 pub fn to_enum(&self) -> BroadcastMessageUnion {
4090 let inner = self.0.slice(molecule::NUMBER_SIZE..);
4091 match self.item_id() {
4092 0 => NodeAnnouncement::new_unchecked(inner).into(),
4093 1 => ChannelAnnouncement::new_unchecked(inner).into(),
4094 2 => ChannelUpdate::new_unchecked(inner).into(),
4095 _ => panic!("{}: invalid data", Self::NAME),
4096 }
4097 }
4098 pub fn as_reader<'r>(&'r self) -> BroadcastMessageReader<'r> {
4099 BroadcastMessageReader::new_unchecked(self.as_slice())
4100 }
4101}
4102impl molecule::prelude::Entity for BroadcastMessage {
4103 type Builder = BroadcastMessageBuilder;
4104 const NAME: &'static str = "BroadcastMessage";
4105 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4106 BroadcastMessage(data)
4107 }
4108 fn as_bytes(&self) -> molecule::bytes::Bytes {
4109 self.0.clone()
4110 }
4111 fn as_slice(&self) -> &[u8] {
4112 &self.0[..]
4113 }
4114 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4115 BroadcastMessageReader::from_slice(slice).map(|reader| reader.to_entity())
4116 }
4117 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4118 BroadcastMessageReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4119 }
4120 fn new_builder() -> Self::Builder {
4121 ::core::default::Default::default()
4122 }
4123 fn as_builder(self) -> Self::Builder {
4124 Self::new_builder().set(self.to_enum())
4125 }
4126}
4127#[derive(Clone, Copy)]
4128pub struct BroadcastMessageReader<'r>(&'r [u8]);
4129impl<'r> ::core::fmt::LowerHex for BroadcastMessageReader<'r> {
4130 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4131 use molecule::hex_string;
4132 if f.alternate() {
4133 write!(f, "0x")?;
4134 }
4135 write!(f, "{}", hex_string(self.as_slice()))
4136 }
4137}
4138impl<'r> ::core::fmt::Debug for BroadcastMessageReader<'r> {
4139 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4140 write!(f, "{}({:#x})", Self::NAME, self)
4141 }
4142}
4143impl<'r> ::core::fmt::Display for BroadcastMessageReader<'r> {
4144 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4145 write!(f, "{}(", Self::NAME)?;
4146 self.to_enum().display_inner(f)?;
4147 write!(f, ")")
4148 }
4149}
4150impl<'r> BroadcastMessageReader<'r> {
4151 pub const ITEMS_COUNT: usize = 3;
4152 pub fn item_id(&self) -> molecule::Number {
4153 molecule::unpack_number(self.as_slice())
4154 }
4155 pub fn to_enum(&self) -> BroadcastMessageUnionReader<'r> {
4156 let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
4157 match self.item_id() {
4158 0 => NodeAnnouncementReader::new_unchecked(inner).into(),
4159 1 => ChannelAnnouncementReader::new_unchecked(inner).into(),
4160 2 => ChannelUpdateReader::new_unchecked(inner).into(),
4161 _ => panic!("{}: invalid data", Self::NAME),
4162 }
4163 }
4164}
4165impl<'r> molecule::prelude::Reader<'r> for BroadcastMessageReader<'r> {
4166 type Entity = BroadcastMessage;
4167 const NAME: &'static str = "BroadcastMessageReader";
4168 fn to_entity(&self) -> Self::Entity {
4169 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4170 }
4171 fn new_unchecked(slice: &'r [u8]) -> Self {
4172 BroadcastMessageReader(slice)
4173 }
4174 fn as_slice(&self) -> &'r [u8] {
4175 self.0
4176 }
4177 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4178 use molecule::verification_error as ve;
4179 let slice_len = slice.len();
4180 if slice_len < molecule::NUMBER_SIZE {
4181 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4182 }
4183 let item_id = molecule::unpack_number(slice);
4184 let inner_slice = &slice[molecule::NUMBER_SIZE..];
4185 match item_id {
4186 0 => NodeAnnouncementReader::verify(inner_slice, compatible),
4187 1 => ChannelAnnouncementReader::verify(inner_slice, compatible),
4188 2 => ChannelUpdateReader::verify(inner_slice, compatible),
4189 _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
4190 }?;
4191 Ok(())
4192 }
4193}
4194#[derive(Clone, Debug, Default)]
4195pub struct BroadcastMessageBuilder(pub(crate) BroadcastMessageUnion);
4196impl BroadcastMessageBuilder {
4197 pub const ITEMS_COUNT: usize = 3;
4198 pub fn set<I>(mut self, v: I) -> Self
4199 where
4200 I: ::core::convert::Into<BroadcastMessageUnion>,
4201 {
4202 self.0 = v.into();
4203 self
4204 }
4205}
4206impl molecule::prelude::Builder for BroadcastMessageBuilder {
4207 type Entity = BroadcastMessage;
4208 const NAME: &'static str = "BroadcastMessageBuilder";
4209 fn expected_length(&self) -> usize {
4210 molecule::NUMBER_SIZE + self.0.as_slice().len()
4211 }
4212 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4213 writer.write_all(&molecule::pack_number(self.0.item_id()))?;
4214 writer.write_all(self.0.as_slice())
4215 }
4216 fn build(&self) -> Self::Entity {
4217 let mut inner = Vec::with_capacity(self.expected_length());
4218 self.write(&mut inner)
4219 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4220 BroadcastMessage::new_unchecked(inner.into())
4221 }
4222}
4223#[derive(Debug, Clone)]
4224pub enum BroadcastMessageUnion {
4225 NodeAnnouncement(NodeAnnouncement),
4226 ChannelAnnouncement(ChannelAnnouncement),
4227 ChannelUpdate(ChannelUpdate),
4228}
4229#[derive(Debug, Clone, Copy)]
4230pub enum BroadcastMessageUnionReader<'r> {
4231 NodeAnnouncement(NodeAnnouncementReader<'r>),
4232 ChannelAnnouncement(ChannelAnnouncementReader<'r>),
4233 ChannelUpdate(ChannelUpdateReader<'r>),
4234}
4235impl ::core::default::Default for BroadcastMessageUnion {
4236 fn default() -> Self {
4237 BroadcastMessageUnion::NodeAnnouncement(::core::default::Default::default())
4238 }
4239}
4240impl ::core::fmt::Display for BroadcastMessageUnion {
4241 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4242 match self {
4243 BroadcastMessageUnion::NodeAnnouncement(ref item) => {
4244 write!(f, "{}::{}({})", Self::NAME, NodeAnnouncement::NAME, item)
4245 }
4246 BroadcastMessageUnion::ChannelAnnouncement(ref item) => {
4247 write!(f, "{}::{}({})", Self::NAME, ChannelAnnouncement::NAME, item)
4248 }
4249 BroadcastMessageUnion::ChannelUpdate(ref item) => {
4250 write!(f, "{}::{}({})", Self::NAME, ChannelUpdate::NAME, item)
4251 }
4252 }
4253 }
4254}
4255impl<'r> ::core::fmt::Display for BroadcastMessageUnionReader<'r> {
4256 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4257 match self {
4258 BroadcastMessageUnionReader::NodeAnnouncement(ref item) => {
4259 write!(f, "{}::{}({})", Self::NAME, NodeAnnouncement::NAME, item)
4260 }
4261 BroadcastMessageUnionReader::ChannelAnnouncement(ref item) => {
4262 write!(f, "{}::{}({})", Self::NAME, ChannelAnnouncement::NAME, item)
4263 }
4264 BroadcastMessageUnionReader::ChannelUpdate(ref item) => {
4265 write!(f, "{}::{}({})", Self::NAME, ChannelUpdate::NAME, item)
4266 }
4267 }
4268 }
4269}
4270impl BroadcastMessageUnion {
4271 pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4272 match self {
4273 BroadcastMessageUnion::NodeAnnouncement(ref item) => write!(f, "{}", item),
4274 BroadcastMessageUnion::ChannelAnnouncement(ref item) => write!(f, "{}", item),
4275 BroadcastMessageUnion::ChannelUpdate(ref item) => write!(f, "{}", item),
4276 }
4277 }
4278}
4279impl<'r> BroadcastMessageUnionReader<'r> {
4280 pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4281 match self {
4282 BroadcastMessageUnionReader::NodeAnnouncement(ref item) => write!(f, "{}", item),
4283 BroadcastMessageUnionReader::ChannelAnnouncement(ref item) => write!(f, "{}", item),
4284 BroadcastMessageUnionReader::ChannelUpdate(ref item) => write!(f, "{}", item),
4285 }
4286 }
4287}
4288impl ::core::convert::From<NodeAnnouncement> for BroadcastMessageUnion {
4289 fn from(item: NodeAnnouncement) -> Self {
4290 BroadcastMessageUnion::NodeAnnouncement(item)
4291 }
4292}
4293impl ::core::convert::From<ChannelAnnouncement> for BroadcastMessageUnion {
4294 fn from(item: ChannelAnnouncement) -> Self {
4295 BroadcastMessageUnion::ChannelAnnouncement(item)
4296 }
4297}
4298impl ::core::convert::From<ChannelUpdate> for BroadcastMessageUnion {
4299 fn from(item: ChannelUpdate) -> Self {
4300 BroadcastMessageUnion::ChannelUpdate(item)
4301 }
4302}
4303impl<'r> ::core::convert::From<NodeAnnouncementReader<'r>> for BroadcastMessageUnionReader<'r> {
4304 fn from(item: NodeAnnouncementReader<'r>) -> Self {
4305 BroadcastMessageUnionReader::NodeAnnouncement(item)
4306 }
4307}
4308impl<'r> ::core::convert::From<ChannelAnnouncementReader<'r>> for BroadcastMessageUnionReader<'r> {
4309 fn from(item: ChannelAnnouncementReader<'r>) -> Self {
4310 BroadcastMessageUnionReader::ChannelAnnouncement(item)
4311 }
4312}
4313impl<'r> ::core::convert::From<ChannelUpdateReader<'r>> for BroadcastMessageUnionReader<'r> {
4314 fn from(item: ChannelUpdateReader<'r>) -> Self {
4315 BroadcastMessageUnionReader::ChannelUpdate(item)
4316 }
4317}
4318impl BroadcastMessageUnion {
4319 pub const NAME: &'static str = "BroadcastMessageUnion";
4320 pub fn as_bytes(&self) -> molecule::bytes::Bytes {
4321 match self {
4322 BroadcastMessageUnion::NodeAnnouncement(item) => item.as_bytes(),
4323 BroadcastMessageUnion::ChannelAnnouncement(item) => item.as_bytes(),
4324 BroadcastMessageUnion::ChannelUpdate(item) => item.as_bytes(),
4325 }
4326 }
4327 pub fn as_slice(&self) -> &[u8] {
4328 match self {
4329 BroadcastMessageUnion::NodeAnnouncement(item) => item.as_slice(),
4330 BroadcastMessageUnion::ChannelAnnouncement(item) => item.as_slice(),
4331 BroadcastMessageUnion::ChannelUpdate(item) => item.as_slice(),
4332 }
4333 }
4334 pub fn item_id(&self) -> molecule::Number {
4335 match self {
4336 BroadcastMessageUnion::NodeAnnouncement(_) => 0,
4337 BroadcastMessageUnion::ChannelAnnouncement(_) => 1,
4338 BroadcastMessageUnion::ChannelUpdate(_) => 2,
4339 }
4340 }
4341 pub fn item_name(&self) -> &str {
4342 match self {
4343 BroadcastMessageUnion::NodeAnnouncement(_) => "NodeAnnouncement",
4344 BroadcastMessageUnion::ChannelAnnouncement(_) => "ChannelAnnouncement",
4345 BroadcastMessageUnion::ChannelUpdate(_) => "ChannelUpdate",
4346 }
4347 }
4348 pub fn as_reader<'r>(&'r self) -> BroadcastMessageUnionReader<'r> {
4349 match self {
4350 BroadcastMessageUnion::NodeAnnouncement(item) => item.as_reader().into(),
4351 BroadcastMessageUnion::ChannelAnnouncement(item) => item.as_reader().into(),
4352 BroadcastMessageUnion::ChannelUpdate(item) => item.as_reader().into(),
4353 }
4354 }
4355}
4356impl<'r> BroadcastMessageUnionReader<'r> {
4357 pub const NAME: &'r str = "BroadcastMessageUnionReader";
4358 pub fn as_slice(&self) -> &'r [u8] {
4359 match self {
4360 BroadcastMessageUnionReader::NodeAnnouncement(item) => item.as_slice(),
4361 BroadcastMessageUnionReader::ChannelAnnouncement(item) => item.as_slice(),
4362 BroadcastMessageUnionReader::ChannelUpdate(item) => item.as_slice(),
4363 }
4364 }
4365 pub fn item_id(&self) -> molecule::Number {
4366 match self {
4367 BroadcastMessageUnionReader::NodeAnnouncement(_) => 0,
4368 BroadcastMessageUnionReader::ChannelAnnouncement(_) => 1,
4369 BroadcastMessageUnionReader::ChannelUpdate(_) => 2,
4370 }
4371 }
4372 pub fn item_name(&self) -> &str {
4373 match self {
4374 BroadcastMessageUnionReader::NodeAnnouncement(_) => "NodeAnnouncement",
4375 BroadcastMessageUnionReader::ChannelAnnouncement(_) => "ChannelAnnouncement",
4376 BroadcastMessageUnionReader::ChannelUpdate(_) => "ChannelUpdate",
4377 }
4378 }
4379}
4380impl From<NodeAnnouncement> for BroadcastMessage {
4381 fn from(value: NodeAnnouncement) -> Self {
4382 Self::new_builder().set(value).build()
4383 }
4384}
4385impl From<ChannelAnnouncement> for BroadcastMessage {
4386 fn from(value: ChannelAnnouncement) -> Self {
4387 Self::new_builder().set(value).build()
4388 }
4389}
4390impl From<ChannelUpdate> for BroadcastMessage {
4391 fn from(value: ChannelUpdate) -> Self {
4392 Self::new_builder().set(value).build()
4393 }
4394}
4395#[derive(Clone)]
4396pub struct BroadcastMessages(molecule::bytes::Bytes);
4397impl ::core::fmt::LowerHex for BroadcastMessages {
4398 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4399 use molecule::hex_string;
4400 if f.alternate() {
4401 write!(f, "0x")?;
4402 }
4403 write!(f, "{}", hex_string(self.as_slice()))
4404 }
4405}
4406impl ::core::fmt::Debug for BroadcastMessages {
4407 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4408 write!(f, "{}({:#x})", Self::NAME, self)
4409 }
4410}
4411impl ::core::fmt::Display for BroadcastMessages {
4412 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4413 write!(f, "{} [", Self::NAME)?;
4414 for i in 0..self.len() {
4415 if i == 0 {
4416 write!(f, "{}", self.get_unchecked(i))?;
4417 } else {
4418 write!(f, ", {}", self.get_unchecked(i))?;
4419 }
4420 }
4421 write!(f, "]")
4422 }
4423}
4424impl ::core::default::Default for BroadcastMessages {
4425 fn default() -> Self {
4426 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4427 BroadcastMessages::new_unchecked(v)
4428 }
4429}
4430impl BroadcastMessages {
4431 const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
4432 pub fn total_size(&self) -> usize {
4433 molecule::unpack_number(self.as_slice()) as usize
4434 }
4435 pub fn item_count(&self) -> usize {
4436 if self.total_size() == molecule::NUMBER_SIZE {
4437 0
4438 } else {
4439 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4440 }
4441 }
4442 pub fn len(&self) -> usize {
4443 self.item_count()
4444 }
4445 pub fn is_empty(&self) -> bool {
4446 self.len() == 0
4447 }
4448 pub fn get(&self, idx: usize) -> Option<BroadcastMessage> {
4449 if idx >= self.len() {
4450 None
4451 } else {
4452 Some(self.get_unchecked(idx))
4453 }
4454 }
4455 pub fn get_unchecked(&self, idx: usize) -> BroadcastMessage {
4456 let slice = self.as_slice();
4457 let start_idx = molecule::NUMBER_SIZE * (1 + idx);
4458 let start = molecule::unpack_number(&slice[start_idx..]) as usize;
4459 if idx == self.len() - 1 {
4460 BroadcastMessage::new_unchecked(self.0.slice(start..))
4461 } else {
4462 let end_idx = start_idx + molecule::NUMBER_SIZE;
4463 let end = molecule::unpack_number(&slice[end_idx..]) as usize;
4464 BroadcastMessage::new_unchecked(self.0.slice(start..end))
4465 }
4466 }
4467 pub fn as_reader<'r>(&'r self) -> BroadcastMessagesReader<'r> {
4468 BroadcastMessagesReader::new_unchecked(self.as_slice())
4469 }
4470}
4471impl molecule::prelude::Entity for BroadcastMessages {
4472 type Builder = BroadcastMessagesBuilder;
4473 const NAME: &'static str = "BroadcastMessages";
4474 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4475 BroadcastMessages(data)
4476 }
4477 fn as_bytes(&self) -> molecule::bytes::Bytes {
4478 self.0.clone()
4479 }
4480 fn as_slice(&self) -> &[u8] {
4481 &self.0[..]
4482 }
4483 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4484 BroadcastMessagesReader::from_slice(slice).map(|reader| reader.to_entity())
4485 }
4486 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4487 BroadcastMessagesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4488 }
4489 fn new_builder() -> Self::Builder {
4490 ::core::default::Default::default()
4491 }
4492 fn as_builder(self) -> Self::Builder {
4493 Self::new_builder().extend(self.into_iter())
4494 }
4495}
4496#[derive(Clone, Copy)]
4497pub struct BroadcastMessagesReader<'r>(&'r [u8]);
4498impl<'r> ::core::fmt::LowerHex for BroadcastMessagesReader<'r> {
4499 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4500 use molecule::hex_string;
4501 if f.alternate() {
4502 write!(f, "0x")?;
4503 }
4504 write!(f, "{}", hex_string(self.as_slice()))
4505 }
4506}
4507impl<'r> ::core::fmt::Debug for BroadcastMessagesReader<'r> {
4508 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4509 write!(f, "{}({:#x})", Self::NAME, self)
4510 }
4511}
4512impl<'r> ::core::fmt::Display for BroadcastMessagesReader<'r> {
4513 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4514 write!(f, "{} [", Self::NAME)?;
4515 for i in 0..self.len() {
4516 if i == 0 {
4517 write!(f, "{}", self.get_unchecked(i))?;
4518 } else {
4519 write!(f, ", {}", self.get_unchecked(i))?;
4520 }
4521 }
4522 write!(f, "]")
4523 }
4524}
4525impl<'r> BroadcastMessagesReader<'r> {
4526 pub fn total_size(&self) -> usize {
4527 molecule::unpack_number(self.as_slice()) as usize
4528 }
4529 pub fn item_count(&self) -> usize {
4530 if self.total_size() == molecule::NUMBER_SIZE {
4531 0
4532 } else {
4533 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4534 }
4535 }
4536 pub fn len(&self) -> usize {
4537 self.item_count()
4538 }
4539 pub fn is_empty(&self) -> bool {
4540 self.len() == 0
4541 }
4542 pub fn get(&self, idx: usize) -> Option<BroadcastMessageReader<'r>> {
4543 if idx >= self.len() {
4544 None
4545 } else {
4546 Some(self.get_unchecked(idx))
4547 }
4548 }
4549 pub fn get_unchecked(&self, idx: usize) -> BroadcastMessageReader<'r> {
4550 let slice = self.as_slice();
4551 let start_idx = molecule::NUMBER_SIZE * (1 + idx);
4552 let start = molecule::unpack_number(&slice[start_idx..]) as usize;
4553 if idx == self.len() - 1 {
4554 BroadcastMessageReader::new_unchecked(&self.as_slice()[start..])
4555 } else {
4556 let end_idx = start_idx + molecule::NUMBER_SIZE;
4557 let end = molecule::unpack_number(&slice[end_idx..]) as usize;
4558 BroadcastMessageReader::new_unchecked(&self.as_slice()[start..end])
4559 }
4560 }
4561}
4562impl<'r> molecule::prelude::Reader<'r> for BroadcastMessagesReader<'r> {
4563 type Entity = BroadcastMessages;
4564 const NAME: &'static str = "BroadcastMessagesReader";
4565 fn to_entity(&self) -> Self::Entity {
4566 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4567 }
4568 fn new_unchecked(slice: &'r [u8]) -> Self {
4569 BroadcastMessagesReader(slice)
4570 }
4571 fn as_slice(&self) -> &'r [u8] {
4572 self.0
4573 }
4574 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4575 use molecule::verification_error as ve;
4576 let slice_len = slice.len();
4577 if slice_len < molecule::NUMBER_SIZE {
4578 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4579 }
4580 let total_size = molecule::unpack_number(slice) as usize;
4581 if slice_len != total_size {
4582 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4583 }
4584 if slice_len == molecule::NUMBER_SIZE {
4585 return Ok(());
4586 }
4587 if slice_len < molecule::NUMBER_SIZE * 2 {
4588 return ve!(
4589 Self,
4590 TotalSizeNotMatch,
4591 molecule::NUMBER_SIZE * 2,
4592 slice_len
4593 );
4594 }
4595 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4596 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4597 return ve!(Self, OffsetsNotMatch);
4598 }
4599 if slice_len < offset_first {
4600 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4601 }
4602 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4603 .chunks_exact(molecule::NUMBER_SIZE)
4604 .map(|x| molecule::unpack_number(x) as usize)
4605 .collect();
4606 offsets.push(total_size);
4607 if offsets.windows(2).any(|i| i[0] > i[1]) {
4608 return ve!(Self, OffsetsNotMatch);
4609 }
4610 for pair in offsets.windows(2) {
4611 let start = pair[0];
4612 let end = pair[1];
4613 BroadcastMessageReader::verify(&slice[start..end], compatible)?;
4614 }
4615 Ok(())
4616 }
4617}
4618#[derive(Clone, Debug, Default)]
4619pub struct BroadcastMessagesBuilder(pub(crate) Vec<BroadcastMessage>);
4620impl BroadcastMessagesBuilder {
4621 pub fn set(mut self, v: Vec<BroadcastMessage>) -> Self {
4622 self.0 = v;
4623 self
4624 }
4625 pub fn push(mut self, v: BroadcastMessage) -> Self {
4626 self.0.push(v);
4627 self
4628 }
4629 pub fn extend<T: ::core::iter::IntoIterator<Item = BroadcastMessage>>(
4630 mut self,
4631 iter: T,
4632 ) -> Self {
4633 for elem in iter {
4634 self.0.push(elem);
4635 }
4636 self
4637 }
4638 pub fn replace(&mut self, index: usize, v: BroadcastMessage) -> Option<BroadcastMessage> {
4639 self.0
4640 .get_mut(index)
4641 .map(|item| ::core::mem::replace(item, v))
4642 }
4643}
4644impl molecule::prelude::Builder for BroadcastMessagesBuilder {
4645 type Entity = BroadcastMessages;
4646 const NAME: &'static str = "BroadcastMessagesBuilder";
4647 fn expected_length(&self) -> usize {
4648 molecule::NUMBER_SIZE * (self.0.len() + 1)
4649 + self
4650 .0
4651 .iter()
4652 .map(|inner| inner.as_slice().len())
4653 .sum::<usize>()
4654 }
4655 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4656 let item_count = self.0.len();
4657 if item_count == 0 {
4658 writer.write_all(&molecule::pack_number(
4659 molecule::NUMBER_SIZE as molecule::Number,
4660 ))?;
4661 } else {
4662 let (total_size, offsets) = self.0.iter().fold(
4663 (
4664 molecule::NUMBER_SIZE * (item_count + 1),
4665 Vec::with_capacity(item_count),
4666 ),
4667 |(start, mut offsets), inner| {
4668 offsets.push(start);
4669 (start + inner.as_slice().len(), offsets)
4670 },
4671 );
4672 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4673 for offset in offsets.into_iter() {
4674 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4675 }
4676 for inner in self.0.iter() {
4677 writer.write_all(inner.as_slice())?;
4678 }
4679 }
4680 Ok(())
4681 }
4682 fn build(&self) -> Self::Entity {
4683 let mut inner = Vec::with_capacity(self.expected_length());
4684 self.write(&mut inner)
4685 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4686 BroadcastMessages::new_unchecked(inner.into())
4687 }
4688}
4689pub struct BroadcastMessagesIterator(BroadcastMessages, usize, usize);
4690impl ::core::iter::Iterator for BroadcastMessagesIterator {
4691 type Item = BroadcastMessage;
4692 fn next(&mut self) -> Option<Self::Item> {
4693 if self.1 >= self.2 {
4694 None
4695 } else {
4696 let ret = self.0.get_unchecked(self.1);
4697 self.1 += 1;
4698 Some(ret)
4699 }
4700 }
4701}
4702impl ::core::iter::ExactSizeIterator for BroadcastMessagesIterator {
4703 fn len(&self) -> usize {
4704 self.2 - self.1
4705 }
4706}
4707impl ::core::iter::IntoIterator for BroadcastMessages {
4708 type Item = BroadcastMessage;
4709 type IntoIter = BroadcastMessagesIterator;
4710 fn into_iter(self) -> Self::IntoIter {
4711 let len = self.len();
4712 BroadcastMessagesIterator(self, 0, len)
4713 }
4714}
4715impl<'r> BroadcastMessagesReader<'r> {
4716 pub fn iter<'t>(&'t self) -> BroadcastMessagesReaderIterator<'t, 'r> {
4717 BroadcastMessagesReaderIterator(&self, 0, self.len())
4718 }
4719}
4720pub struct BroadcastMessagesReaderIterator<'t, 'r>(&'t BroadcastMessagesReader<'r>, usize, usize);
4721impl<'t: 'r, 'r> ::core::iter::Iterator for BroadcastMessagesReaderIterator<'t, 'r> {
4722 type Item = BroadcastMessageReader<'t>;
4723 fn next(&mut self) -> Option<Self::Item> {
4724 if self.1 >= self.2 {
4725 None
4726 } else {
4727 let ret = self.0.get_unchecked(self.1);
4728 self.1 += 1;
4729 Some(ret)
4730 }
4731 }
4732}
4733impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for BroadcastMessagesReaderIterator<'t, 'r> {
4734 fn len(&self) -> usize {
4735 self.2 - self.1
4736 }
4737}
4738impl ::core::iter::FromIterator<BroadcastMessage> for BroadcastMessages {
4739 fn from_iter<T: IntoIterator<Item = BroadcastMessage>>(iter: T) -> Self {
4740 Self::new_builder().extend(iter).build()
4741 }
4742}
4743#[derive(Clone)]
4744pub struct MissingQueryIndexes(molecule::bytes::Bytes);
4745impl ::core::fmt::LowerHex for MissingQueryIndexes {
4746 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4747 use molecule::hex_string;
4748 if f.alternate() {
4749 write!(f, "0x")?;
4750 }
4751 write!(f, "{}", hex_string(self.as_slice()))
4752 }
4753}
4754impl ::core::fmt::Debug for MissingQueryIndexes {
4755 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4756 write!(f, "{}({:#x})", Self::NAME, self)
4757 }
4758}
4759impl ::core::fmt::Display for MissingQueryIndexes {
4760 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4761 write!(f, "{} [", Self::NAME)?;
4762 for i in 0..self.len() {
4763 if i == 0 {
4764 write!(f, "{}", self.get_unchecked(i))?;
4765 } else {
4766 write!(f, ", {}", self.get_unchecked(i))?;
4767 }
4768 }
4769 write!(f, "]")
4770 }
4771}
4772impl ::core::default::Default for MissingQueryIndexes {
4773 fn default() -> Self {
4774 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4775 MissingQueryIndexes::new_unchecked(v)
4776 }
4777}
4778impl MissingQueryIndexes {
4779 const DEFAULT_VALUE: [u8; 4] = [0, 0, 0, 0];
4780 pub const ITEM_SIZE: usize = 2;
4781 pub fn total_size(&self) -> usize {
4782 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count()
4783 }
4784 pub fn item_count(&self) -> usize {
4785 molecule::unpack_number(self.as_slice()) as usize
4786 }
4787 pub fn len(&self) -> usize {
4788 self.item_count()
4789 }
4790 pub fn is_empty(&self) -> bool {
4791 self.len() == 0
4792 }
4793 pub fn get(&self, idx: usize) -> Option<Uint16> {
4794 if idx >= self.len() {
4795 None
4796 } else {
4797 Some(self.get_unchecked(idx))
4798 }
4799 }
4800 pub fn get_unchecked(&self, idx: usize) -> Uint16 {
4801 let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
4802 let end = start + Self::ITEM_SIZE;
4803 Uint16::new_unchecked(self.0.slice(start..end))
4804 }
4805 pub fn as_reader<'r>(&'r self) -> MissingQueryIndexesReader<'r> {
4806 MissingQueryIndexesReader::new_unchecked(self.as_slice())
4807 }
4808}
4809impl molecule::prelude::Entity for MissingQueryIndexes {
4810 type Builder = MissingQueryIndexesBuilder;
4811 const NAME: &'static str = "MissingQueryIndexes";
4812 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4813 MissingQueryIndexes(data)
4814 }
4815 fn as_bytes(&self) -> molecule::bytes::Bytes {
4816 self.0.clone()
4817 }
4818 fn as_slice(&self) -> &[u8] {
4819 &self.0[..]
4820 }
4821 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4822 MissingQueryIndexesReader::from_slice(slice).map(|reader| reader.to_entity())
4823 }
4824 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4825 MissingQueryIndexesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4826 }
4827 fn new_builder() -> Self::Builder {
4828 ::core::default::Default::default()
4829 }
4830 fn as_builder(self) -> Self::Builder {
4831 Self::new_builder().extend(self.into_iter())
4832 }
4833}
4834#[derive(Clone, Copy)]
4835pub struct MissingQueryIndexesReader<'r>(&'r [u8]);
4836impl<'r> ::core::fmt::LowerHex for MissingQueryIndexesReader<'r> {
4837 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4838 use molecule::hex_string;
4839 if f.alternate() {
4840 write!(f, "0x")?;
4841 }
4842 write!(f, "{}", hex_string(self.as_slice()))
4843 }
4844}
4845impl<'r> ::core::fmt::Debug for MissingQueryIndexesReader<'r> {
4846 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4847 write!(f, "{}({:#x})", Self::NAME, self)
4848 }
4849}
4850impl<'r> ::core::fmt::Display for MissingQueryIndexesReader<'r> {
4851 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4852 write!(f, "{} [", Self::NAME)?;
4853 for i in 0..self.len() {
4854 if i == 0 {
4855 write!(f, "{}", self.get_unchecked(i))?;
4856 } else {
4857 write!(f, ", {}", self.get_unchecked(i))?;
4858 }
4859 }
4860 write!(f, "]")
4861 }
4862}
4863impl<'r> MissingQueryIndexesReader<'r> {
4864 pub const ITEM_SIZE: usize = 2;
4865 pub fn total_size(&self) -> usize {
4866 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count()
4867 }
4868 pub fn item_count(&self) -> usize {
4869 molecule::unpack_number(self.as_slice()) as usize
4870 }
4871 pub fn len(&self) -> usize {
4872 self.item_count()
4873 }
4874 pub fn is_empty(&self) -> bool {
4875 self.len() == 0
4876 }
4877 pub fn get(&self, idx: usize) -> Option<Uint16Reader<'r>> {
4878 if idx >= self.len() {
4879 None
4880 } else {
4881 Some(self.get_unchecked(idx))
4882 }
4883 }
4884 pub fn get_unchecked(&self, idx: usize) -> Uint16Reader<'r> {
4885 let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx;
4886 let end = start + Self::ITEM_SIZE;
4887 Uint16Reader::new_unchecked(&self.as_slice()[start..end])
4888 }
4889}
4890impl<'r> molecule::prelude::Reader<'r> for MissingQueryIndexesReader<'r> {
4891 type Entity = MissingQueryIndexes;
4892 const NAME: &'static str = "MissingQueryIndexesReader";
4893 fn to_entity(&self) -> Self::Entity {
4894 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4895 }
4896 fn new_unchecked(slice: &'r [u8]) -> Self {
4897 MissingQueryIndexesReader(slice)
4898 }
4899 fn as_slice(&self) -> &'r [u8] {
4900 self.0
4901 }
4902 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
4903 use molecule::verification_error as ve;
4904 let slice_len = slice.len();
4905 if slice_len < molecule::NUMBER_SIZE {
4906 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4907 }
4908 let item_count = molecule::unpack_number(slice) as usize;
4909 if item_count == 0 {
4910 if slice_len != molecule::NUMBER_SIZE {
4911 return ve!(Self, TotalSizeNotMatch, molecule::NUMBER_SIZE, slice_len);
4912 }
4913 return Ok(());
4914 }
4915 let total_size = molecule::NUMBER_SIZE + Self::ITEM_SIZE * item_count;
4916 if slice_len != total_size {
4917 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4918 }
4919 Ok(())
4920 }
4921}
4922#[derive(Clone, Debug, Default)]
4923pub struct MissingQueryIndexesBuilder(pub(crate) Vec<Uint16>);
4924impl MissingQueryIndexesBuilder {
4925 pub const ITEM_SIZE: usize = 2;
4926 pub fn set(mut self, v: Vec<Uint16>) -> Self {
4927 self.0 = v;
4928 self
4929 }
4930 pub fn push(mut self, v: Uint16) -> Self {
4931 self.0.push(v);
4932 self
4933 }
4934 pub fn extend<T: ::core::iter::IntoIterator<Item = Uint16>>(mut self, iter: T) -> Self {
4935 for elem in iter {
4936 self.0.push(elem);
4937 }
4938 self
4939 }
4940 pub fn replace(&mut self, index: usize, v: Uint16) -> Option<Uint16> {
4941 self.0
4942 .get_mut(index)
4943 .map(|item| ::core::mem::replace(item, v))
4944 }
4945}
4946impl molecule::prelude::Builder for MissingQueryIndexesBuilder {
4947 type Entity = MissingQueryIndexes;
4948 const NAME: &'static str = "MissingQueryIndexesBuilder";
4949 fn expected_length(&self) -> usize {
4950 molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len()
4951 }
4952 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4953 writer.write_all(&molecule::pack_number(self.0.len() as molecule::Number))?;
4954 for inner in &self.0[..] {
4955 writer.write_all(inner.as_slice())?;
4956 }
4957 Ok(())
4958 }
4959 fn build(&self) -> Self::Entity {
4960 let mut inner = Vec::with_capacity(self.expected_length());
4961 self.write(&mut inner)
4962 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4963 MissingQueryIndexes::new_unchecked(inner.into())
4964 }
4965}
4966pub struct MissingQueryIndexesIterator(MissingQueryIndexes, usize, usize);
4967impl ::core::iter::Iterator for MissingQueryIndexesIterator {
4968 type Item = Uint16;
4969 fn next(&mut self) -> Option<Self::Item> {
4970 if self.1 >= self.2 {
4971 None
4972 } else {
4973 let ret = self.0.get_unchecked(self.1);
4974 self.1 += 1;
4975 Some(ret)
4976 }
4977 }
4978}
4979impl ::core::iter::ExactSizeIterator for MissingQueryIndexesIterator {
4980 fn len(&self) -> usize {
4981 self.2 - self.1
4982 }
4983}
4984impl ::core::iter::IntoIterator for MissingQueryIndexes {
4985 type Item = Uint16;
4986 type IntoIter = MissingQueryIndexesIterator;
4987 fn into_iter(self) -> Self::IntoIter {
4988 let len = self.len();
4989 MissingQueryIndexesIterator(self, 0, len)
4990 }
4991}
4992impl<'r> MissingQueryIndexesReader<'r> {
4993 pub fn iter<'t>(&'t self) -> MissingQueryIndexesReaderIterator<'t, 'r> {
4994 MissingQueryIndexesReaderIterator(&self, 0, self.len())
4995 }
4996}
4997pub struct MissingQueryIndexesReaderIterator<'t, 'r>(
4998 &'t MissingQueryIndexesReader<'r>,
4999 usize,
5000 usize,
5001);
5002impl<'t: 'r, 'r> ::core::iter::Iterator for MissingQueryIndexesReaderIterator<'t, 'r> {
5003 type Item = Uint16Reader<'t>;
5004 fn next(&mut self) -> Option<Self::Item> {
5005 if self.1 >= self.2 {
5006 None
5007 } else {
5008 let ret = self.0.get_unchecked(self.1);
5009 self.1 += 1;
5010 Some(ret)
5011 }
5012 }
5013}
5014impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for MissingQueryIndexesReaderIterator<'t, 'r> {
5015 fn len(&self) -> usize {
5016 self.2 - self.1
5017 }
5018}
5019impl ::core::iter::FromIterator<Uint16> for MissingQueryIndexes {
5020 fn from_iter<T: IntoIterator<Item = Uint16>>(iter: T) -> Self {
5021 Self::new_builder().extend(iter).build()
5022 }
5023}
5024#[derive(Clone)]
5025pub struct BroadcastMessagesFilter(molecule::bytes::Bytes);
5026impl ::core::fmt::LowerHex for BroadcastMessagesFilter {
5027 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5028 use molecule::hex_string;
5029 if f.alternate() {
5030 write!(f, "0x")?;
5031 }
5032 write!(f, "{}", hex_string(self.as_slice()))
5033 }
5034}
5035impl ::core::fmt::Debug for BroadcastMessagesFilter {
5036 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5037 write!(f, "{}({:#x})", Self::NAME, self)
5038 }
5039}
5040impl ::core::fmt::Display for BroadcastMessagesFilter {
5041 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5042 write!(f, "{} {{ ", Self::NAME)?;
5043 write!(f, "{}: {}", "chain_hash", self.chain_hash())?;
5044 write!(f, ", {}: {}", "after_cursor", self.after_cursor())?;
5045 write!(f, " }}")
5046 }
5047}
5048impl ::core::default::Default for BroadcastMessagesFilter {
5049 fn default() -> Self {
5050 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5051 BroadcastMessagesFilter::new_unchecked(v)
5052 }
5053}
5054impl BroadcastMessagesFilter {
5055 const DEFAULT_VALUE: [u8; 77] = [
5056 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5057 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5058 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5059 ];
5060 pub const TOTAL_SIZE: usize = 77;
5061 pub const FIELD_SIZES: [usize; 2] = [32, 45];
5062 pub const FIELD_COUNT: usize = 2;
5063 pub fn chain_hash(&self) -> Byte32 {
5064 Byte32::new_unchecked(self.0.slice(0..32))
5065 }
5066 pub fn after_cursor(&self) -> Cursor {
5067 Cursor::new_unchecked(self.0.slice(32..77))
5068 }
5069 pub fn as_reader<'r>(&'r self) -> BroadcastMessagesFilterReader<'r> {
5070 BroadcastMessagesFilterReader::new_unchecked(self.as_slice())
5071 }
5072}
5073impl molecule::prelude::Entity for BroadcastMessagesFilter {
5074 type Builder = BroadcastMessagesFilterBuilder;
5075 const NAME: &'static str = "BroadcastMessagesFilter";
5076 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5077 BroadcastMessagesFilter(data)
5078 }
5079 fn as_bytes(&self) -> molecule::bytes::Bytes {
5080 self.0.clone()
5081 }
5082 fn as_slice(&self) -> &[u8] {
5083 &self.0[..]
5084 }
5085 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5086 BroadcastMessagesFilterReader::from_slice(slice).map(|reader| reader.to_entity())
5087 }
5088 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5089 BroadcastMessagesFilterReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5090 }
5091 fn new_builder() -> Self::Builder {
5092 ::core::default::Default::default()
5093 }
5094 fn as_builder(self) -> Self::Builder {
5095 Self::new_builder()
5096 .chain_hash(self.chain_hash())
5097 .after_cursor(self.after_cursor())
5098 }
5099}
5100#[derive(Clone, Copy)]
5101pub struct BroadcastMessagesFilterReader<'r>(&'r [u8]);
5102impl<'r> ::core::fmt::LowerHex for BroadcastMessagesFilterReader<'r> {
5103 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5104 use molecule::hex_string;
5105 if f.alternate() {
5106 write!(f, "0x")?;
5107 }
5108 write!(f, "{}", hex_string(self.as_slice()))
5109 }
5110}
5111impl<'r> ::core::fmt::Debug for BroadcastMessagesFilterReader<'r> {
5112 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5113 write!(f, "{}({:#x})", Self::NAME, self)
5114 }
5115}
5116impl<'r> ::core::fmt::Display for BroadcastMessagesFilterReader<'r> {
5117 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5118 write!(f, "{} {{ ", Self::NAME)?;
5119 write!(f, "{}: {}", "chain_hash", self.chain_hash())?;
5120 write!(f, ", {}: {}", "after_cursor", self.after_cursor())?;
5121 write!(f, " }}")
5122 }
5123}
5124impl<'r> BroadcastMessagesFilterReader<'r> {
5125 pub const TOTAL_SIZE: usize = 77;
5126 pub const FIELD_SIZES: [usize; 2] = [32, 45];
5127 pub const FIELD_COUNT: usize = 2;
5128 pub fn chain_hash(&self) -> Byte32Reader<'r> {
5129 Byte32Reader::new_unchecked(&self.as_slice()[0..32])
5130 }
5131 pub fn after_cursor(&self) -> CursorReader<'r> {
5132 CursorReader::new_unchecked(&self.as_slice()[32..77])
5133 }
5134}
5135impl<'r> molecule::prelude::Reader<'r> for BroadcastMessagesFilterReader<'r> {
5136 type Entity = BroadcastMessagesFilter;
5137 const NAME: &'static str = "BroadcastMessagesFilterReader";
5138 fn to_entity(&self) -> Self::Entity {
5139 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5140 }
5141 fn new_unchecked(slice: &'r [u8]) -> Self {
5142 BroadcastMessagesFilterReader(slice)
5143 }
5144 fn as_slice(&self) -> &'r [u8] {
5145 self.0
5146 }
5147 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
5148 use molecule::verification_error as ve;
5149 let slice_len = slice.len();
5150 if slice_len != Self::TOTAL_SIZE {
5151 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
5152 }
5153 Ok(())
5154 }
5155}
5156#[derive(Clone, Debug, Default)]
5157pub struct BroadcastMessagesFilterBuilder {
5158 pub(crate) chain_hash: Byte32,
5159 pub(crate) after_cursor: Cursor,
5160}
5161impl BroadcastMessagesFilterBuilder {
5162 pub const TOTAL_SIZE: usize = 77;
5163 pub const FIELD_SIZES: [usize; 2] = [32, 45];
5164 pub const FIELD_COUNT: usize = 2;
5165 pub fn chain_hash(mut self, v: Byte32) -> Self {
5166 self.chain_hash = v;
5167 self
5168 }
5169 pub fn after_cursor(mut self, v: Cursor) -> Self {
5170 self.after_cursor = v;
5171 self
5172 }
5173}
5174impl molecule::prelude::Builder for BroadcastMessagesFilterBuilder {
5175 type Entity = BroadcastMessagesFilter;
5176 const NAME: &'static str = "BroadcastMessagesFilterBuilder";
5177 fn expected_length(&self) -> usize {
5178 Self::TOTAL_SIZE
5179 }
5180 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5181 writer.write_all(self.chain_hash.as_slice())?;
5182 writer.write_all(self.after_cursor.as_slice())?;
5183 Ok(())
5184 }
5185 fn build(&self) -> Self::Entity {
5186 let mut inner = Vec::with_capacity(self.expected_length());
5187 self.write(&mut inner)
5188 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5189 BroadcastMessagesFilter::new_unchecked(inner.into())
5190 }
5191}
5192#[derive(Clone)]
5193pub struct GetBroadcastMessages(molecule::bytes::Bytes);
5194impl ::core::fmt::LowerHex for GetBroadcastMessages {
5195 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5196 use molecule::hex_string;
5197 if f.alternate() {
5198 write!(f, "0x")?;
5199 }
5200 write!(f, "{}", hex_string(self.as_slice()))
5201 }
5202}
5203impl ::core::fmt::Debug for GetBroadcastMessages {
5204 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5205 write!(f, "{}({:#x})", Self::NAME, self)
5206 }
5207}
5208impl ::core::fmt::Display for GetBroadcastMessages {
5209 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5210 write!(f, "{} {{ ", Self::NAME)?;
5211 write!(f, "{}: {}", "id", self.id())?;
5212 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
5213 write!(f, ", {}: {}", "after_cursor", self.after_cursor())?;
5214 write!(f, ", {}: {}", "count", self.count())?;
5215 write!(f, " }}")
5216 }
5217}
5218impl ::core::default::Default for GetBroadcastMessages {
5219 fn default() -> Self {
5220 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5221 GetBroadcastMessages::new_unchecked(v)
5222 }
5223}
5224impl GetBroadcastMessages {
5225 const DEFAULT_VALUE: [u8; 87] = [
5226 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5227 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5229 ];
5230 pub const TOTAL_SIZE: usize = 87;
5231 pub const FIELD_SIZES: [usize; 4] = [8, 32, 45, 2];
5232 pub const FIELD_COUNT: usize = 4;
5233 pub fn id(&self) -> Uint64 {
5234 Uint64::new_unchecked(self.0.slice(0..8))
5235 }
5236 pub fn chain_hash(&self) -> Byte32 {
5237 Byte32::new_unchecked(self.0.slice(8..40))
5238 }
5239 pub fn after_cursor(&self) -> Cursor {
5240 Cursor::new_unchecked(self.0.slice(40..85))
5241 }
5242 pub fn count(&self) -> Uint16 {
5243 Uint16::new_unchecked(self.0.slice(85..87))
5244 }
5245 pub fn as_reader<'r>(&'r self) -> GetBroadcastMessagesReader<'r> {
5246 GetBroadcastMessagesReader::new_unchecked(self.as_slice())
5247 }
5248}
5249impl molecule::prelude::Entity for GetBroadcastMessages {
5250 type Builder = GetBroadcastMessagesBuilder;
5251 const NAME: &'static str = "GetBroadcastMessages";
5252 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5253 GetBroadcastMessages(data)
5254 }
5255 fn as_bytes(&self) -> molecule::bytes::Bytes {
5256 self.0.clone()
5257 }
5258 fn as_slice(&self) -> &[u8] {
5259 &self.0[..]
5260 }
5261 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5262 GetBroadcastMessagesReader::from_slice(slice).map(|reader| reader.to_entity())
5263 }
5264 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5265 GetBroadcastMessagesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5266 }
5267 fn new_builder() -> Self::Builder {
5268 ::core::default::Default::default()
5269 }
5270 fn as_builder(self) -> Self::Builder {
5271 Self::new_builder()
5272 .id(self.id())
5273 .chain_hash(self.chain_hash())
5274 .after_cursor(self.after_cursor())
5275 .count(self.count())
5276 }
5277}
5278#[derive(Clone, Copy)]
5279pub struct GetBroadcastMessagesReader<'r>(&'r [u8]);
5280impl<'r> ::core::fmt::LowerHex for GetBroadcastMessagesReader<'r> {
5281 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5282 use molecule::hex_string;
5283 if f.alternate() {
5284 write!(f, "0x")?;
5285 }
5286 write!(f, "{}", hex_string(self.as_slice()))
5287 }
5288}
5289impl<'r> ::core::fmt::Debug for GetBroadcastMessagesReader<'r> {
5290 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5291 write!(f, "{}({:#x})", Self::NAME, self)
5292 }
5293}
5294impl<'r> ::core::fmt::Display for GetBroadcastMessagesReader<'r> {
5295 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5296 write!(f, "{} {{ ", Self::NAME)?;
5297 write!(f, "{}: {}", "id", self.id())?;
5298 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
5299 write!(f, ", {}: {}", "after_cursor", self.after_cursor())?;
5300 write!(f, ", {}: {}", "count", self.count())?;
5301 write!(f, " }}")
5302 }
5303}
5304impl<'r> GetBroadcastMessagesReader<'r> {
5305 pub const TOTAL_SIZE: usize = 87;
5306 pub const FIELD_SIZES: [usize; 4] = [8, 32, 45, 2];
5307 pub const FIELD_COUNT: usize = 4;
5308 pub fn id(&self) -> Uint64Reader<'r> {
5309 Uint64Reader::new_unchecked(&self.as_slice()[0..8])
5310 }
5311 pub fn chain_hash(&self) -> Byte32Reader<'r> {
5312 Byte32Reader::new_unchecked(&self.as_slice()[8..40])
5313 }
5314 pub fn after_cursor(&self) -> CursorReader<'r> {
5315 CursorReader::new_unchecked(&self.as_slice()[40..85])
5316 }
5317 pub fn count(&self) -> Uint16Reader<'r> {
5318 Uint16Reader::new_unchecked(&self.as_slice()[85..87])
5319 }
5320}
5321impl<'r> molecule::prelude::Reader<'r> for GetBroadcastMessagesReader<'r> {
5322 type Entity = GetBroadcastMessages;
5323 const NAME: &'static str = "GetBroadcastMessagesReader";
5324 fn to_entity(&self) -> Self::Entity {
5325 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5326 }
5327 fn new_unchecked(slice: &'r [u8]) -> Self {
5328 GetBroadcastMessagesReader(slice)
5329 }
5330 fn as_slice(&self) -> &'r [u8] {
5331 self.0
5332 }
5333 fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
5334 use molecule::verification_error as ve;
5335 let slice_len = slice.len();
5336 if slice_len != Self::TOTAL_SIZE {
5337 return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
5338 }
5339 Ok(())
5340 }
5341}
5342#[derive(Clone, Debug, Default)]
5343pub struct GetBroadcastMessagesBuilder {
5344 pub(crate) id: Uint64,
5345 pub(crate) chain_hash: Byte32,
5346 pub(crate) after_cursor: Cursor,
5347 pub(crate) count: Uint16,
5348}
5349impl GetBroadcastMessagesBuilder {
5350 pub const TOTAL_SIZE: usize = 87;
5351 pub const FIELD_SIZES: [usize; 4] = [8, 32, 45, 2];
5352 pub const FIELD_COUNT: usize = 4;
5353 pub fn id(mut self, v: Uint64) -> Self {
5354 self.id = v;
5355 self
5356 }
5357 pub fn chain_hash(mut self, v: Byte32) -> Self {
5358 self.chain_hash = v;
5359 self
5360 }
5361 pub fn after_cursor(mut self, v: Cursor) -> Self {
5362 self.after_cursor = v;
5363 self
5364 }
5365 pub fn count(mut self, v: Uint16) -> Self {
5366 self.count = v;
5367 self
5368 }
5369}
5370impl molecule::prelude::Builder for GetBroadcastMessagesBuilder {
5371 type Entity = GetBroadcastMessages;
5372 const NAME: &'static str = "GetBroadcastMessagesBuilder";
5373 fn expected_length(&self) -> usize {
5374 Self::TOTAL_SIZE
5375 }
5376 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5377 writer.write_all(self.id.as_slice())?;
5378 writer.write_all(self.chain_hash.as_slice())?;
5379 writer.write_all(self.after_cursor.as_slice())?;
5380 writer.write_all(self.count.as_slice())?;
5381 Ok(())
5382 }
5383 fn build(&self) -> Self::Entity {
5384 let mut inner = Vec::with_capacity(self.expected_length());
5385 self.write(&mut inner)
5386 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5387 GetBroadcastMessages::new_unchecked(inner.into())
5388 }
5389}
5390#[derive(Clone)]
5391pub struct QueryBroadcastMessages(molecule::bytes::Bytes);
5392impl ::core::fmt::LowerHex for QueryBroadcastMessages {
5393 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5394 use molecule::hex_string;
5395 if f.alternate() {
5396 write!(f, "0x")?;
5397 }
5398 write!(f, "{}", hex_string(self.as_slice()))
5399 }
5400}
5401impl ::core::fmt::Debug for QueryBroadcastMessages {
5402 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5403 write!(f, "{}({:#x})", Self::NAME, self)
5404 }
5405}
5406impl ::core::fmt::Display for QueryBroadcastMessages {
5407 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5408 write!(f, "{} {{ ", Self::NAME)?;
5409 write!(f, "{}: {}", "id", self.id())?;
5410 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
5411 write!(f, ", {}: {}", "queries", self.queries())?;
5412 let extra_count = self.count_extra_fields();
5413 if extra_count != 0 {
5414 write!(f, ", .. ({} fields)", extra_count)?;
5415 }
5416 write!(f, " }}")
5417 }
5418}
5419impl ::core::default::Default for QueryBroadcastMessages {
5420 fn default() -> Self {
5421 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5422 QueryBroadcastMessages::new_unchecked(v)
5423 }
5424}
5425impl QueryBroadcastMessages {
5426 const DEFAULT_VALUE: [u8; 60] = [
5427 60, 0, 0, 0, 16, 0, 0, 0, 24, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5428 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5429 0,
5430 ];
5431 pub const FIELD_COUNT: usize = 3;
5432 pub fn total_size(&self) -> usize {
5433 molecule::unpack_number(self.as_slice()) as usize
5434 }
5435 pub fn field_count(&self) -> usize {
5436 if self.total_size() == molecule::NUMBER_SIZE {
5437 0
5438 } else {
5439 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5440 }
5441 }
5442 pub fn count_extra_fields(&self) -> usize {
5443 self.field_count() - Self::FIELD_COUNT
5444 }
5445 pub fn has_extra_fields(&self) -> bool {
5446 Self::FIELD_COUNT != self.field_count()
5447 }
5448 pub fn id(&self) -> Uint64 {
5449 let slice = self.as_slice();
5450 let start = molecule::unpack_number(&slice[4..]) as usize;
5451 let end = molecule::unpack_number(&slice[8..]) as usize;
5452 Uint64::new_unchecked(self.0.slice(start..end))
5453 }
5454 pub fn chain_hash(&self) -> Byte32 {
5455 let slice = self.as_slice();
5456 let start = molecule::unpack_number(&slice[8..]) as usize;
5457 let end = molecule::unpack_number(&slice[12..]) as usize;
5458 Byte32::new_unchecked(self.0.slice(start..end))
5459 }
5460 pub fn queries(&self) -> BroadcastMessageQueries {
5461 let slice = self.as_slice();
5462 let start = molecule::unpack_number(&slice[12..]) as usize;
5463 if self.has_extra_fields() {
5464 let end = molecule::unpack_number(&slice[16..]) as usize;
5465 BroadcastMessageQueries::new_unchecked(self.0.slice(start..end))
5466 } else {
5467 BroadcastMessageQueries::new_unchecked(self.0.slice(start..))
5468 }
5469 }
5470 pub fn as_reader<'r>(&'r self) -> QueryBroadcastMessagesReader<'r> {
5471 QueryBroadcastMessagesReader::new_unchecked(self.as_slice())
5472 }
5473}
5474impl molecule::prelude::Entity for QueryBroadcastMessages {
5475 type Builder = QueryBroadcastMessagesBuilder;
5476 const NAME: &'static str = "QueryBroadcastMessages";
5477 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5478 QueryBroadcastMessages(data)
5479 }
5480 fn as_bytes(&self) -> molecule::bytes::Bytes {
5481 self.0.clone()
5482 }
5483 fn as_slice(&self) -> &[u8] {
5484 &self.0[..]
5485 }
5486 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5487 QueryBroadcastMessagesReader::from_slice(slice).map(|reader| reader.to_entity())
5488 }
5489 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5490 QueryBroadcastMessagesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5491 }
5492 fn new_builder() -> Self::Builder {
5493 ::core::default::Default::default()
5494 }
5495 fn as_builder(self) -> Self::Builder {
5496 Self::new_builder()
5497 .id(self.id())
5498 .chain_hash(self.chain_hash())
5499 .queries(self.queries())
5500 }
5501}
5502#[derive(Clone, Copy)]
5503pub struct QueryBroadcastMessagesReader<'r>(&'r [u8]);
5504impl<'r> ::core::fmt::LowerHex for QueryBroadcastMessagesReader<'r> {
5505 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5506 use molecule::hex_string;
5507 if f.alternate() {
5508 write!(f, "0x")?;
5509 }
5510 write!(f, "{}", hex_string(self.as_slice()))
5511 }
5512}
5513impl<'r> ::core::fmt::Debug for QueryBroadcastMessagesReader<'r> {
5514 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5515 write!(f, "{}({:#x})", Self::NAME, self)
5516 }
5517}
5518impl<'r> ::core::fmt::Display for QueryBroadcastMessagesReader<'r> {
5519 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5520 write!(f, "{} {{ ", Self::NAME)?;
5521 write!(f, "{}: {}", "id", self.id())?;
5522 write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
5523 write!(f, ", {}: {}", "queries", self.queries())?;
5524 let extra_count = self.count_extra_fields();
5525 if extra_count != 0 {
5526 write!(f, ", .. ({} fields)", extra_count)?;
5527 }
5528 write!(f, " }}")
5529 }
5530}
5531impl<'r> QueryBroadcastMessagesReader<'r> {
5532 pub const FIELD_COUNT: usize = 3;
5533 pub fn total_size(&self) -> usize {
5534 molecule::unpack_number(self.as_slice()) as usize
5535 }
5536 pub fn field_count(&self) -> usize {
5537 if self.total_size() == molecule::NUMBER_SIZE {
5538 0
5539 } else {
5540 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5541 }
5542 }
5543 pub fn count_extra_fields(&self) -> usize {
5544 self.field_count() - Self::FIELD_COUNT
5545 }
5546 pub fn has_extra_fields(&self) -> bool {
5547 Self::FIELD_COUNT != self.field_count()
5548 }
5549 pub fn id(&self) -> Uint64Reader<'r> {
5550 let slice = self.as_slice();
5551 let start = molecule::unpack_number(&slice[4..]) as usize;
5552 let end = molecule::unpack_number(&slice[8..]) as usize;
5553 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5554 }
5555 pub fn chain_hash(&self) -> Byte32Reader<'r> {
5556 let slice = self.as_slice();
5557 let start = molecule::unpack_number(&slice[8..]) as usize;
5558 let end = molecule::unpack_number(&slice[12..]) as usize;
5559 Byte32Reader::new_unchecked(&self.as_slice()[start..end])
5560 }
5561 pub fn queries(&self) -> BroadcastMessageQueriesReader<'r> {
5562 let slice = self.as_slice();
5563 let start = molecule::unpack_number(&slice[12..]) as usize;
5564 if self.has_extra_fields() {
5565 let end = molecule::unpack_number(&slice[16..]) as usize;
5566 BroadcastMessageQueriesReader::new_unchecked(&self.as_slice()[start..end])
5567 } else {
5568 BroadcastMessageQueriesReader::new_unchecked(&self.as_slice()[start..])
5569 }
5570 }
5571}
5572impl<'r> molecule::prelude::Reader<'r> for QueryBroadcastMessagesReader<'r> {
5573 type Entity = QueryBroadcastMessages;
5574 const NAME: &'static str = "QueryBroadcastMessagesReader";
5575 fn to_entity(&self) -> Self::Entity {
5576 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5577 }
5578 fn new_unchecked(slice: &'r [u8]) -> Self {
5579 QueryBroadcastMessagesReader(slice)
5580 }
5581 fn as_slice(&self) -> &'r [u8] {
5582 self.0
5583 }
5584 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
5585 use molecule::verification_error as ve;
5586 let slice_len = slice.len();
5587 if slice_len < molecule::NUMBER_SIZE {
5588 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
5589 }
5590 let total_size = molecule::unpack_number(slice) as usize;
5591 if slice_len != total_size {
5592 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
5593 }
5594 if slice_len < molecule::NUMBER_SIZE * 2 {
5595 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
5596 }
5597 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
5598 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
5599 return ve!(Self, OffsetsNotMatch);
5600 }
5601 if slice_len < offset_first {
5602 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
5603 }
5604 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
5605 if field_count < Self::FIELD_COUNT {
5606 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5607 } else if !compatible && field_count > Self::FIELD_COUNT {
5608 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5609 };
5610 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
5611 .chunks_exact(molecule::NUMBER_SIZE)
5612 .map(|x| molecule::unpack_number(x) as usize)
5613 .collect();
5614 offsets.push(total_size);
5615 if offsets.windows(2).any(|i| i[0] > i[1]) {
5616 return ve!(Self, OffsetsNotMatch);
5617 }
5618 Uint64Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
5619 Byte32Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
5620 BroadcastMessageQueriesReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
5621 Ok(())
5622 }
5623}
5624#[derive(Clone, Debug, Default)]
5625pub struct QueryBroadcastMessagesBuilder {
5626 pub(crate) id: Uint64,
5627 pub(crate) chain_hash: Byte32,
5628 pub(crate) queries: BroadcastMessageQueries,
5629}
5630impl QueryBroadcastMessagesBuilder {
5631 pub const FIELD_COUNT: usize = 3;
5632 pub fn id(mut self, v: Uint64) -> Self {
5633 self.id = v;
5634 self
5635 }
5636 pub fn chain_hash(mut self, v: Byte32) -> Self {
5637 self.chain_hash = v;
5638 self
5639 }
5640 pub fn queries(mut self, v: BroadcastMessageQueries) -> Self {
5641 self.queries = v;
5642 self
5643 }
5644}
5645impl molecule::prelude::Builder for QueryBroadcastMessagesBuilder {
5646 type Entity = QueryBroadcastMessages;
5647 const NAME: &'static str = "QueryBroadcastMessagesBuilder";
5648 fn expected_length(&self) -> usize {
5649 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
5650 + self.id.as_slice().len()
5651 + self.chain_hash.as_slice().len()
5652 + self.queries.as_slice().len()
5653 }
5654 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5655 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
5656 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
5657 offsets.push(total_size);
5658 total_size += self.id.as_slice().len();
5659 offsets.push(total_size);
5660 total_size += self.chain_hash.as_slice().len();
5661 offsets.push(total_size);
5662 total_size += self.queries.as_slice().len();
5663 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
5664 for offset in offsets.into_iter() {
5665 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
5666 }
5667 writer.write_all(self.id.as_slice())?;
5668 writer.write_all(self.chain_hash.as_slice())?;
5669 writer.write_all(self.queries.as_slice())?;
5670 Ok(())
5671 }
5672 fn build(&self) -> Self::Entity {
5673 let mut inner = Vec::with_capacity(self.expected_length());
5674 self.write(&mut inner)
5675 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5676 QueryBroadcastMessages::new_unchecked(inner.into())
5677 }
5678}
5679#[derive(Clone)]
5680pub struct BroadcastMessagesFilterResult(molecule::bytes::Bytes);
5681impl ::core::fmt::LowerHex for BroadcastMessagesFilterResult {
5682 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5683 use molecule::hex_string;
5684 if f.alternate() {
5685 write!(f, "0x")?;
5686 }
5687 write!(f, "{}", hex_string(self.as_slice()))
5688 }
5689}
5690impl ::core::fmt::Debug for BroadcastMessagesFilterResult {
5691 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5692 write!(f, "{}({:#x})", Self::NAME, self)
5693 }
5694}
5695impl ::core::fmt::Display for BroadcastMessagesFilterResult {
5696 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5697 write!(f, "{} {{ ", Self::NAME)?;
5698 write!(f, "{}: {}", "messages", self.messages())?;
5699 let extra_count = self.count_extra_fields();
5700 if extra_count != 0 {
5701 write!(f, ", .. ({} fields)", extra_count)?;
5702 }
5703 write!(f, " }}")
5704 }
5705}
5706impl ::core::default::Default for BroadcastMessagesFilterResult {
5707 fn default() -> Self {
5708 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5709 BroadcastMessagesFilterResult::new_unchecked(v)
5710 }
5711}
5712impl BroadcastMessagesFilterResult {
5713 const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 4, 0, 0, 0];
5714 pub const FIELD_COUNT: usize = 1;
5715 pub fn total_size(&self) -> usize {
5716 molecule::unpack_number(self.as_slice()) as usize
5717 }
5718 pub fn field_count(&self) -> usize {
5719 if self.total_size() == molecule::NUMBER_SIZE {
5720 0
5721 } else {
5722 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5723 }
5724 }
5725 pub fn count_extra_fields(&self) -> usize {
5726 self.field_count() - Self::FIELD_COUNT
5727 }
5728 pub fn has_extra_fields(&self) -> bool {
5729 Self::FIELD_COUNT != self.field_count()
5730 }
5731 pub fn messages(&self) -> BroadcastMessages {
5732 let slice = self.as_slice();
5733 let start = molecule::unpack_number(&slice[4..]) as usize;
5734 if self.has_extra_fields() {
5735 let end = molecule::unpack_number(&slice[8..]) as usize;
5736 BroadcastMessages::new_unchecked(self.0.slice(start..end))
5737 } else {
5738 BroadcastMessages::new_unchecked(self.0.slice(start..))
5739 }
5740 }
5741 pub fn as_reader<'r>(&'r self) -> BroadcastMessagesFilterResultReader<'r> {
5742 BroadcastMessagesFilterResultReader::new_unchecked(self.as_slice())
5743 }
5744}
5745impl molecule::prelude::Entity for BroadcastMessagesFilterResult {
5746 type Builder = BroadcastMessagesFilterResultBuilder;
5747 const NAME: &'static str = "BroadcastMessagesFilterResult";
5748 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5749 BroadcastMessagesFilterResult(data)
5750 }
5751 fn as_bytes(&self) -> molecule::bytes::Bytes {
5752 self.0.clone()
5753 }
5754 fn as_slice(&self) -> &[u8] {
5755 &self.0[..]
5756 }
5757 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5758 BroadcastMessagesFilterResultReader::from_slice(slice).map(|reader| reader.to_entity())
5759 }
5760 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5761 BroadcastMessagesFilterResultReader::from_compatible_slice(slice)
5762 .map(|reader| reader.to_entity())
5763 }
5764 fn new_builder() -> Self::Builder {
5765 ::core::default::Default::default()
5766 }
5767 fn as_builder(self) -> Self::Builder {
5768 Self::new_builder().messages(self.messages())
5769 }
5770}
5771#[derive(Clone, Copy)]
5772pub struct BroadcastMessagesFilterResultReader<'r>(&'r [u8]);
5773impl<'r> ::core::fmt::LowerHex for BroadcastMessagesFilterResultReader<'r> {
5774 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5775 use molecule::hex_string;
5776 if f.alternate() {
5777 write!(f, "0x")?;
5778 }
5779 write!(f, "{}", hex_string(self.as_slice()))
5780 }
5781}
5782impl<'r> ::core::fmt::Debug for BroadcastMessagesFilterResultReader<'r> {
5783 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5784 write!(f, "{}({:#x})", Self::NAME, self)
5785 }
5786}
5787impl<'r> ::core::fmt::Display for BroadcastMessagesFilterResultReader<'r> {
5788 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5789 write!(f, "{} {{ ", Self::NAME)?;
5790 write!(f, "{}: {}", "messages", self.messages())?;
5791 let extra_count = self.count_extra_fields();
5792 if extra_count != 0 {
5793 write!(f, ", .. ({} fields)", extra_count)?;
5794 }
5795 write!(f, " }}")
5796 }
5797}
5798impl<'r> BroadcastMessagesFilterResultReader<'r> {
5799 pub const FIELD_COUNT: usize = 1;
5800 pub fn total_size(&self) -> usize {
5801 molecule::unpack_number(self.as_slice()) as usize
5802 }
5803 pub fn field_count(&self) -> usize {
5804 if self.total_size() == molecule::NUMBER_SIZE {
5805 0
5806 } else {
5807 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5808 }
5809 }
5810 pub fn count_extra_fields(&self) -> usize {
5811 self.field_count() - Self::FIELD_COUNT
5812 }
5813 pub fn has_extra_fields(&self) -> bool {
5814 Self::FIELD_COUNT != self.field_count()
5815 }
5816 pub fn messages(&self) -> BroadcastMessagesReader<'r> {
5817 let slice = self.as_slice();
5818 let start = molecule::unpack_number(&slice[4..]) as usize;
5819 if self.has_extra_fields() {
5820 let end = molecule::unpack_number(&slice[8..]) as usize;
5821 BroadcastMessagesReader::new_unchecked(&self.as_slice()[start..end])
5822 } else {
5823 BroadcastMessagesReader::new_unchecked(&self.as_slice()[start..])
5824 }
5825 }
5826}
5827impl<'r> molecule::prelude::Reader<'r> for BroadcastMessagesFilterResultReader<'r> {
5828 type Entity = BroadcastMessagesFilterResult;
5829 const NAME: &'static str = "BroadcastMessagesFilterResultReader";
5830 fn to_entity(&self) -> Self::Entity {
5831 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5832 }
5833 fn new_unchecked(slice: &'r [u8]) -> Self {
5834 BroadcastMessagesFilterResultReader(slice)
5835 }
5836 fn as_slice(&self) -> &'r [u8] {
5837 self.0
5838 }
5839 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
5840 use molecule::verification_error as ve;
5841 let slice_len = slice.len();
5842 if slice_len < molecule::NUMBER_SIZE {
5843 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
5844 }
5845 let total_size = molecule::unpack_number(slice) as usize;
5846 if slice_len != total_size {
5847 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
5848 }
5849 if slice_len < molecule::NUMBER_SIZE * 2 {
5850 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
5851 }
5852 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
5853 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
5854 return ve!(Self, OffsetsNotMatch);
5855 }
5856 if slice_len < offset_first {
5857 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
5858 }
5859 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
5860 if field_count < Self::FIELD_COUNT {
5861 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5862 } else if !compatible && field_count > Self::FIELD_COUNT {
5863 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5864 };
5865 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
5866 .chunks_exact(molecule::NUMBER_SIZE)
5867 .map(|x| molecule::unpack_number(x) as usize)
5868 .collect();
5869 offsets.push(total_size);
5870 if offsets.windows(2).any(|i| i[0] > i[1]) {
5871 return ve!(Self, OffsetsNotMatch);
5872 }
5873 BroadcastMessagesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
5874 Ok(())
5875 }
5876}
5877#[derive(Clone, Debug, Default)]
5878pub struct BroadcastMessagesFilterResultBuilder {
5879 pub(crate) messages: BroadcastMessages,
5880}
5881impl BroadcastMessagesFilterResultBuilder {
5882 pub const FIELD_COUNT: usize = 1;
5883 pub fn messages(mut self, v: BroadcastMessages) -> Self {
5884 self.messages = v;
5885 self
5886 }
5887}
5888impl molecule::prelude::Builder for BroadcastMessagesFilterResultBuilder {
5889 type Entity = BroadcastMessagesFilterResult;
5890 const NAME: &'static str = "BroadcastMessagesFilterResultBuilder";
5891 fn expected_length(&self) -> usize {
5892 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.messages.as_slice().len()
5893 }
5894 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5895 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
5896 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
5897 offsets.push(total_size);
5898 total_size += self.messages.as_slice().len();
5899 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
5900 for offset in offsets.into_iter() {
5901 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
5902 }
5903 writer.write_all(self.messages.as_slice())?;
5904 Ok(())
5905 }
5906 fn build(&self) -> Self::Entity {
5907 let mut inner = Vec::with_capacity(self.expected_length());
5908 self.write(&mut inner)
5909 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5910 BroadcastMessagesFilterResult::new_unchecked(inner.into())
5911 }
5912}
5913#[derive(Clone)]
5914pub struct GetBroadcastMessagesResult(molecule::bytes::Bytes);
5915impl ::core::fmt::LowerHex for GetBroadcastMessagesResult {
5916 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5917 use molecule::hex_string;
5918 if f.alternate() {
5919 write!(f, "0x")?;
5920 }
5921 write!(f, "{}", hex_string(self.as_slice()))
5922 }
5923}
5924impl ::core::fmt::Debug for GetBroadcastMessagesResult {
5925 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5926 write!(f, "{}({:#x})", Self::NAME, self)
5927 }
5928}
5929impl ::core::fmt::Display for GetBroadcastMessagesResult {
5930 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5931 write!(f, "{} {{ ", Self::NAME)?;
5932 write!(f, "{}: {}", "id", self.id())?;
5933 write!(f, ", {}: {}", "messages", self.messages())?;
5934 let extra_count = self.count_extra_fields();
5935 if extra_count != 0 {
5936 write!(f, ", .. ({} fields)", extra_count)?;
5937 }
5938 write!(f, " }}")
5939 }
5940}
5941impl ::core::default::Default for GetBroadcastMessagesResult {
5942 fn default() -> Self {
5943 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5944 GetBroadcastMessagesResult::new_unchecked(v)
5945 }
5946}
5947impl GetBroadcastMessagesResult {
5948 const DEFAULT_VALUE: [u8; 24] = [
5949 24, 0, 0, 0, 12, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
5950 ];
5951 pub const FIELD_COUNT: usize = 2;
5952 pub fn total_size(&self) -> usize {
5953 molecule::unpack_number(self.as_slice()) as usize
5954 }
5955 pub fn field_count(&self) -> usize {
5956 if self.total_size() == molecule::NUMBER_SIZE {
5957 0
5958 } else {
5959 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5960 }
5961 }
5962 pub fn count_extra_fields(&self) -> usize {
5963 self.field_count() - Self::FIELD_COUNT
5964 }
5965 pub fn has_extra_fields(&self) -> bool {
5966 Self::FIELD_COUNT != self.field_count()
5967 }
5968 pub fn id(&self) -> Uint64 {
5969 let slice = self.as_slice();
5970 let start = molecule::unpack_number(&slice[4..]) as usize;
5971 let end = molecule::unpack_number(&slice[8..]) as usize;
5972 Uint64::new_unchecked(self.0.slice(start..end))
5973 }
5974 pub fn messages(&self) -> BroadcastMessages {
5975 let slice = self.as_slice();
5976 let start = molecule::unpack_number(&slice[8..]) as usize;
5977 if self.has_extra_fields() {
5978 let end = molecule::unpack_number(&slice[12..]) as usize;
5979 BroadcastMessages::new_unchecked(self.0.slice(start..end))
5980 } else {
5981 BroadcastMessages::new_unchecked(self.0.slice(start..))
5982 }
5983 }
5984 pub fn as_reader<'r>(&'r self) -> GetBroadcastMessagesResultReader<'r> {
5985 GetBroadcastMessagesResultReader::new_unchecked(self.as_slice())
5986 }
5987}
5988impl molecule::prelude::Entity for GetBroadcastMessagesResult {
5989 type Builder = GetBroadcastMessagesResultBuilder;
5990 const NAME: &'static str = "GetBroadcastMessagesResult";
5991 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5992 GetBroadcastMessagesResult(data)
5993 }
5994 fn as_bytes(&self) -> molecule::bytes::Bytes {
5995 self.0.clone()
5996 }
5997 fn as_slice(&self) -> &[u8] {
5998 &self.0[..]
5999 }
6000 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6001 GetBroadcastMessagesResultReader::from_slice(slice).map(|reader| reader.to_entity())
6002 }
6003 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6004 GetBroadcastMessagesResultReader::from_compatible_slice(slice)
6005 .map(|reader| reader.to_entity())
6006 }
6007 fn new_builder() -> Self::Builder {
6008 ::core::default::Default::default()
6009 }
6010 fn as_builder(self) -> Self::Builder {
6011 Self::new_builder().id(self.id()).messages(self.messages())
6012 }
6013}
6014#[derive(Clone, Copy)]
6015pub struct GetBroadcastMessagesResultReader<'r>(&'r [u8]);
6016impl<'r> ::core::fmt::LowerHex for GetBroadcastMessagesResultReader<'r> {
6017 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6018 use molecule::hex_string;
6019 if f.alternate() {
6020 write!(f, "0x")?;
6021 }
6022 write!(f, "{}", hex_string(self.as_slice()))
6023 }
6024}
6025impl<'r> ::core::fmt::Debug for GetBroadcastMessagesResultReader<'r> {
6026 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6027 write!(f, "{}({:#x})", Self::NAME, self)
6028 }
6029}
6030impl<'r> ::core::fmt::Display for GetBroadcastMessagesResultReader<'r> {
6031 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6032 write!(f, "{} {{ ", Self::NAME)?;
6033 write!(f, "{}: {}", "id", self.id())?;
6034 write!(f, ", {}: {}", "messages", self.messages())?;
6035 let extra_count = self.count_extra_fields();
6036 if extra_count != 0 {
6037 write!(f, ", .. ({} fields)", extra_count)?;
6038 }
6039 write!(f, " }}")
6040 }
6041}
6042impl<'r> GetBroadcastMessagesResultReader<'r> {
6043 pub const FIELD_COUNT: usize = 2;
6044 pub fn total_size(&self) -> usize {
6045 molecule::unpack_number(self.as_slice()) as usize
6046 }
6047 pub fn field_count(&self) -> usize {
6048 if self.total_size() == molecule::NUMBER_SIZE {
6049 0
6050 } else {
6051 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6052 }
6053 }
6054 pub fn count_extra_fields(&self) -> usize {
6055 self.field_count() - Self::FIELD_COUNT
6056 }
6057 pub fn has_extra_fields(&self) -> bool {
6058 Self::FIELD_COUNT != self.field_count()
6059 }
6060 pub fn id(&self) -> Uint64Reader<'r> {
6061 let slice = self.as_slice();
6062 let start = molecule::unpack_number(&slice[4..]) as usize;
6063 let end = molecule::unpack_number(&slice[8..]) as usize;
6064 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
6065 }
6066 pub fn messages(&self) -> BroadcastMessagesReader<'r> {
6067 let slice = self.as_slice();
6068 let start = molecule::unpack_number(&slice[8..]) as usize;
6069 if self.has_extra_fields() {
6070 let end = molecule::unpack_number(&slice[12..]) as usize;
6071 BroadcastMessagesReader::new_unchecked(&self.as_slice()[start..end])
6072 } else {
6073 BroadcastMessagesReader::new_unchecked(&self.as_slice()[start..])
6074 }
6075 }
6076}
6077impl<'r> molecule::prelude::Reader<'r> for GetBroadcastMessagesResultReader<'r> {
6078 type Entity = GetBroadcastMessagesResult;
6079 const NAME: &'static str = "GetBroadcastMessagesResultReader";
6080 fn to_entity(&self) -> Self::Entity {
6081 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6082 }
6083 fn new_unchecked(slice: &'r [u8]) -> Self {
6084 GetBroadcastMessagesResultReader(slice)
6085 }
6086 fn as_slice(&self) -> &'r [u8] {
6087 self.0
6088 }
6089 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6090 use molecule::verification_error as ve;
6091 let slice_len = slice.len();
6092 if slice_len < molecule::NUMBER_SIZE {
6093 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6094 }
6095 let total_size = molecule::unpack_number(slice) as usize;
6096 if slice_len != total_size {
6097 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
6098 }
6099 if slice_len < molecule::NUMBER_SIZE * 2 {
6100 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
6101 }
6102 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
6103 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
6104 return ve!(Self, OffsetsNotMatch);
6105 }
6106 if slice_len < offset_first {
6107 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
6108 }
6109 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
6110 if field_count < Self::FIELD_COUNT {
6111 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6112 } else if !compatible && field_count > Self::FIELD_COUNT {
6113 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6114 };
6115 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
6116 .chunks_exact(molecule::NUMBER_SIZE)
6117 .map(|x| molecule::unpack_number(x) as usize)
6118 .collect();
6119 offsets.push(total_size);
6120 if offsets.windows(2).any(|i| i[0] > i[1]) {
6121 return ve!(Self, OffsetsNotMatch);
6122 }
6123 Uint64Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
6124 BroadcastMessagesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
6125 Ok(())
6126 }
6127}
6128#[derive(Clone, Debug, Default)]
6129pub struct GetBroadcastMessagesResultBuilder {
6130 pub(crate) id: Uint64,
6131 pub(crate) messages: BroadcastMessages,
6132}
6133impl GetBroadcastMessagesResultBuilder {
6134 pub const FIELD_COUNT: usize = 2;
6135 pub fn id(mut self, v: Uint64) -> Self {
6136 self.id = v;
6137 self
6138 }
6139 pub fn messages(mut self, v: BroadcastMessages) -> Self {
6140 self.messages = v;
6141 self
6142 }
6143}
6144impl molecule::prelude::Builder for GetBroadcastMessagesResultBuilder {
6145 type Entity = GetBroadcastMessagesResult;
6146 const NAME: &'static str = "GetBroadcastMessagesResultBuilder";
6147 fn expected_length(&self) -> usize {
6148 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
6149 + self.id.as_slice().len()
6150 + self.messages.as_slice().len()
6151 }
6152 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6153 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
6154 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
6155 offsets.push(total_size);
6156 total_size += self.id.as_slice().len();
6157 offsets.push(total_size);
6158 total_size += self.messages.as_slice().len();
6159 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
6160 for offset in offsets.into_iter() {
6161 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
6162 }
6163 writer.write_all(self.id.as_slice())?;
6164 writer.write_all(self.messages.as_slice())?;
6165 Ok(())
6166 }
6167 fn build(&self) -> Self::Entity {
6168 let mut inner = Vec::with_capacity(self.expected_length());
6169 self.write(&mut inner)
6170 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6171 GetBroadcastMessagesResult::new_unchecked(inner.into())
6172 }
6173}
6174#[derive(Clone)]
6175pub struct QueryBroadcastMessagesResult(molecule::bytes::Bytes);
6176impl ::core::fmt::LowerHex for QueryBroadcastMessagesResult {
6177 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6178 use molecule::hex_string;
6179 if f.alternate() {
6180 write!(f, "0x")?;
6181 }
6182 write!(f, "{}", hex_string(self.as_slice()))
6183 }
6184}
6185impl ::core::fmt::Debug for QueryBroadcastMessagesResult {
6186 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6187 write!(f, "{}({:#x})", Self::NAME, self)
6188 }
6189}
6190impl ::core::fmt::Display for QueryBroadcastMessagesResult {
6191 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6192 write!(f, "{} {{ ", Self::NAME)?;
6193 write!(f, "{}: {}", "id", self.id())?;
6194 write!(f, ", {}: {}", "messages", self.messages())?;
6195 write!(f, ", {}: {}", "missing_queries", self.missing_queries())?;
6196 let extra_count = self.count_extra_fields();
6197 if extra_count != 0 {
6198 write!(f, ", .. ({} fields)", extra_count)?;
6199 }
6200 write!(f, " }}")
6201 }
6202}
6203impl ::core::default::Default for QueryBroadcastMessagesResult {
6204 fn default() -> Self {
6205 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
6206 QueryBroadcastMessagesResult::new_unchecked(v)
6207 }
6208}
6209impl QueryBroadcastMessagesResult {
6210 const DEFAULT_VALUE: [u8; 32] = [
6211 32, 0, 0, 0, 16, 0, 0, 0, 24, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0,
6212 0, 0, 0,
6213 ];
6214 pub const FIELD_COUNT: usize = 3;
6215 pub fn total_size(&self) -> usize {
6216 molecule::unpack_number(self.as_slice()) as usize
6217 }
6218 pub fn field_count(&self) -> usize {
6219 if self.total_size() == molecule::NUMBER_SIZE {
6220 0
6221 } else {
6222 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6223 }
6224 }
6225 pub fn count_extra_fields(&self) -> usize {
6226 self.field_count() - Self::FIELD_COUNT
6227 }
6228 pub fn has_extra_fields(&self) -> bool {
6229 Self::FIELD_COUNT != self.field_count()
6230 }
6231 pub fn id(&self) -> Uint64 {
6232 let slice = self.as_slice();
6233 let start = molecule::unpack_number(&slice[4..]) as usize;
6234 let end = molecule::unpack_number(&slice[8..]) as usize;
6235 Uint64::new_unchecked(self.0.slice(start..end))
6236 }
6237 pub fn messages(&self) -> BroadcastMessages {
6238 let slice = self.as_slice();
6239 let start = molecule::unpack_number(&slice[8..]) as usize;
6240 let end = molecule::unpack_number(&slice[12..]) as usize;
6241 BroadcastMessages::new_unchecked(self.0.slice(start..end))
6242 }
6243 pub fn missing_queries(&self) -> MissingQueryIndexes {
6244 let slice = self.as_slice();
6245 let start = molecule::unpack_number(&slice[12..]) as usize;
6246 if self.has_extra_fields() {
6247 let end = molecule::unpack_number(&slice[16..]) as usize;
6248 MissingQueryIndexes::new_unchecked(self.0.slice(start..end))
6249 } else {
6250 MissingQueryIndexes::new_unchecked(self.0.slice(start..))
6251 }
6252 }
6253 pub fn as_reader<'r>(&'r self) -> QueryBroadcastMessagesResultReader<'r> {
6254 QueryBroadcastMessagesResultReader::new_unchecked(self.as_slice())
6255 }
6256}
6257impl molecule::prelude::Entity for QueryBroadcastMessagesResult {
6258 type Builder = QueryBroadcastMessagesResultBuilder;
6259 const NAME: &'static str = "QueryBroadcastMessagesResult";
6260 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
6261 QueryBroadcastMessagesResult(data)
6262 }
6263 fn as_bytes(&self) -> molecule::bytes::Bytes {
6264 self.0.clone()
6265 }
6266 fn as_slice(&self) -> &[u8] {
6267 &self.0[..]
6268 }
6269 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6270 QueryBroadcastMessagesResultReader::from_slice(slice).map(|reader| reader.to_entity())
6271 }
6272 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6273 QueryBroadcastMessagesResultReader::from_compatible_slice(slice)
6274 .map(|reader| reader.to_entity())
6275 }
6276 fn new_builder() -> Self::Builder {
6277 ::core::default::Default::default()
6278 }
6279 fn as_builder(self) -> Self::Builder {
6280 Self::new_builder()
6281 .id(self.id())
6282 .messages(self.messages())
6283 .missing_queries(self.missing_queries())
6284 }
6285}
6286#[derive(Clone, Copy)]
6287pub struct QueryBroadcastMessagesResultReader<'r>(&'r [u8]);
6288impl<'r> ::core::fmt::LowerHex for QueryBroadcastMessagesResultReader<'r> {
6289 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6290 use molecule::hex_string;
6291 if f.alternate() {
6292 write!(f, "0x")?;
6293 }
6294 write!(f, "{}", hex_string(self.as_slice()))
6295 }
6296}
6297impl<'r> ::core::fmt::Debug for QueryBroadcastMessagesResultReader<'r> {
6298 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6299 write!(f, "{}({:#x})", Self::NAME, self)
6300 }
6301}
6302impl<'r> ::core::fmt::Display for QueryBroadcastMessagesResultReader<'r> {
6303 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6304 write!(f, "{} {{ ", Self::NAME)?;
6305 write!(f, "{}: {}", "id", self.id())?;
6306 write!(f, ", {}: {}", "messages", self.messages())?;
6307 write!(f, ", {}: {}", "missing_queries", self.missing_queries())?;
6308 let extra_count = self.count_extra_fields();
6309 if extra_count != 0 {
6310 write!(f, ", .. ({} fields)", extra_count)?;
6311 }
6312 write!(f, " }}")
6313 }
6314}
6315impl<'r> QueryBroadcastMessagesResultReader<'r> {
6316 pub const FIELD_COUNT: usize = 3;
6317 pub fn total_size(&self) -> usize {
6318 molecule::unpack_number(self.as_slice()) as usize
6319 }
6320 pub fn field_count(&self) -> usize {
6321 if self.total_size() == molecule::NUMBER_SIZE {
6322 0
6323 } else {
6324 (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6325 }
6326 }
6327 pub fn count_extra_fields(&self) -> usize {
6328 self.field_count() - Self::FIELD_COUNT
6329 }
6330 pub fn has_extra_fields(&self) -> bool {
6331 Self::FIELD_COUNT != self.field_count()
6332 }
6333 pub fn id(&self) -> Uint64Reader<'r> {
6334 let slice = self.as_slice();
6335 let start = molecule::unpack_number(&slice[4..]) as usize;
6336 let end = molecule::unpack_number(&slice[8..]) as usize;
6337 Uint64Reader::new_unchecked(&self.as_slice()[start..end])
6338 }
6339 pub fn messages(&self) -> BroadcastMessagesReader<'r> {
6340 let slice = self.as_slice();
6341 let start = molecule::unpack_number(&slice[8..]) as usize;
6342 let end = molecule::unpack_number(&slice[12..]) as usize;
6343 BroadcastMessagesReader::new_unchecked(&self.as_slice()[start..end])
6344 }
6345 pub fn missing_queries(&self) -> MissingQueryIndexesReader<'r> {
6346 let slice = self.as_slice();
6347 let start = molecule::unpack_number(&slice[12..]) as usize;
6348 if self.has_extra_fields() {
6349 let end = molecule::unpack_number(&slice[16..]) as usize;
6350 MissingQueryIndexesReader::new_unchecked(&self.as_slice()[start..end])
6351 } else {
6352 MissingQueryIndexesReader::new_unchecked(&self.as_slice()[start..])
6353 }
6354 }
6355}
6356impl<'r> molecule::prelude::Reader<'r> for QueryBroadcastMessagesResultReader<'r> {
6357 type Entity = QueryBroadcastMessagesResult;
6358 const NAME: &'static str = "QueryBroadcastMessagesResultReader";
6359 fn to_entity(&self) -> Self::Entity {
6360 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6361 }
6362 fn new_unchecked(slice: &'r [u8]) -> Self {
6363 QueryBroadcastMessagesResultReader(slice)
6364 }
6365 fn as_slice(&self) -> &'r [u8] {
6366 self.0
6367 }
6368 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6369 use molecule::verification_error as ve;
6370 let slice_len = slice.len();
6371 if slice_len < molecule::NUMBER_SIZE {
6372 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6373 }
6374 let total_size = molecule::unpack_number(slice) as usize;
6375 if slice_len != total_size {
6376 return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
6377 }
6378 if slice_len < molecule::NUMBER_SIZE * 2 {
6379 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
6380 }
6381 let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
6382 if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
6383 return ve!(Self, OffsetsNotMatch);
6384 }
6385 if slice_len < offset_first {
6386 return ve!(Self, HeaderIsBroken, offset_first, slice_len);
6387 }
6388 let field_count = offset_first / molecule::NUMBER_SIZE - 1;
6389 if field_count < Self::FIELD_COUNT {
6390 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6391 } else if !compatible && field_count > Self::FIELD_COUNT {
6392 return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6393 };
6394 let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
6395 .chunks_exact(molecule::NUMBER_SIZE)
6396 .map(|x| molecule::unpack_number(x) as usize)
6397 .collect();
6398 offsets.push(total_size);
6399 if offsets.windows(2).any(|i| i[0] > i[1]) {
6400 return ve!(Self, OffsetsNotMatch);
6401 }
6402 Uint64Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
6403 BroadcastMessagesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
6404 MissingQueryIndexesReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
6405 Ok(())
6406 }
6407}
6408#[derive(Clone, Debug, Default)]
6409pub struct QueryBroadcastMessagesResultBuilder {
6410 pub(crate) id: Uint64,
6411 pub(crate) messages: BroadcastMessages,
6412 pub(crate) missing_queries: MissingQueryIndexes,
6413}
6414impl QueryBroadcastMessagesResultBuilder {
6415 pub const FIELD_COUNT: usize = 3;
6416 pub fn id(mut self, v: Uint64) -> Self {
6417 self.id = v;
6418 self
6419 }
6420 pub fn messages(mut self, v: BroadcastMessages) -> Self {
6421 self.messages = v;
6422 self
6423 }
6424 pub fn missing_queries(mut self, v: MissingQueryIndexes) -> Self {
6425 self.missing_queries = v;
6426 self
6427 }
6428}
6429impl molecule::prelude::Builder for QueryBroadcastMessagesResultBuilder {
6430 type Entity = QueryBroadcastMessagesResult;
6431 const NAME: &'static str = "QueryBroadcastMessagesResultBuilder";
6432 fn expected_length(&self) -> usize {
6433 molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
6434 + self.id.as_slice().len()
6435 + self.messages.as_slice().len()
6436 + self.missing_queries.as_slice().len()
6437 }
6438 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6439 let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
6440 let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
6441 offsets.push(total_size);
6442 total_size += self.id.as_slice().len();
6443 offsets.push(total_size);
6444 total_size += self.messages.as_slice().len();
6445 offsets.push(total_size);
6446 total_size += self.missing_queries.as_slice().len();
6447 writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
6448 for offset in offsets.into_iter() {
6449 writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
6450 }
6451 writer.write_all(self.id.as_slice())?;
6452 writer.write_all(self.messages.as_slice())?;
6453 writer.write_all(self.missing_queries.as_slice())?;
6454 Ok(())
6455 }
6456 fn build(&self) -> Self::Entity {
6457 let mut inner = Vec::with_capacity(self.expected_length());
6458 self.write(&mut inner)
6459 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6460 QueryBroadcastMessagesResult::new_unchecked(inner.into())
6461 }
6462}
6463#[derive(Clone)]
6464pub struct GossipMessage(molecule::bytes::Bytes);
6465impl ::core::fmt::LowerHex for GossipMessage {
6466 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6467 use molecule::hex_string;
6468 if f.alternate() {
6469 write!(f, "0x")?;
6470 }
6471 write!(f, "{}", hex_string(self.as_slice()))
6472 }
6473}
6474impl ::core::fmt::Debug for GossipMessage {
6475 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6476 write!(f, "{}({:#x})", Self::NAME, self)
6477 }
6478}
6479impl ::core::fmt::Display for GossipMessage {
6480 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6481 write!(f, "{}(", Self::NAME)?;
6482 self.to_enum().display_inner(f)?;
6483 write!(f, ")")
6484 }
6485}
6486impl ::core::default::Default for GossipMessage {
6487 fn default() -> Self {
6488 let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
6489 GossipMessage::new_unchecked(v)
6490 }
6491}
6492impl GossipMessage {
6493 const DEFAULT_VALUE: [u8; 81] = [
6494 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6495 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6496 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6497 ];
6498 pub const ITEMS_COUNT: usize = 6;
6499 pub fn item_id(&self) -> molecule::Number {
6500 molecule::unpack_number(self.as_slice())
6501 }
6502 pub fn to_enum(&self) -> GossipMessageUnion {
6503 let inner = self.0.slice(molecule::NUMBER_SIZE..);
6504 match self.item_id() {
6505 0 => BroadcastMessagesFilter::new_unchecked(inner).into(),
6506 1 => BroadcastMessagesFilterResult::new_unchecked(inner).into(),
6507 2 => GetBroadcastMessages::new_unchecked(inner).into(),
6508 3 => GetBroadcastMessagesResult::new_unchecked(inner).into(),
6509 4 => QueryBroadcastMessages::new_unchecked(inner).into(),
6510 5 => QueryBroadcastMessagesResult::new_unchecked(inner).into(),
6511 _ => panic!("{}: invalid data", Self::NAME),
6512 }
6513 }
6514 pub fn as_reader<'r>(&'r self) -> GossipMessageReader<'r> {
6515 GossipMessageReader::new_unchecked(self.as_slice())
6516 }
6517}
6518impl molecule::prelude::Entity for GossipMessage {
6519 type Builder = GossipMessageBuilder;
6520 const NAME: &'static str = "GossipMessage";
6521 fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
6522 GossipMessage(data)
6523 }
6524 fn as_bytes(&self) -> molecule::bytes::Bytes {
6525 self.0.clone()
6526 }
6527 fn as_slice(&self) -> &[u8] {
6528 &self.0[..]
6529 }
6530 fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6531 GossipMessageReader::from_slice(slice).map(|reader| reader.to_entity())
6532 }
6533 fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6534 GossipMessageReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
6535 }
6536 fn new_builder() -> Self::Builder {
6537 ::core::default::Default::default()
6538 }
6539 fn as_builder(self) -> Self::Builder {
6540 Self::new_builder().set(self.to_enum())
6541 }
6542}
6543#[derive(Clone, Copy)]
6544pub struct GossipMessageReader<'r>(&'r [u8]);
6545impl<'r> ::core::fmt::LowerHex for GossipMessageReader<'r> {
6546 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6547 use molecule::hex_string;
6548 if f.alternate() {
6549 write!(f, "0x")?;
6550 }
6551 write!(f, "{}", hex_string(self.as_slice()))
6552 }
6553}
6554impl<'r> ::core::fmt::Debug for GossipMessageReader<'r> {
6555 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6556 write!(f, "{}({:#x})", Self::NAME, self)
6557 }
6558}
6559impl<'r> ::core::fmt::Display for GossipMessageReader<'r> {
6560 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6561 write!(f, "{}(", Self::NAME)?;
6562 self.to_enum().display_inner(f)?;
6563 write!(f, ")")
6564 }
6565}
6566impl<'r> GossipMessageReader<'r> {
6567 pub const ITEMS_COUNT: usize = 6;
6568 pub fn item_id(&self) -> molecule::Number {
6569 molecule::unpack_number(self.as_slice())
6570 }
6571 pub fn to_enum(&self) -> GossipMessageUnionReader<'r> {
6572 let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
6573 match self.item_id() {
6574 0 => BroadcastMessagesFilterReader::new_unchecked(inner).into(),
6575 1 => BroadcastMessagesFilterResultReader::new_unchecked(inner).into(),
6576 2 => GetBroadcastMessagesReader::new_unchecked(inner).into(),
6577 3 => GetBroadcastMessagesResultReader::new_unchecked(inner).into(),
6578 4 => QueryBroadcastMessagesReader::new_unchecked(inner).into(),
6579 5 => QueryBroadcastMessagesResultReader::new_unchecked(inner).into(),
6580 _ => panic!("{}: invalid data", Self::NAME),
6581 }
6582 }
6583}
6584impl<'r> molecule::prelude::Reader<'r> for GossipMessageReader<'r> {
6585 type Entity = GossipMessage;
6586 const NAME: &'static str = "GossipMessageReader";
6587 fn to_entity(&self) -> Self::Entity {
6588 Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6589 }
6590 fn new_unchecked(slice: &'r [u8]) -> Self {
6591 GossipMessageReader(slice)
6592 }
6593 fn as_slice(&self) -> &'r [u8] {
6594 self.0
6595 }
6596 fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6597 use molecule::verification_error as ve;
6598 let slice_len = slice.len();
6599 if slice_len < molecule::NUMBER_SIZE {
6600 return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6601 }
6602 let item_id = molecule::unpack_number(slice);
6603 let inner_slice = &slice[molecule::NUMBER_SIZE..];
6604 match item_id {
6605 0 => BroadcastMessagesFilterReader::verify(inner_slice, compatible),
6606 1 => BroadcastMessagesFilterResultReader::verify(inner_slice, compatible),
6607 2 => GetBroadcastMessagesReader::verify(inner_slice, compatible),
6608 3 => GetBroadcastMessagesResultReader::verify(inner_slice, compatible),
6609 4 => QueryBroadcastMessagesReader::verify(inner_slice, compatible),
6610 5 => QueryBroadcastMessagesResultReader::verify(inner_slice, compatible),
6611 _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
6612 }?;
6613 Ok(())
6614 }
6615}
6616#[derive(Clone, Debug, Default)]
6617pub struct GossipMessageBuilder(pub(crate) GossipMessageUnion);
6618impl GossipMessageBuilder {
6619 pub const ITEMS_COUNT: usize = 6;
6620 pub fn set<I>(mut self, v: I) -> Self
6621 where
6622 I: ::core::convert::Into<GossipMessageUnion>,
6623 {
6624 self.0 = v.into();
6625 self
6626 }
6627}
6628impl molecule::prelude::Builder for GossipMessageBuilder {
6629 type Entity = GossipMessage;
6630 const NAME: &'static str = "GossipMessageBuilder";
6631 fn expected_length(&self) -> usize {
6632 molecule::NUMBER_SIZE + self.0.as_slice().len()
6633 }
6634 fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6635 writer.write_all(&molecule::pack_number(self.0.item_id()))?;
6636 writer.write_all(self.0.as_slice())
6637 }
6638 fn build(&self) -> Self::Entity {
6639 let mut inner = Vec::with_capacity(self.expected_length());
6640 self.write(&mut inner)
6641 .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6642 GossipMessage::new_unchecked(inner.into())
6643 }
6644}
6645#[derive(Debug, Clone)]
6646pub enum GossipMessageUnion {
6647 BroadcastMessagesFilter(BroadcastMessagesFilter),
6648 BroadcastMessagesFilterResult(BroadcastMessagesFilterResult),
6649 GetBroadcastMessages(GetBroadcastMessages),
6650 GetBroadcastMessagesResult(GetBroadcastMessagesResult),
6651 QueryBroadcastMessages(QueryBroadcastMessages),
6652 QueryBroadcastMessagesResult(QueryBroadcastMessagesResult),
6653}
6654#[derive(Debug, Clone, Copy)]
6655pub enum GossipMessageUnionReader<'r> {
6656 BroadcastMessagesFilter(BroadcastMessagesFilterReader<'r>),
6657 BroadcastMessagesFilterResult(BroadcastMessagesFilterResultReader<'r>),
6658 GetBroadcastMessages(GetBroadcastMessagesReader<'r>),
6659 GetBroadcastMessagesResult(GetBroadcastMessagesResultReader<'r>),
6660 QueryBroadcastMessages(QueryBroadcastMessagesReader<'r>),
6661 QueryBroadcastMessagesResult(QueryBroadcastMessagesResultReader<'r>),
6662}
6663impl ::core::default::Default for GossipMessageUnion {
6664 fn default() -> Self {
6665 GossipMessageUnion::BroadcastMessagesFilter(::core::default::Default::default())
6666 }
6667}
6668impl ::core::fmt::Display for GossipMessageUnion {
6669 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6670 match self {
6671 GossipMessageUnion::BroadcastMessagesFilter(ref item) => {
6672 write!(
6673 f,
6674 "{}::{}({})",
6675 Self::NAME,
6676 BroadcastMessagesFilter::NAME,
6677 item
6678 )
6679 }
6680 GossipMessageUnion::BroadcastMessagesFilterResult(ref item) => {
6681 write!(
6682 f,
6683 "{}::{}({})",
6684 Self::NAME,
6685 BroadcastMessagesFilterResult::NAME,
6686 item
6687 )
6688 }
6689 GossipMessageUnion::GetBroadcastMessages(ref item) => {
6690 write!(
6691 f,
6692 "{}::{}({})",
6693 Self::NAME,
6694 GetBroadcastMessages::NAME,
6695 item
6696 )
6697 }
6698 GossipMessageUnion::GetBroadcastMessagesResult(ref item) => {
6699 write!(
6700 f,
6701 "{}::{}({})",
6702 Self::NAME,
6703 GetBroadcastMessagesResult::NAME,
6704 item
6705 )
6706 }
6707 GossipMessageUnion::QueryBroadcastMessages(ref item) => {
6708 write!(
6709 f,
6710 "{}::{}({})",
6711 Self::NAME,
6712 QueryBroadcastMessages::NAME,
6713 item
6714 )
6715 }
6716 GossipMessageUnion::QueryBroadcastMessagesResult(ref item) => {
6717 write!(
6718 f,
6719 "{}::{}({})",
6720 Self::NAME,
6721 QueryBroadcastMessagesResult::NAME,
6722 item
6723 )
6724 }
6725 }
6726 }
6727}
6728impl<'r> ::core::fmt::Display for GossipMessageUnionReader<'r> {
6729 fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6730 match self {
6731 GossipMessageUnionReader::BroadcastMessagesFilter(ref item) => {
6732 write!(
6733 f,
6734 "{}::{}({})",
6735 Self::NAME,
6736 BroadcastMessagesFilter::NAME,
6737 item
6738 )
6739 }
6740 GossipMessageUnionReader::BroadcastMessagesFilterResult(ref item) => {
6741 write!(
6742 f,
6743 "{}::{}({})",
6744 Self::NAME,
6745 BroadcastMessagesFilterResult::NAME,
6746 item
6747 )
6748 }
6749 GossipMessageUnionReader::GetBroadcastMessages(ref item) => {
6750 write!(
6751 f,
6752 "{}::{}({})",
6753 Self::NAME,
6754 GetBroadcastMessages::NAME,
6755 item
6756 )
6757 }
6758 GossipMessageUnionReader::GetBroadcastMessagesResult(ref item) => {
6759 write!(
6760 f,
6761 "{}::{}({})",
6762 Self::NAME,
6763 GetBroadcastMessagesResult::NAME,
6764 item
6765 )
6766 }
6767 GossipMessageUnionReader::QueryBroadcastMessages(ref item) => {
6768 write!(
6769 f,
6770 "{}::{}({})",
6771 Self::NAME,
6772 QueryBroadcastMessages::NAME,
6773 item
6774 )
6775 }
6776 GossipMessageUnionReader::QueryBroadcastMessagesResult(ref item) => {
6777 write!(
6778 f,
6779 "{}::{}({})",
6780 Self::NAME,
6781 QueryBroadcastMessagesResult::NAME,
6782 item
6783 )
6784 }
6785 }
6786 }
6787}
6788impl GossipMessageUnion {
6789 pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6790 match self {
6791 GossipMessageUnion::BroadcastMessagesFilter(ref item) => write!(f, "{}", item),
6792 GossipMessageUnion::BroadcastMessagesFilterResult(ref item) => write!(f, "{}", item),
6793 GossipMessageUnion::GetBroadcastMessages(ref item) => write!(f, "{}", item),
6794 GossipMessageUnion::GetBroadcastMessagesResult(ref item) => write!(f, "{}", item),
6795 GossipMessageUnion::QueryBroadcastMessages(ref item) => write!(f, "{}", item),
6796 GossipMessageUnion::QueryBroadcastMessagesResult(ref item) => write!(f, "{}", item),
6797 }
6798 }
6799}
6800impl<'r> GossipMessageUnionReader<'r> {
6801 pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6802 match self {
6803 GossipMessageUnionReader::BroadcastMessagesFilter(ref item) => write!(f, "{}", item),
6804 GossipMessageUnionReader::BroadcastMessagesFilterResult(ref item) => {
6805 write!(f, "{}", item)
6806 }
6807 GossipMessageUnionReader::GetBroadcastMessages(ref item) => write!(f, "{}", item),
6808 GossipMessageUnionReader::GetBroadcastMessagesResult(ref item) => write!(f, "{}", item),
6809 GossipMessageUnionReader::QueryBroadcastMessages(ref item) => write!(f, "{}", item),
6810 GossipMessageUnionReader::QueryBroadcastMessagesResult(ref item) => {
6811 write!(f, "{}", item)
6812 }
6813 }
6814 }
6815}
6816impl ::core::convert::From<BroadcastMessagesFilter> for GossipMessageUnion {
6817 fn from(item: BroadcastMessagesFilter) -> Self {
6818 GossipMessageUnion::BroadcastMessagesFilter(item)
6819 }
6820}
6821impl ::core::convert::From<BroadcastMessagesFilterResult> for GossipMessageUnion {
6822 fn from(item: BroadcastMessagesFilterResult) -> Self {
6823 GossipMessageUnion::BroadcastMessagesFilterResult(item)
6824 }
6825}
6826impl ::core::convert::From<GetBroadcastMessages> for GossipMessageUnion {
6827 fn from(item: GetBroadcastMessages) -> Self {
6828 GossipMessageUnion::GetBroadcastMessages(item)
6829 }
6830}
6831impl ::core::convert::From<GetBroadcastMessagesResult> for GossipMessageUnion {
6832 fn from(item: GetBroadcastMessagesResult) -> Self {
6833 GossipMessageUnion::GetBroadcastMessagesResult(item)
6834 }
6835}
6836impl ::core::convert::From<QueryBroadcastMessages> for GossipMessageUnion {
6837 fn from(item: QueryBroadcastMessages) -> Self {
6838 GossipMessageUnion::QueryBroadcastMessages(item)
6839 }
6840}
6841impl ::core::convert::From<QueryBroadcastMessagesResult> for GossipMessageUnion {
6842 fn from(item: QueryBroadcastMessagesResult) -> Self {
6843 GossipMessageUnion::QueryBroadcastMessagesResult(item)
6844 }
6845}
6846impl<'r> ::core::convert::From<BroadcastMessagesFilterReader<'r>> for GossipMessageUnionReader<'r> {
6847 fn from(item: BroadcastMessagesFilterReader<'r>) -> Self {
6848 GossipMessageUnionReader::BroadcastMessagesFilter(item)
6849 }
6850}
6851impl<'r> ::core::convert::From<BroadcastMessagesFilterResultReader<'r>>
6852 for GossipMessageUnionReader<'r>
6853{
6854 fn from(item: BroadcastMessagesFilterResultReader<'r>) -> Self {
6855 GossipMessageUnionReader::BroadcastMessagesFilterResult(item)
6856 }
6857}
6858impl<'r> ::core::convert::From<GetBroadcastMessagesReader<'r>> for GossipMessageUnionReader<'r> {
6859 fn from(item: GetBroadcastMessagesReader<'r>) -> Self {
6860 GossipMessageUnionReader::GetBroadcastMessages(item)
6861 }
6862}
6863impl<'r> ::core::convert::From<GetBroadcastMessagesResultReader<'r>>
6864 for GossipMessageUnionReader<'r>
6865{
6866 fn from(item: GetBroadcastMessagesResultReader<'r>) -> Self {
6867 GossipMessageUnionReader::GetBroadcastMessagesResult(item)
6868 }
6869}
6870impl<'r> ::core::convert::From<QueryBroadcastMessagesReader<'r>> for GossipMessageUnionReader<'r> {
6871 fn from(item: QueryBroadcastMessagesReader<'r>) -> Self {
6872 GossipMessageUnionReader::QueryBroadcastMessages(item)
6873 }
6874}
6875impl<'r> ::core::convert::From<QueryBroadcastMessagesResultReader<'r>>
6876 for GossipMessageUnionReader<'r>
6877{
6878 fn from(item: QueryBroadcastMessagesResultReader<'r>) -> Self {
6879 GossipMessageUnionReader::QueryBroadcastMessagesResult(item)
6880 }
6881}
6882impl GossipMessageUnion {
6883 pub const NAME: &'static str = "GossipMessageUnion";
6884 pub fn as_bytes(&self) -> molecule::bytes::Bytes {
6885 match self {
6886 GossipMessageUnion::BroadcastMessagesFilter(item) => item.as_bytes(),
6887 GossipMessageUnion::BroadcastMessagesFilterResult(item) => item.as_bytes(),
6888 GossipMessageUnion::GetBroadcastMessages(item) => item.as_bytes(),
6889 GossipMessageUnion::GetBroadcastMessagesResult(item) => item.as_bytes(),
6890 GossipMessageUnion::QueryBroadcastMessages(item) => item.as_bytes(),
6891 GossipMessageUnion::QueryBroadcastMessagesResult(item) => item.as_bytes(),
6892 }
6893 }
6894 pub fn as_slice(&self) -> &[u8] {
6895 match self {
6896 GossipMessageUnion::BroadcastMessagesFilter(item) => item.as_slice(),
6897 GossipMessageUnion::BroadcastMessagesFilterResult(item) => item.as_slice(),
6898 GossipMessageUnion::GetBroadcastMessages(item) => item.as_slice(),
6899 GossipMessageUnion::GetBroadcastMessagesResult(item) => item.as_slice(),
6900 GossipMessageUnion::QueryBroadcastMessages(item) => item.as_slice(),
6901 GossipMessageUnion::QueryBroadcastMessagesResult(item) => item.as_slice(),
6902 }
6903 }
6904 pub fn item_id(&self) -> molecule::Number {
6905 match self {
6906 GossipMessageUnion::BroadcastMessagesFilter(_) => 0,
6907 GossipMessageUnion::BroadcastMessagesFilterResult(_) => 1,
6908 GossipMessageUnion::GetBroadcastMessages(_) => 2,
6909 GossipMessageUnion::GetBroadcastMessagesResult(_) => 3,
6910 GossipMessageUnion::QueryBroadcastMessages(_) => 4,
6911 GossipMessageUnion::QueryBroadcastMessagesResult(_) => 5,
6912 }
6913 }
6914 pub fn item_name(&self) -> &str {
6915 match self {
6916 GossipMessageUnion::BroadcastMessagesFilter(_) => "BroadcastMessagesFilter",
6917 GossipMessageUnion::BroadcastMessagesFilterResult(_) => "BroadcastMessagesFilterResult",
6918 GossipMessageUnion::GetBroadcastMessages(_) => "GetBroadcastMessages",
6919 GossipMessageUnion::GetBroadcastMessagesResult(_) => "GetBroadcastMessagesResult",
6920 GossipMessageUnion::QueryBroadcastMessages(_) => "QueryBroadcastMessages",
6921 GossipMessageUnion::QueryBroadcastMessagesResult(_) => "QueryBroadcastMessagesResult",
6922 }
6923 }
6924 pub fn as_reader<'r>(&'r self) -> GossipMessageUnionReader<'r> {
6925 match self {
6926 GossipMessageUnion::BroadcastMessagesFilter(item) => item.as_reader().into(),
6927 GossipMessageUnion::BroadcastMessagesFilterResult(item) => item.as_reader().into(),
6928 GossipMessageUnion::GetBroadcastMessages(item) => item.as_reader().into(),
6929 GossipMessageUnion::GetBroadcastMessagesResult(item) => item.as_reader().into(),
6930 GossipMessageUnion::QueryBroadcastMessages(item) => item.as_reader().into(),
6931 GossipMessageUnion::QueryBroadcastMessagesResult(item) => item.as_reader().into(),
6932 }
6933 }
6934}
6935impl<'r> GossipMessageUnionReader<'r> {
6936 pub const NAME: &'r str = "GossipMessageUnionReader";
6937 pub fn as_slice(&self) -> &'r [u8] {
6938 match self {
6939 GossipMessageUnionReader::BroadcastMessagesFilter(item) => item.as_slice(),
6940 GossipMessageUnionReader::BroadcastMessagesFilterResult(item) => item.as_slice(),
6941 GossipMessageUnionReader::GetBroadcastMessages(item) => item.as_slice(),
6942 GossipMessageUnionReader::GetBroadcastMessagesResult(item) => item.as_slice(),
6943 GossipMessageUnionReader::QueryBroadcastMessages(item) => item.as_slice(),
6944 GossipMessageUnionReader::QueryBroadcastMessagesResult(item) => item.as_slice(),
6945 }
6946 }
6947 pub fn item_id(&self) -> molecule::Number {
6948 match self {
6949 GossipMessageUnionReader::BroadcastMessagesFilter(_) => 0,
6950 GossipMessageUnionReader::BroadcastMessagesFilterResult(_) => 1,
6951 GossipMessageUnionReader::GetBroadcastMessages(_) => 2,
6952 GossipMessageUnionReader::GetBroadcastMessagesResult(_) => 3,
6953 GossipMessageUnionReader::QueryBroadcastMessages(_) => 4,
6954 GossipMessageUnionReader::QueryBroadcastMessagesResult(_) => 5,
6955 }
6956 }
6957 pub fn item_name(&self) -> &str {
6958 match self {
6959 GossipMessageUnionReader::BroadcastMessagesFilter(_) => "BroadcastMessagesFilter",
6960 GossipMessageUnionReader::BroadcastMessagesFilterResult(_) => {
6961 "BroadcastMessagesFilterResult"
6962 }
6963 GossipMessageUnionReader::GetBroadcastMessages(_) => "GetBroadcastMessages",
6964 GossipMessageUnionReader::GetBroadcastMessagesResult(_) => "GetBroadcastMessagesResult",
6965 GossipMessageUnionReader::QueryBroadcastMessages(_) => "QueryBroadcastMessages",
6966 GossipMessageUnionReader::QueryBroadcastMessagesResult(_) => {
6967 "QueryBroadcastMessagesResult"
6968 }
6969 }
6970 }
6971}
6972impl From<BroadcastMessagesFilter> for GossipMessage {
6973 fn from(value: BroadcastMessagesFilter) -> Self {
6974 Self::new_builder().set(value).build()
6975 }
6976}
6977impl From<BroadcastMessagesFilterResult> for GossipMessage {
6978 fn from(value: BroadcastMessagesFilterResult) -> Self {
6979 Self::new_builder().set(value).build()
6980 }
6981}
6982impl From<GetBroadcastMessages> for GossipMessage {
6983 fn from(value: GetBroadcastMessages) -> Self {
6984 Self::new_builder().set(value).build()
6985 }
6986}
6987impl From<GetBroadcastMessagesResult> for GossipMessage {
6988 fn from(value: GetBroadcastMessagesResult) -> Self {
6989 Self::new_builder().set(value).build()
6990 }
6991}
6992impl From<QueryBroadcastMessages> for GossipMessage {
6993 fn from(value: QueryBroadcastMessages) -> Self {
6994 Self::new_builder().set(value).build()
6995 }
6996}
6997impl From<QueryBroadcastMessagesResult> for GossipMessage {
6998 fn from(value: QueryBroadcastMessagesResult) -> Self {
6999 Self::new_builder().set(value).build()
7000 }
7001}