Skip to main content

wincode_dynamic/
value.rs

1use {
2    crate::{
3        PrimitiveTy,
4        wincode_extra::{LenMap, Map},
5    },
6    alloc::{borrow::Cow, vec::Vec},
7    core::{marker::PhantomData, mem::MaybeUninit},
8    wincode::{
9        ReadError, ReadResult, SchemaRead, SchemaReadContext,
10        config::{Config, ConfigCore, DefaultConfig},
11        context::Len,
12        io::Reader,
13        len::SeqLen,
14    },
15};
16
17/// An owned, dynamically typed primitive value.
18#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
19pub enum PrimitiveValue {
20    /// An unsigned 8-bit integer.
21    U8(u8),
22    /// An unsigned 16-bit integer.
23    U16(u16),
24    /// An unsigned 32-bit integer.
25    U32(u32),
26    /// An unsigned 64-bit integer.
27    U64(u64),
28    /// A signed 8-bit integer.
29    I8(i8),
30    /// A signed 16-bit integer.
31    I16(i16),
32    /// A signed 32-bit integer.
33    I32(i32),
34    /// A signed 64-bit integer.
35    I64(i64),
36    /// A 32-bit floating-point number.
37    F32(f32),
38    /// A 64-bit floating-point number.
39    F64(f64),
40    /// A Boolean value.
41    Bool(bool),
42}
43
44impl PrimitiveValue {
45    /// Returns the complete encoded width of this primitive, in bytes.
46    ///
47    /// Primitive encodings have no length prefix, so this is also the complete
48    /// serialized size under wincode's [`DefaultConfig`].
49    #[inline]
50    pub const fn size(self) -> usize {
51        match self {
52            PrimitiveValue::U8(_) => 1,
53            PrimitiveValue::U16(_) => 2,
54            PrimitiveValue::U32(_) => 4,
55            PrimitiveValue::U64(_) => 8,
56            PrimitiveValue::I8(_) => 1,
57            PrimitiveValue::I16(_) => 2,
58            PrimitiveValue::I32(_) => 4,
59            PrimitiveValue::I64(_) => 8,
60            PrimitiveValue::F32(_) => 4,
61            PrimitiveValue::F64(_) => 8,
62            PrimitiveValue::Bool(_) => 1,
63        }
64    }
65}
66
67/// A value decoded from a runtime [`Ty`](crate::Ty).
68///
69/// Scalar primitives are stored by value. Strings and byte payloads use
70/// [`Cow`] so they can borrow from readers that support stable borrowing.
71/// Non-byte primitive arrays and vectors are represented by [`LazyVec`] and
72/// decoded as they are iterated.
73#[derive(Debug, Clone, PartialEq)]
74pub enum Value<'a> {
75    /// An unsigned 8-bit integer.
76    U8(u8),
77    /// An unsigned 16-bit integer.
78    U16(u16),
79    /// An unsigned 32-bit integer.
80    U32(u32),
81    /// An unsigned 64-bit integer.
82    U64(u64),
83    /// A signed 8-bit integer.
84    I8(i8),
85    /// A signed 16-bit integer.
86    I16(i16),
87    /// A signed 32-bit integer.
88    I32(i32),
89    /// A signed 64-bit integer.
90    I64(i64),
91    /// A 32-bit floating-point number.
92    F32(f32),
93    /// A 64-bit floating-point number.
94    F64(f64),
95    /// A Boolean value.
96    Bool(bool),
97    /// A UTF-8 string, borrowed from the input when possible.
98    String(Cow<'a, str>),
99    /// A byte array or byte vector, borrowed from the input when possible.
100    Bytes(Cow<'a, [u8]>),
101    /// A lazily decoded array or vector of non-byte primitives.
102    Vec(LazyVec<'a>),
103}
104
105impl Value<'_> {
106    /// Returns the number of encoded payload bytes held by this value.
107    ///
108    /// For scalar primitives this is their complete encoded width. For
109    /// strings, bytes, and lazy vectors this is only the payload length and
110    /// excludes any length prefix from a dynamically sized string or vector.
111    /// Consequently, this is not necessarily the complete serialized size of
112    /// the original field.
113    #[inline]
114    pub fn size(&self) -> usize {
115        match self {
116            Value::U8(_) => 1,
117            Value::U16(_) => 2,
118            Value::U32(_) => 4,
119            Value::U64(_) => 8,
120            Value::I8(_) => 1,
121            Value::I16(_) => 2,
122            Value::I32(_) => 4,
123            Value::I64(_) => 8,
124            Value::F32(_) => 4,
125            Value::F64(_) => 8,
126            Value::Bool(_) => 1,
127            Value::String(str) => str.len(),
128            Value::Bytes(bytes) => bytes.len(),
129            Value::Vec(vec) => vec.payload.len(),
130        }
131    }
132}
133
134/// A lazily decoded vector of fixed-width primitive values.
135///
136/// The encoded payload remains borrowed when the input reader supports stable
137/// borrowing. Use [`Self::try_iter_as`] to iterate by reference when the
138/// concrete element type is known, [`Self::try_into_iter_as`] to create an
139/// owning iterator, or [`Self::into_dyn_vec`] to decode dynamically typed
140/// values.
141#[derive(Debug, Clone, PartialEq)]
142pub struct LazyVec<'a> {
143    ty: PrimitiveTy,
144    payload: Cow<'a, [u8]>,
145    /// The length of the vector, in _elements_ (not bytes).
146    ///
147    /// Invariant: `payload.len() == len * ty.size()`.
148    len: usize,
149}
150
151/// Lazy-vector iterator types.
152pub mod lazy_vec {
153    use {super::*, crate::DynPrimitiveTy};
154
155    /// A borrowing, lazy iterator over the elements of a [`LazyVec`].
156    ///
157    /// Each item is decoded only when [`Iterator::next`] is called.
158    #[derive(Debug, Clone, Copy)]
159    pub struct Iter<'a, As> {
160        payload: &'a [u8],
161        len: usize,
162        index: usize,
163        _marker: PhantomData<As>,
164    }
165
166    /// An owning, lazy iterator over the elements of a [`LazyVec`].
167    ///
168    /// Each item is decoded only when [`Iterator::next`] is called.
169    #[derive(Debug, Clone)]
170    pub struct IntoIter<'a, As> {
171        payload: Cow<'a, [u8]>,
172        len: usize,
173        index: usize,
174        _marker: PhantomData<As>,
175    }
176
177    impl<'a> LazyVec<'a> {
178        /// # Safety
179        ///
180        /// `payload.len()` must equal `len * ty.size()`.
181        pub(crate) unsafe fn new_unchecked(
182            ty: PrimitiveTy,
183            len: usize,
184            payload: Cow<'a, [u8]>,
185        ) -> Self {
186            Self { ty, len, payload }
187        }
188
189        /// Returns a borrowing, lazy iterator of `As` values.
190        ///
191        /// The requested type must match the primitive element type recorded in
192        /// the schema. This prevents, for example, interpreting the payload of
193        /// a `Vec<u64>` as a sequence of `u8` values.
194        ///
195        /// This method validates the element type and its width, but it does
196        /// not decode any elements. Decoding happens as the returned iterator
197        /// is advanced, and each item is returned as a [`ReadResult`].
198        /// Consequently, malformed element encodings are reported by
199        /// the iterator item that encounters them rather than by this
200        /// method.
201        ///
202        /// The iterator borrows this lazy vector. Multiple iterators can be
203        /// created without cloning or decoding the payload.
204        ///
205        /// To iterate, `As` must also implement
206        /// [`SchemaRead<DefaultConfig, Dst = As>`](SchemaRead).
207        ///
208        /// # Errors
209        ///
210        /// Returns an error if:
211        ///
212        /// - `As` does not match the vector's recorded primitive element type;
213        ///   or
214        /// - the size of `As` does not match the recorded element width.
215        ///
216        /// # Examples
217        ///
218        /// ```
219        /// use wincode::{ReadResult, SchemaRead, SchemaWrite};
220        /// use wincode_dynamic::{Decoder, SchemaDynamic, Value};
221        ///
222        /// #[derive(SchemaDynamic, SchemaRead, SchemaWrite)]
223        /// struct Message {
224        ///     values: Vec<u64>,
225        /// }
226        ///
227        /// let encoded = wincode::serialize(&Message {
228        ///     values: vec![10, 20, 30],
229        /// })
230        /// .expect("serialize message");
231        /// let schema = Message::schema();
232        /// let decoder = Decoder::new(&schema);
233        /// let mut fields = decoder.fields(encoded.as_slice())?;
234        ///
235        /// let field = fields.next().expect("values field")?;
236        /// assert_eq!(field.name(), "values");
237        /// let Value::Vec(values) = field.value() else {
238        ///     panic!("expected a vector");
239        /// };
240        /// let values = values
241        ///     .try_iter_as::<u64>()?
242        ///     .collect::<ReadResult<Vec<_>>>()?;
243        ///
244        /// assert_eq!(values, [10, 20, 30]);
245        /// # Ok::<(), wincode::ReadError>(())
246        /// ```
247        #[inline]
248        pub fn try_iter_as<'iter, As>(&'iter self) -> ReadResult<Iter<'iter, As>>
249        where
250            As: DynPrimitiveTy,
251        {
252            validate_element_type::<As>(self.ty)?;
253
254            Ok(Iter {
255                len: self.len,
256                payload: self.payload.as_ref(),
257                index: 0,
258                _marker: PhantomData,
259            })
260        }
261
262        /// Converts this vector into an owning, lazy iterator of `As` values.
263        ///
264        /// This performs the same type validation as [`Self::try_iter_as`], but
265        /// consumes the lazy vector and moves its payload into the iterator.
266        /// Borrowed payloads remain borrowed, and owned payloads are moved
267        /// without cloning or reallocating them.
268        ///
269        /// # Errors
270        ///
271        /// Returns an error if `As` does not match the vector's recorded
272        /// primitive element type or width.
273        #[inline]
274        pub fn try_into_iter_as<As>(self) -> ReadResult<IntoIter<'a, As>>
275        where
276            As: DynPrimitiveTy,
277        {
278            validate_element_type::<As>(self.ty)?;
279
280            Ok(IntoIter {
281                len: self.len,
282                payload: self.payload,
283                index: 0,
284                _marker: PhantomData,
285            })
286        }
287
288        /// Converts this lazy vector into a [`Vec<PrimitiveValue>`] by decoding
289        /// all elements using the vector's recorded primitive element type.
290        ///
291        /// # Errors
292        ///
293        /// Returns the first element decoding error encountered in the payload.
294        #[inline]
295        pub fn into_dyn_vec(self) -> ReadResult<Vec<PrimitiveValue>> {
296            <<DefaultConfig as Config>::LengthEncoding as SeqLen<DefaultConfig>>::prealloc_check::<
297                PrimitiveValue,
298            >(self.len)?;
299            <Array<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::get_with_context(
300                (Len(self.len), self.ty),
301                &self.payload[..],
302            )
303        }
304
305        /// Returns the number of elements in the vector.
306        #[inline]
307        pub const fn len(&self) -> usize {
308            self.len
309        }
310
311        /// Returns `true` if the vector contains no elements.
312        #[inline]
313        pub fn is_empty(&self) -> bool {
314            self.payload.is_empty()
315        }
316
317        #[cfg(all(test, feature = "std"))]
318        pub(crate) fn has_borrowed_payload(&self) -> bool {
319            matches!(self.payload, Cow::Borrowed(_))
320        }
321
322        /// Returns the vector's primitive element type.
323        #[inline]
324        pub const fn ty(&self) -> PrimitiveTy {
325            self.ty
326        }
327    }
328
329    #[inline]
330    fn validate_element_type<As: DynPrimitiveTy>(ty: PrimitiveTy) -> ReadResult<()> {
331        #[cold]
332        const fn ty_mismatch() -> ReadError {
333            ReadError::Custom("lazy vector element type mismatch")
334        }
335
336        if As::TYPE != ty || ty.size() != size_of::<As>() {
337            return Err(ty_mismatch());
338        }
339
340        Ok(())
341    }
342
343    macro_rules! impl_iterator {
344        ($iter:ident) => {
345            impl<As> Iterator for $iter<'_, As>
346            where
347                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>,
348            {
349                type Item = ReadResult<As>;
350
351                #[inline]
352                fn next(&mut self) -> Option<Self::Item> {
353                    if self.index >= self.len {
354                        return None;
355                    }
356                    let start = self.index * size_of::<As>();
357                    // SAFETY:
358                    // - `payload.len()` is an exact multiple of `size_of::<As>()`.
359                    // - `len` is `payload.len() / size_of::<As>()`.
360                    // - `index < len`, so `start < payload.len()`.
361                    let remaining = unsafe { self.payload.as_ref().get_unchecked(start..) };
362                    let item = As::get(remaining);
363                    self.index += 1;
364                    Some(item)
365                }
366
367                #[inline]
368                fn size_hint(&self) -> (usize, Option<usize>) {
369                    let remaining = self.len - self.index;
370                    (remaining, Some(remaining))
371                }
372            }
373
374            impl<As> ExactSizeIterator for $iter<'_, As>
375            where
376                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>,
377            {
378                #[inline]
379                fn len(&self) -> usize {
380                    self.len - self.index
381                }
382            }
383
384            impl<As> core::iter::FusedIterator for $iter<'_, As> where
385                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>
386            {
387            }
388        };
389    }
390
391    impl_iterator!(Iter);
392    impl_iterator!(IntoIter);
393}
394
395unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, PrimitiveTy> for PrimitiveValue {
396    type Dst = Self;
397
398    #[inline]
399    fn read_with_context(
400        ctx: PrimitiveTy,
401        reader: impl Reader<'de>,
402        dst: &mut MaybeUninit<Self::Dst>,
403    ) -> ReadResult<()> {
404        let val = match ctx {
405            PrimitiveTy::U8 => <u8 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U8)?,
406            PrimitiveTy::U16 => <u16 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U16)?,
407            PrimitiveTy::U32 => <u32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U32)?,
408            PrimitiveTy::U64 => <u64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U64)?,
409            PrimitiveTy::I8 => <i8 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I8)?,
410            PrimitiveTy::I16 => <i16 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I16)?,
411            PrimitiveTy::I32 => <i32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I32)?,
412            PrimitiveTy::I64 => <i64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I64)?,
413            PrimitiveTy::F32 => <f32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::F32)?,
414            PrimitiveTy::F64 => <f64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::F64)?,
415            PrimitiveTy::Bool => <bool as SchemaRead<C>>::get(reader).map(PrimitiveValue::Bool)?,
416        };
417
418        dst.write(val);
419
420        Ok(())
421    }
422}
423
424unsafe impl<'de> SchemaReadContext<'de, DefaultConfig, PrimitiveTy> for usize {
425    type Dst = Self;
426
427    #[inline]
428    fn read_with_context(
429        ctx: PrimitiveTy,
430        reader: impl Reader<'de>,
431        dst: &mut MaybeUninit<Self::Dst>,
432    ) -> ReadResult<()> {
433        #[inline]
434        fn try_cast_to_usize(val: impl TryInto<usize>) -> ReadResult<usize> {
435            #[cold]
436            fn err() -> ReadError {
437                ReadError::Custom("cannot cast to usize")
438            }
439            val.try_into().map_err(|_| err())
440        }
441
442        let val = match ctx {
443            PrimitiveTy::U8 => <u8 as SchemaRead<DefaultConfig>>::get(reader).map(usize::from)?,
444            PrimitiveTy::U16 => <u16 as SchemaRead<DefaultConfig>>::get(reader).map(usize::from)?,
445            PrimitiveTy::U32 => {
446                <u32 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
447            }
448            PrimitiveTy::U64 => {
449                <u64 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
450            }
451            PrimitiveTy::I8 => {
452                <i8 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
453            }
454            PrimitiveTy::I16 => {
455                <i16 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
456            }
457            PrimitiveTy::I32 => {
458                <i32 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
459            }
460            PrimitiveTy::I64 => {
461                <i64 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
462            }
463            _ => return Err(ReadError::Custom("cannot cast to usize")),
464        };
465
466        dst.write(val);
467
468        Ok(())
469    }
470}
471unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, PrimitiveTy> for Value<'de> {
472    type Dst = Self;
473
474    #[inline]
475    fn read_with_context(
476        ctx: PrimitiveTy,
477        reader: impl Reader<'de>,
478        dst: &mut MaybeUninit<Self::Dst>,
479    ) -> ReadResult<()> {
480        let val = match ctx {
481            PrimitiveTy::U8 => <u8 as SchemaRead<C>>::get(reader).map(Value::U8)?,
482            PrimitiveTy::U16 => <u16 as SchemaRead<C>>::get(reader).map(Value::U16)?,
483            PrimitiveTy::U32 => <u32 as SchemaRead<C>>::get(reader).map(Value::U32)?,
484            PrimitiveTy::U64 => <u64 as SchemaRead<C>>::get(reader).map(Value::U64)?,
485            PrimitiveTy::I8 => <i8 as SchemaRead<C>>::get(reader).map(Value::I8)?,
486            PrimitiveTy::I16 => <i16 as SchemaRead<C>>::get(reader).map(Value::I16)?,
487            PrimitiveTy::I32 => <i32 as SchemaRead<C>>::get(reader).map(Value::I32)?,
488            PrimitiveTy::I64 => <i64 as SchemaRead<C>>::get(reader).map(Value::I64)?,
489            PrimitiveTy::F32 => <f32 as SchemaRead<C>>::get(reader).map(Value::F32)?,
490            PrimitiveTy::F64 => <f64 as SchemaRead<C>>::get(reader).map(Value::F64)?,
491            PrimitiveTy::Bool => <bool as SchemaRead<C>>::get(reader).map(Value::Bool)?,
492        };
493
494        dst.write(val);
495
496        Ok(())
497    }
498}
499
500unsafe impl<'de> SchemaReadContext<'de, DefaultConfig, PrimitiveTy> for Vec<PrimitiveValue> {
501    type Dst = Self;
502
503    #[inline]
504    fn read_with_context(
505        ctx: PrimitiveTy,
506        reader: impl Reader<'de>,
507        dst: &mut MaybeUninit<Self::Dst>,
508    ) -> ReadResult<()> {
509        match ctx {
510            PrimitiveTy::U8 => {
511                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
512                    Map::new(PrimitiveValue::U8),
513                    reader,
514                    dst,
515                )
516            }
517            PrimitiveTy::U16 => {
518                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
519                    Map::new(PrimitiveValue::U16),
520                    reader,
521                    dst,
522                )
523            }
524            PrimitiveTy::U32 => {
525                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
526                    Map::new(PrimitiveValue::U32),
527                    reader,
528                    dst,
529                )
530            }
531            PrimitiveTy::U64 => {
532                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
533                    Map::new(PrimitiveValue::U64),
534                    reader,
535                    dst,
536                )
537            }
538            PrimitiveTy::I8 => {
539                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
540                    Map::new(PrimitiveValue::I8),
541                    reader,
542                    dst,
543                )
544            }
545            PrimitiveTy::I16 => {
546                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
547                    Map::new(PrimitiveValue::I16),
548                    reader,
549                    dst,
550                )
551            }
552            PrimitiveTy::I32 => {
553                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
554                    Map::new(PrimitiveValue::I32),
555                    reader,
556                    dst,
557                )
558            }
559            PrimitiveTy::I64 => {
560                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
561                    Map::new(PrimitiveValue::I64),
562                    reader,
563                    dst,
564                )
565            }
566            PrimitiveTy::F32 => {
567                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
568                    Map::new(PrimitiveValue::F32),
569                    reader,
570                    dst,
571                )
572            }
573            PrimitiveTy::F64 => {
574                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
575                    Map::new(PrimitiveValue::F64),
576                    reader,
577                    dst,
578                )
579            }
580            PrimitiveTy::Bool => {
581                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
582                    Map::new(PrimitiveValue::Bool),
583                    reader,
584                    dst,
585                )
586            }
587        }
588    }
589}
590
591pub(crate) struct Array<T> {
592    _marker: core::marker::PhantomData<T>,
593}
594
595unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, (Len, PrimitiveTy)>
596    for Array<PrimitiveValue>
597{
598    type Dst = Vec<PrimitiveValue>;
599
600    #[inline]
601    fn read_with_context(
602        ctx: (Len, PrimitiveTy),
603        reader: impl Reader<'de>,
604        dst: &mut MaybeUninit<Self::Dst>,
605    ) -> ReadResult<()> {
606        let (Len(len), ty) = ctx;
607
608        match ty {
609            PrimitiveTy::U8 => {
610                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
611                    LenMap::new(len, PrimitiveValue::U8),
612                    reader,
613                    dst,
614                )
615            }
616            PrimitiveTy::U16 => {
617                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
618                    LenMap::new(len, PrimitiveValue::U16),
619                    reader,
620                    dst,
621                )
622            }
623            PrimitiveTy::U32 => {
624                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
625                    LenMap::new(len, PrimitiveValue::U32),
626                    reader,
627                    dst,
628                )
629            }
630            PrimitiveTy::U64 => {
631                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
632                    LenMap::new(len, PrimitiveValue::U64),
633                    reader,
634                    dst,
635                )
636            }
637            PrimitiveTy::I8 => {
638                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
639                    LenMap::new(len, PrimitiveValue::I8),
640                    reader,
641                    dst,
642                )
643            }
644            PrimitiveTy::I16 => {
645                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
646                    LenMap::new(len, PrimitiveValue::I16),
647                    reader,
648                    dst,
649                )
650            }
651            PrimitiveTy::I32 => {
652                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
653                    LenMap::new(len, PrimitiveValue::I32),
654                    reader,
655                    dst,
656                )
657            }
658            PrimitiveTy::I64 => {
659                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
660                    LenMap::new(len, PrimitiveValue::I64),
661                    reader,
662                    dst,
663                )
664            }
665            PrimitiveTy::F32 => {
666                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
667                    LenMap::new(len, PrimitiveValue::F32),
668                    reader,
669                    dst,
670                )
671            }
672            PrimitiveTy::F64 => {
673                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
674                    LenMap::new(len, PrimitiveValue::F64),
675                    reader,
676                    dst,
677                )
678            }
679            PrimitiveTy::Bool => {
680                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
681                    LenMap::new(len, PrimitiveValue::Bool),
682                    reader,
683                    dst,
684                )
685            }
686        }
687    }
688}