]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_serialize/src/opaque.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / compiler / rustc_serialize / src / opaque.rs
1 use crate::leb128::{self, max_leb128_len};
2 use crate::serialize::{self, Decoder as _, Encoder as _};
3 use std::convert::TryInto;
4 use std::fs::File;
5 use std::io::{self, Write};
6 use std::mem::MaybeUninit;
7 use std::path::Path;
8 use std::ptr;
9
10 // -----------------------------------------------------------------------------
11 // Encoder
12 // -----------------------------------------------------------------------------
13
14 pub type EncodeResult = Result<(), !>;
15
16 pub struct Encoder {
17 pub data: Vec<u8>,
18 }
19
20 impl Encoder {
21 pub fn new(data: Vec<u8>) -> Encoder {
22 Encoder { data }
23 }
24
25 pub fn into_inner(self) -> Vec<u8> {
26 self.data
27 }
28
29 #[inline]
30 pub fn position(&self) -> usize {
31 self.data.len()
32 }
33 }
34
35 macro_rules! write_leb128 {
36 ($enc:expr, $value:expr, $int_ty:ty, $fun:ident) => {{
37 const MAX_ENCODED_LEN: usize = max_leb128_len!($int_ty);
38 let old_len = $enc.data.len();
39
40 if MAX_ENCODED_LEN > $enc.data.capacity() - old_len {
41 $enc.data.reserve(MAX_ENCODED_LEN);
42 }
43
44 // SAFETY: The above check and `reserve` ensures that there is enough
45 // room to write the encoded value to the vector's internal buffer.
46 unsafe {
47 let buf = &mut *($enc.data.as_mut_ptr().add(old_len)
48 as *mut [MaybeUninit<u8>; MAX_ENCODED_LEN]);
49 let encoded = leb128::$fun(buf, $value);
50 $enc.data.set_len(old_len + encoded.len());
51 }
52
53 Ok(())
54 }};
55 }
56
57 /// A byte that [cannot occur in UTF8 sequences][utf8]. Used to mark the end of a string.
58 /// This way we can skip validation and still be relatively sure that deserialization
59 /// did not desynchronize.
60 ///
61 /// [utf8]: https://en.wikipedia.org/w/index.php?title=UTF-8&oldid=1058865525#Codepage_layout
62 const STR_SENTINEL: u8 = 0xC1;
63
64 impl serialize::Encoder for Encoder {
65 type Error = !;
66
67 #[inline]
68 fn emit_unit(&mut self) -> EncodeResult {
69 Ok(())
70 }
71
72 #[inline]
73 fn emit_usize(&mut self, v: usize) -> EncodeResult {
74 write_leb128!(self, v, usize, write_usize_leb128)
75 }
76
77 #[inline]
78 fn emit_u128(&mut self, v: u128) -> EncodeResult {
79 write_leb128!(self, v, u128, write_u128_leb128)
80 }
81
82 #[inline]
83 fn emit_u64(&mut self, v: u64) -> EncodeResult {
84 write_leb128!(self, v, u64, write_u64_leb128)
85 }
86
87 #[inline]
88 fn emit_u32(&mut self, v: u32) -> EncodeResult {
89 write_leb128!(self, v, u32, write_u32_leb128)
90 }
91
92 #[inline]
93 fn emit_u16(&mut self, v: u16) -> EncodeResult {
94 self.data.extend_from_slice(&v.to_le_bytes());
95 Ok(())
96 }
97
98 #[inline]
99 fn emit_u8(&mut self, v: u8) -> EncodeResult {
100 self.data.push(v);
101 Ok(())
102 }
103
104 #[inline]
105 fn emit_isize(&mut self, v: isize) -> EncodeResult {
106 write_leb128!(self, v, isize, write_isize_leb128)
107 }
108
109 #[inline]
110 fn emit_i128(&mut self, v: i128) -> EncodeResult {
111 write_leb128!(self, v, i128, write_i128_leb128)
112 }
113
114 #[inline]
115 fn emit_i64(&mut self, v: i64) -> EncodeResult {
116 write_leb128!(self, v, i64, write_i64_leb128)
117 }
118
119 #[inline]
120 fn emit_i32(&mut self, v: i32) -> EncodeResult {
121 write_leb128!(self, v, i32, write_i32_leb128)
122 }
123
124 #[inline]
125 fn emit_i16(&mut self, v: i16) -> EncodeResult {
126 self.data.extend_from_slice(&v.to_le_bytes());
127 Ok(())
128 }
129
130 #[inline]
131 fn emit_i8(&mut self, v: i8) -> EncodeResult {
132 self.emit_u8(v as u8)
133 }
134
135 #[inline]
136 fn emit_bool(&mut self, v: bool) -> EncodeResult {
137 self.emit_u8(if v { 1 } else { 0 })
138 }
139
140 #[inline]
141 fn emit_f64(&mut self, v: f64) -> EncodeResult {
142 let as_u64: u64 = v.to_bits();
143 self.emit_u64(as_u64)
144 }
145
146 #[inline]
147 fn emit_f32(&mut self, v: f32) -> EncodeResult {
148 let as_u32: u32 = v.to_bits();
149 self.emit_u32(as_u32)
150 }
151
152 #[inline]
153 fn emit_char(&mut self, v: char) -> EncodeResult {
154 self.emit_u32(v as u32)
155 }
156
157 #[inline]
158 fn emit_str(&mut self, v: &str) -> EncodeResult {
159 self.emit_usize(v.len())?;
160 self.emit_raw_bytes(v.as_bytes())?;
161 self.emit_u8(STR_SENTINEL)
162 }
163
164 #[inline]
165 fn emit_raw_bytes(&mut self, s: &[u8]) -> EncodeResult {
166 self.data.extend_from_slice(s);
167 Ok(())
168 }
169 }
170
171 pub type FileEncodeResult = Result<(), io::Error>;
172
173 // `FileEncoder` encodes data to file via fixed-size buffer.
174 //
175 // When encoding large amounts of data to a file, using `FileEncoder` may be
176 // preferred over using `Encoder` to encode to a `Vec`, and then writing the
177 // `Vec` to file, as the latter uses as much memory as there is encoded data,
178 // while the former uses the fixed amount of memory allocated to the buffer.
179 // `FileEncoder` also has the advantage of not needing to reallocate as data
180 // is appended to it, but the disadvantage of requiring more error handling,
181 // which has some runtime overhead.
182 pub struct FileEncoder {
183 // The input buffer. For adequate performance, we need more control over
184 // buffering than `BufWriter` offers. If `BufWriter` ever offers a raw
185 // buffer access API, we can use it, and remove `buf` and `buffered`.
186 buf: Box<[MaybeUninit<u8>]>,
187 buffered: usize,
188 flushed: usize,
189 file: File,
190 }
191
192 impl FileEncoder {
193 pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Self> {
194 const DEFAULT_BUF_SIZE: usize = 8192;
195 FileEncoder::with_capacity(path, DEFAULT_BUF_SIZE)
196 }
197
198 pub fn with_capacity<P: AsRef<Path>>(path: P, capacity: usize) -> io::Result<Self> {
199 // Require capacity at least as large as the largest LEB128 encoding
200 // here, so that we don't have to check or handle this on every write.
201 assert!(capacity >= max_leb128_len());
202
203 // Require capacity small enough such that some capacity checks can be
204 // done using guaranteed non-overflowing add rather than sub, which
205 // shaves an instruction off those code paths (on x86 at least).
206 assert!(capacity <= usize::MAX - max_leb128_len());
207
208 let file = File::create(path)?;
209
210 Ok(FileEncoder { buf: Box::new_uninit_slice(capacity), buffered: 0, flushed: 0, file })
211 }
212
213 #[inline]
214 pub fn position(&self) -> usize {
215 // Tracking position this way instead of having a `self.position` field
216 // means that we don't have to update the position on every write call.
217 self.flushed + self.buffered
218 }
219
220 pub fn flush(&mut self) -> FileEncodeResult {
221 // This is basically a copy of `BufWriter::flush`. If `BufWriter` ever
222 // offers a raw buffer access API, we can use it, and remove this.
223
224 /// Helper struct to ensure the buffer is updated after all the writes
225 /// are complete. It tracks the number of written bytes and drains them
226 /// all from the front of the buffer when dropped.
227 struct BufGuard<'a> {
228 buffer: &'a mut [u8],
229 encoder_buffered: &'a mut usize,
230 encoder_flushed: &'a mut usize,
231 flushed: usize,
232 }
233
234 impl<'a> BufGuard<'a> {
235 fn new(
236 buffer: &'a mut [u8],
237 encoder_buffered: &'a mut usize,
238 encoder_flushed: &'a mut usize,
239 ) -> Self {
240 assert_eq!(buffer.len(), *encoder_buffered);
241 Self { buffer, encoder_buffered, encoder_flushed, flushed: 0 }
242 }
243
244 /// The unwritten part of the buffer
245 fn remaining(&self) -> &[u8] {
246 &self.buffer[self.flushed..]
247 }
248
249 /// Flag some bytes as removed from the front of the buffer
250 fn consume(&mut self, amt: usize) {
251 self.flushed += amt;
252 }
253
254 /// true if all of the bytes have been written
255 fn done(&self) -> bool {
256 self.flushed >= *self.encoder_buffered
257 }
258 }
259
260 impl Drop for BufGuard<'_> {
261 fn drop(&mut self) {
262 if self.flushed > 0 {
263 if self.done() {
264 *self.encoder_flushed += *self.encoder_buffered;
265 *self.encoder_buffered = 0;
266 } else {
267 self.buffer.copy_within(self.flushed.., 0);
268 *self.encoder_flushed += self.flushed;
269 *self.encoder_buffered -= self.flushed;
270 }
271 }
272 }
273 }
274
275 let mut guard = BufGuard::new(
276 unsafe { MaybeUninit::slice_assume_init_mut(&mut self.buf[..self.buffered]) },
277 &mut self.buffered,
278 &mut self.flushed,
279 );
280
281 while !guard.done() {
282 match self.file.write(guard.remaining()) {
283 Ok(0) => {
284 return Err(io::Error::new(
285 io::ErrorKind::WriteZero,
286 "failed to write the buffered data",
287 ));
288 }
289 Ok(n) => guard.consume(n),
290 Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
291 Err(e) => return Err(e),
292 }
293 }
294
295 Ok(())
296 }
297
298 #[inline]
299 fn capacity(&self) -> usize {
300 self.buf.len()
301 }
302
303 #[inline]
304 fn write_one(&mut self, value: u8) -> FileEncodeResult {
305 // We ensure this during `FileEncoder` construction.
306 debug_assert!(self.capacity() >= 1);
307
308 let mut buffered = self.buffered;
309
310 if std::intrinsics::unlikely(buffered >= self.capacity()) {
311 self.flush()?;
312 buffered = 0;
313 }
314
315 // SAFETY: The above check and `flush` ensures that there is enough
316 // room to write the input to the buffer.
317 unsafe {
318 *MaybeUninit::slice_as_mut_ptr(&mut self.buf).add(buffered) = value;
319 }
320
321 self.buffered = buffered + 1;
322
323 Ok(())
324 }
325
326 #[inline]
327 fn write_all(&mut self, buf: &[u8]) -> FileEncodeResult {
328 let capacity = self.capacity();
329 let buf_len = buf.len();
330
331 if std::intrinsics::likely(buf_len <= capacity) {
332 let mut buffered = self.buffered;
333
334 if std::intrinsics::unlikely(buf_len > capacity - buffered) {
335 self.flush()?;
336 buffered = 0;
337 }
338
339 // SAFETY: The above check and `flush` ensures that there is enough
340 // room to write the input to the buffer.
341 unsafe {
342 let src = buf.as_ptr();
343 let dst = MaybeUninit::slice_as_mut_ptr(&mut self.buf).add(buffered);
344 ptr::copy_nonoverlapping(src, dst, buf_len);
345 }
346
347 self.buffered = buffered + buf_len;
348
349 Ok(())
350 } else {
351 self.write_all_unbuffered(buf)
352 }
353 }
354
355 fn write_all_unbuffered(&mut self, mut buf: &[u8]) -> FileEncodeResult {
356 if self.buffered > 0 {
357 self.flush()?;
358 }
359
360 // This is basically a copy of `Write::write_all` but also updates our
361 // `self.flushed`. It's necessary because `Write::write_all` does not
362 // return the number of bytes written when an error is encountered, and
363 // without that, we cannot accurately update `self.flushed` on error.
364 while !buf.is_empty() {
365 match self.file.write(buf) {
366 Ok(0) => {
367 return Err(io::Error::new(
368 io::ErrorKind::WriteZero,
369 "failed to write whole buffer",
370 ));
371 }
372 Ok(n) => {
373 buf = &buf[n..];
374 self.flushed += n;
375 }
376 Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
377 Err(e) => return Err(e),
378 }
379 }
380
381 Ok(())
382 }
383 }
384
385 impl Drop for FileEncoder {
386 fn drop(&mut self) {
387 let _result = self.flush();
388 }
389 }
390
391 macro_rules! file_encoder_write_leb128 {
392 ($enc:expr, $value:expr, $int_ty:ty, $fun:ident) => {{
393 const MAX_ENCODED_LEN: usize = max_leb128_len!($int_ty);
394
395 // We ensure this during `FileEncoder` construction.
396 debug_assert!($enc.capacity() >= MAX_ENCODED_LEN);
397
398 let mut buffered = $enc.buffered;
399
400 // This can't overflow. See assertion in `FileEncoder::with_capacity`.
401 if std::intrinsics::unlikely(buffered + MAX_ENCODED_LEN > $enc.capacity()) {
402 $enc.flush()?;
403 buffered = 0;
404 }
405
406 // SAFETY: The above check and flush ensures that there is enough
407 // room to write the encoded value to the buffer.
408 let buf = unsafe {
409 &mut *($enc.buf.as_mut_ptr().add(buffered) as *mut [MaybeUninit<u8>; MAX_ENCODED_LEN])
410 };
411
412 let encoded = leb128::$fun(buf, $value);
413 $enc.buffered = buffered + encoded.len();
414
415 Ok(())
416 }};
417 }
418
419 impl serialize::Encoder for FileEncoder {
420 type Error = io::Error;
421
422 #[inline]
423 fn emit_unit(&mut self) -> FileEncodeResult {
424 Ok(())
425 }
426
427 #[inline]
428 fn emit_usize(&mut self, v: usize) -> FileEncodeResult {
429 file_encoder_write_leb128!(self, v, usize, write_usize_leb128)
430 }
431
432 #[inline]
433 fn emit_u128(&mut self, v: u128) -> FileEncodeResult {
434 file_encoder_write_leb128!(self, v, u128, write_u128_leb128)
435 }
436
437 #[inline]
438 fn emit_u64(&mut self, v: u64) -> FileEncodeResult {
439 file_encoder_write_leb128!(self, v, u64, write_u64_leb128)
440 }
441
442 #[inline]
443 fn emit_u32(&mut self, v: u32) -> FileEncodeResult {
444 file_encoder_write_leb128!(self, v, u32, write_u32_leb128)
445 }
446
447 #[inline]
448 fn emit_u16(&mut self, v: u16) -> FileEncodeResult {
449 self.write_all(&v.to_le_bytes())
450 }
451
452 #[inline]
453 fn emit_u8(&mut self, v: u8) -> FileEncodeResult {
454 self.write_one(v)
455 }
456
457 #[inline]
458 fn emit_isize(&mut self, v: isize) -> FileEncodeResult {
459 file_encoder_write_leb128!(self, v, isize, write_isize_leb128)
460 }
461
462 #[inline]
463 fn emit_i128(&mut self, v: i128) -> FileEncodeResult {
464 file_encoder_write_leb128!(self, v, i128, write_i128_leb128)
465 }
466
467 #[inline]
468 fn emit_i64(&mut self, v: i64) -> FileEncodeResult {
469 file_encoder_write_leb128!(self, v, i64, write_i64_leb128)
470 }
471
472 #[inline]
473 fn emit_i32(&mut self, v: i32) -> FileEncodeResult {
474 file_encoder_write_leb128!(self, v, i32, write_i32_leb128)
475 }
476
477 #[inline]
478 fn emit_i16(&mut self, v: i16) -> FileEncodeResult {
479 self.write_all(&v.to_le_bytes())
480 }
481
482 #[inline]
483 fn emit_i8(&mut self, v: i8) -> FileEncodeResult {
484 self.emit_u8(v as u8)
485 }
486
487 #[inline]
488 fn emit_bool(&mut self, v: bool) -> FileEncodeResult {
489 self.emit_u8(if v { 1 } else { 0 })
490 }
491
492 #[inline]
493 fn emit_f64(&mut self, v: f64) -> FileEncodeResult {
494 let as_u64: u64 = v.to_bits();
495 self.emit_u64(as_u64)
496 }
497
498 #[inline]
499 fn emit_f32(&mut self, v: f32) -> FileEncodeResult {
500 let as_u32: u32 = v.to_bits();
501 self.emit_u32(as_u32)
502 }
503
504 #[inline]
505 fn emit_char(&mut self, v: char) -> FileEncodeResult {
506 self.emit_u32(v as u32)
507 }
508
509 #[inline]
510 fn emit_str(&mut self, v: &str) -> FileEncodeResult {
511 self.emit_usize(v.len())?;
512 self.emit_raw_bytes(v.as_bytes())?;
513 self.emit_u8(STR_SENTINEL)
514 }
515
516 #[inline]
517 fn emit_raw_bytes(&mut self, s: &[u8]) -> FileEncodeResult {
518 self.write_all(s)
519 }
520 }
521
522 // -----------------------------------------------------------------------------
523 // Decoder
524 // -----------------------------------------------------------------------------
525
526 pub struct Decoder<'a> {
527 pub data: &'a [u8],
528 position: usize,
529 }
530
531 impl<'a> Decoder<'a> {
532 #[inline]
533 pub fn new(data: &'a [u8], position: usize) -> Decoder<'a> {
534 Decoder { data, position }
535 }
536
537 #[inline]
538 pub fn position(&self) -> usize {
539 self.position
540 }
541
542 #[inline]
543 pub fn set_position(&mut self, pos: usize) {
544 self.position = pos
545 }
546
547 #[inline]
548 pub fn advance(&mut self, bytes: usize) {
549 self.position += bytes;
550 }
551 }
552
553 macro_rules! read_leb128 {
554 ($dec:expr, $fun:ident) => {{ leb128::$fun($dec.data, &mut $dec.position) }};
555 }
556
557 impl<'a> serialize::Decoder for Decoder<'a> {
558 #[inline]
559 fn read_u128(&mut self) -> u128 {
560 read_leb128!(self, read_u128_leb128)
561 }
562
563 #[inline]
564 fn read_u64(&mut self) -> u64 {
565 read_leb128!(self, read_u64_leb128)
566 }
567
568 #[inline]
569 fn read_u32(&mut self) -> u32 {
570 read_leb128!(self, read_u32_leb128)
571 }
572
573 #[inline]
574 fn read_u16(&mut self) -> u16 {
575 let bytes = [self.data[self.position], self.data[self.position + 1]];
576 let value = u16::from_le_bytes(bytes);
577 self.position += 2;
578 value
579 }
580
581 #[inline]
582 fn read_u8(&mut self) -> u8 {
583 let value = self.data[self.position];
584 self.position += 1;
585 value
586 }
587
588 #[inline]
589 fn read_usize(&mut self) -> usize {
590 read_leb128!(self, read_usize_leb128)
591 }
592
593 #[inline]
594 fn read_i128(&mut self) -> i128 {
595 read_leb128!(self, read_i128_leb128)
596 }
597
598 #[inline]
599 fn read_i64(&mut self) -> i64 {
600 read_leb128!(self, read_i64_leb128)
601 }
602
603 #[inline]
604 fn read_i32(&mut self) -> i32 {
605 read_leb128!(self, read_i32_leb128)
606 }
607
608 #[inline]
609 fn read_i16(&mut self) -> i16 {
610 let bytes = [self.data[self.position], self.data[self.position + 1]];
611 let value = i16::from_le_bytes(bytes);
612 self.position += 2;
613 value
614 }
615
616 #[inline]
617 fn read_i8(&mut self) -> i8 {
618 let value = self.data[self.position];
619 self.position += 1;
620 value as i8
621 }
622
623 #[inline]
624 fn read_isize(&mut self) -> isize {
625 read_leb128!(self, read_isize_leb128)
626 }
627
628 #[inline]
629 fn read_bool(&mut self) -> bool {
630 let value = self.read_u8();
631 value != 0
632 }
633
634 #[inline]
635 fn read_f64(&mut self) -> f64 {
636 let bits = self.read_u64();
637 f64::from_bits(bits)
638 }
639
640 #[inline]
641 fn read_f32(&mut self) -> f32 {
642 let bits = self.read_u32();
643 f32::from_bits(bits)
644 }
645
646 #[inline]
647 fn read_char(&mut self) -> char {
648 let bits = self.read_u32();
649 std::char::from_u32(bits).unwrap()
650 }
651
652 #[inline]
653 fn read_str(&mut self) -> &'a str {
654 let len = self.read_usize();
655 let sentinel = self.data[self.position + len];
656 assert!(sentinel == STR_SENTINEL);
657 let s = unsafe {
658 std::str::from_utf8_unchecked(&self.data[self.position..self.position + len])
659 };
660 self.position += len + 1;
661 s
662 }
663
664 #[inline]
665 fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] {
666 let start = self.position;
667 self.position += bytes;
668 &self.data[start..self.position]
669 }
670 }
671
672 // Specializations for contiguous byte sequences follow. The default implementations for slices
673 // encode and decode each element individually. This isn't necessary for `u8` slices when using
674 // opaque encoders and decoders, because each `u8` is unchanged by encoding and decoding.
675 // Therefore, we can use more efficient implementations that process the entire sequence at once.
676
677 // Specialize encoding byte slices. This specialization also applies to encoding `Vec<u8>`s, etc.,
678 // since the default implementations call `encode` on their slices internally.
679 impl serialize::Encodable<Encoder> for [u8] {
680 fn encode(&self, e: &mut Encoder) -> EncodeResult {
681 serialize::Encoder::emit_usize(e, self.len())?;
682 e.emit_raw_bytes(self)
683 }
684 }
685
686 impl serialize::Encodable<FileEncoder> for [u8] {
687 fn encode(&self, e: &mut FileEncoder) -> FileEncodeResult {
688 serialize::Encoder::emit_usize(e, self.len())?;
689 e.emit_raw_bytes(self)
690 }
691 }
692
693 // Specialize decoding `Vec<u8>`. This specialization also applies to decoding `Box<[u8]>`s, etc.,
694 // since the default implementations call `decode` to produce a `Vec<u8>` internally.
695 impl<'a> serialize::Decodable<Decoder<'a>> for Vec<u8> {
696 fn decode(d: &mut Decoder<'a>) -> Self {
697 let len = serialize::Decoder::read_usize(d);
698 d.read_raw_bytes(len).to_owned()
699 }
700 }
701
702 // An integer that will always encode to 8 bytes.
703 pub struct IntEncodedWithFixedSize(pub u64);
704
705 impl IntEncodedWithFixedSize {
706 pub const ENCODED_SIZE: usize = 8;
707 }
708
709 impl serialize::Encodable<Encoder> for IntEncodedWithFixedSize {
710 #[inline]
711 fn encode(&self, e: &mut Encoder) -> EncodeResult {
712 let _start_pos = e.position();
713 e.emit_raw_bytes(&self.0.to_le_bytes())?;
714 let _end_pos = e.position();
715 debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);
716 Ok(())
717 }
718 }
719
720 impl serialize::Encodable<FileEncoder> for IntEncodedWithFixedSize {
721 #[inline]
722 fn encode(&self, e: &mut FileEncoder) -> FileEncodeResult {
723 let _start_pos = e.position();
724 e.emit_raw_bytes(&self.0.to_le_bytes())?;
725 let _end_pos = e.position();
726 debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);
727 Ok(())
728 }
729 }
730
731 impl<'a> serialize::Decodable<Decoder<'a>> for IntEncodedWithFixedSize {
732 #[inline]
733 fn decode(decoder: &mut Decoder<'a>) -> IntEncodedWithFixedSize {
734 let _start_pos = decoder.position();
735 let bytes = decoder.read_raw_bytes(IntEncodedWithFixedSize::ENCODED_SIZE);
736 let value = u64::from_le_bytes(bytes.try_into().unwrap());
737 let _end_pos = decoder.position();
738 debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);
739
740 IntEncodedWithFixedSize(value)
741 }
742 }