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 decoder = Decoder::new(Message::schema());
232        /// let mut fields = decoder.fields(encoded.as_slice())?;
233        ///
234        /// let field = fields.next().expect("values field")?;
235        /// assert_eq!(field.name(), "values");
236        /// let Value::Vec(values) = field.value() else {
237        ///     panic!("expected a vector");
238        /// };
239        /// let values = values
240        ///     .try_iter_as::<u64>()?
241        ///     .collect::<ReadResult<Vec<_>>>()?;
242        ///
243        /// assert_eq!(values, [10, 20, 30]);
244        /// # Ok::<(), wincode::ReadError>(())
245        /// ```
246        #[inline]
247        pub fn try_iter_as<'iter, As>(&'iter self) -> ReadResult<Iter<'iter, As>>
248        where
249            As: DynPrimitiveTy,
250        {
251            validate_element_type::<As>(self.ty)?;
252
253            Ok(Iter {
254                len: self.len,
255                payload: self.payload.as_ref(),
256                index: 0,
257                _marker: PhantomData,
258            })
259        }
260
261        /// Converts this vector into an owning, lazy iterator of `As` values.
262        ///
263        /// This performs the same type validation as [`Self::try_iter_as`], but
264        /// consumes the lazy vector and moves its payload into the iterator.
265        /// Borrowed payloads remain borrowed, and owned payloads are moved
266        /// without cloning or reallocating them.
267        ///
268        /// # Errors
269        ///
270        /// Returns an error if `As` does not match the vector's recorded
271        /// primitive element type or width.
272        #[inline]
273        pub fn try_into_iter_as<As>(self) -> ReadResult<IntoIter<'a, As>>
274        where
275            As: DynPrimitiveTy,
276        {
277            validate_element_type::<As>(self.ty)?;
278
279            Ok(IntoIter {
280                len: self.len,
281                payload: self.payload,
282                index: 0,
283                _marker: PhantomData,
284            })
285        }
286
287        /// Converts this lazy vector into a [`Vec<PrimitiveValue>`] by decoding
288        /// all elements using the vector's recorded primitive element type.
289        ///
290        /// # Errors
291        ///
292        /// Returns the first element decoding error encountered in the payload.
293        #[inline]
294        pub fn into_dyn_vec(self) -> ReadResult<Vec<PrimitiveValue>> {
295            <<DefaultConfig as Config>::LengthEncoding as SeqLen<DefaultConfig>>::prealloc_check::<
296                PrimitiveValue,
297            >(self.len)?;
298            <Array<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::get_with_context(
299                (Len(self.len), self.ty),
300                &self.payload[..],
301            )
302        }
303
304        /// Returns the number of elements in the vector.
305        #[inline]
306        pub const fn len(&self) -> usize {
307            self.len
308        }
309
310        /// Returns `true` if the vector contains no elements.
311        #[inline]
312        pub fn is_empty(&self) -> bool {
313            self.payload.is_empty()
314        }
315
316        #[cfg(all(test, feature = "std"))]
317        pub(crate) fn has_borrowed_payload(&self) -> bool {
318            matches!(self.payload, Cow::Borrowed(_))
319        }
320
321        /// Returns the vector's primitive element type.
322        #[inline]
323        pub const fn ty(&self) -> PrimitiveTy {
324            self.ty
325        }
326    }
327
328    #[inline]
329    fn validate_element_type<As: DynPrimitiveTy>(ty: PrimitiveTy) -> ReadResult<()> {
330        #[cold]
331        const fn ty_mismatch() -> ReadError {
332            ReadError::Custom("lazy vector element type mismatch")
333        }
334
335        if As::TYPE != ty || ty.size() != size_of::<As>() {
336            return Err(ty_mismatch());
337        }
338
339        Ok(())
340    }
341
342    macro_rules! impl_iterator {
343        ($iter:ident) => {
344            impl<As> Iterator for $iter<'_, As>
345            where
346                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>,
347            {
348                type Item = ReadResult<As>;
349
350                #[inline]
351                fn next(&mut self) -> Option<Self::Item> {
352                    if self.index >= self.len {
353                        return None;
354                    }
355                    let start = self.index * size_of::<As>();
356                    // SAFETY:
357                    // - `payload.len()` is an exact multiple of `size_of::<As>()`.
358                    // - `len` is `payload.len() / size_of::<As>()`.
359                    // - `index < len`, so `start < payload.len()`.
360                    let remaining = unsafe { self.payload.as_ref().get_unchecked(start..) };
361                    let item = As::get(remaining);
362                    self.index += 1;
363                    Some(item)
364                }
365
366                #[inline]
367                fn size_hint(&self) -> (usize, Option<usize>) {
368                    let remaining = self.len - self.index;
369                    (remaining, Some(remaining))
370                }
371            }
372
373            impl<As> ExactSizeIterator for $iter<'_, As>
374            where
375                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>,
376            {
377                #[inline]
378                fn len(&self) -> usize {
379                    self.len - self.index
380                }
381            }
382
383            impl<As> core::iter::FusedIterator for $iter<'_, As> where
384                As: for<'de> SchemaRead<'de, DefaultConfig, Dst = As>
385            {
386            }
387        };
388    }
389
390    impl_iterator!(Iter);
391    impl_iterator!(IntoIter);
392}
393
394unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, PrimitiveTy> for PrimitiveValue {
395    type Dst = Self;
396
397    #[inline]
398    fn read_with_context(
399        ctx: PrimitiveTy,
400        reader: impl Reader<'de>,
401        dst: &mut MaybeUninit<Self::Dst>,
402    ) -> ReadResult<()> {
403        let val = match ctx {
404            PrimitiveTy::U8 => <u8 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U8)?,
405            PrimitiveTy::U16 => <u16 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U16)?,
406            PrimitiveTy::U32 => <u32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U32)?,
407            PrimitiveTy::U64 => <u64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::U64)?,
408            PrimitiveTy::I8 => <i8 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I8)?,
409            PrimitiveTy::I16 => <i16 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I16)?,
410            PrimitiveTy::I32 => <i32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I32)?,
411            PrimitiveTy::I64 => <i64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::I64)?,
412            PrimitiveTy::F32 => <f32 as SchemaRead<C>>::get(reader).map(PrimitiveValue::F32)?,
413            PrimitiveTy::F64 => <f64 as SchemaRead<C>>::get(reader).map(PrimitiveValue::F64)?,
414            PrimitiveTy::Bool => <bool as SchemaRead<C>>::get(reader).map(PrimitiveValue::Bool)?,
415        };
416
417        dst.write(val);
418
419        Ok(())
420    }
421}
422
423unsafe impl<'de> SchemaReadContext<'de, DefaultConfig, PrimitiveTy> for usize {
424    type Dst = Self;
425
426    #[inline]
427    fn read_with_context(
428        ctx: PrimitiveTy,
429        reader: impl Reader<'de>,
430        dst: &mut MaybeUninit<Self::Dst>,
431    ) -> ReadResult<()> {
432        #[inline]
433        fn try_cast_to_usize(val: impl TryInto<usize>) -> ReadResult<usize> {
434            #[cold]
435            fn err() -> ReadError {
436                ReadError::Custom("cannot cast to usize")
437            }
438            val.try_into().map_err(|_| err())
439        }
440
441        let val = match ctx {
442            PrimitiveTy::U8 => <u8 as SchemaRead<DefaultConfig>>::get(reader).map(usize::from)?,
443            PrimitiveTy::U16 => <u16 as SchemaRead<DefaultConfig>>::get(reader).map(usize::from)?,
444            PrimitiveTy::U32 => {
445                <u32 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
446            }
447            PrimitiveTy::U64 => {
448                <u64 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
449            }
450            PrimitiveTy::I8 => {
451                <i8 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
452            }
453            PrimitiveTy::I16 => {
454                <i16 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
455            }
456            PrimitiveTy::I32 => {
457                <i32 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
458            }
459            PrimitiveTy::I64 => {
460                <i64 as SchemaRead<DefaultConfig>>::get(reader).and_then(try_cast_to_usize)?
461            }
462            _ => return Err(ReadError::Custom("cannot cast to usize")),
463        };
464
465        dst.write(val);
466
467        Ok(())
468    }
469}
470unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, PrimitiveTy> for Value<'de> {
471    type Dst = Self;
472
473    #[inline]
474    fn read_with_context(
475        ctx: PrimitiveTy,
476        reader: impl Reader<'de>,
477        dst: &mut MaybeUninit<Self::Dst>,
478    ) -> ReadResult<()> {
479        let val = match ctx {
480            PrimitiveTy::U8 => <u8 as SchemaRead<C>>::get(reader).map(Value::U8)?,
481            PrimitiveTy::U16 => <u16 as SchemaRead<C>>::get(reader).map(Value::U16)?,
482            PrimitiveTy::U32 => <u32 as SchemaRead<C>>::get(reader).map(Value::U32)?,
483            PrimitiveTy::U64 => <u64 as SchemaRead<C>>::get(reader).map(Value::U64)?,
484            PrimitiveTy::I8 => <i8 as SchemaRead<C>>::get(reader).map(Value::I8)?,
485            PrimitiveTy::I16 => <i16 as SchemaRead<C>>::get(reader).map(Value::I16)?,
486            PrimitiveTy::I32 => <i32 as SchemaRead<C>>::get(reader).map(Value::I32)?,
487            PrimitiveTy::I64 => <i64 as SchemaRead<C>>::get(reader).map(Value::I64)?,
488            PrimitiveTy::F32 => <f32 as SchemaRead<C>>::get(reader).map(Value::F32)?,
489            PrimitiveTy::F64 => <f64 as SchemaRead<C>>::get(reader).map(Value::F64)?,
490            PrimitiveTy::Bool => <bool as SchemaRead<C>>::get(reader).map(Value::Bool)?,
491        };
492
493        dst.write(val);
494
495        Ok(())
496    }
497}
498
499unsafe impl<'de> SchemaReadContext<'de, DefaultConfig, PrimitiveTy> for Vec<PrimitiveValue> {
500    type Dst = Self;
501
502    #[inline]
503    fn read_with_context(
504        ctx: PrimitiveTy,
505        reader: impl Reader<'de>,
506        dst: &mut MaybeUninit<Self::Dst>,
507    ) -> ReadResult<()> {
508        match ctx {
509            PrimitiveTy::U8 => {
510                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
511                    Map::new(PrimitiveValue::U8),
512                    reader,
513                    dst,
514                )
515            }
516            PrimitiveTy::U16 => {
517                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
518                    Map::new(PrimitiveValue::U16),
519                    reader,
520                    dst,
521                )
522            }
523            PrimitiveTy::U32 => {
524                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
525                    Map::new(PrimitiveValue::U32),
526                    reader,
527                    dst,
528                )
529            }
530            PrimitiveTy::U64 => {
531                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
532                    Map::new(PrimitiveValue::U64),
533                    reader,
534                    dst,
535                )
536            }
537            PrimitiveTy::I8 => {
538                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
539                    Map::new(PrimitiveValue::I8),
540                    reader,
541                    dst,
542                )
543            }
544            PrimitiveTy::I16 => {
545                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
546                    Map::new(PrimitiveValue::I16),
547                    reader,
548                    dst,
549                )
550            }
551            PrimitiveTy::I32 => {
552                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
553                    Map::new(PrimitiveValue::I32),
554                    reader,
555                    dst,
556                )
557            }
558            PrimitiveTy::I64 => {
559                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
560                    Map::new(PrimitiveValue::I64),
561                    reader,
562                    dst,
563                )
564            }
565            PrimitiveTy::F32 => {
566                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
567                    Map::new(PrimitiveValue::F32),
568                    reader,
569                    dst,
570                )
571            }
572            PrimitiveTy::F64 => {
573                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
574                    Map::new(PrimitiveValue::F64),
575                    reader,
576                    dst,
577                )
578            }
579            PrimitiveTy::Bool => {
580                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
581                    Map::new(PrimitiveValue::Bool),
582                    reader,
583                    dst,
584                )
585            }
586        }
587    }
588}
589
590pub(crate) struct Array<T> {
591    _marker: core::marker::PhantomData<T>,
592}
593
594unsafe impl<'de, C: ConfigCore> SchemaReadContext<'de, C, (Len, PrimitiveTy)>
595    for Array<PrimitiveValue>
596{
597    type Dst = Vec<PrimitiveValue>;
598
599    #[inline]
600    fn read_with_context(
601        ctx: (Len, PrimitiveTy),
602        reader: impl Reader<'de>,
603        dst: &mut MaybeUninit<Self::Dst>,
604    ) -> ReadResult<()> {
605        let (Len(len), ty) = ctx;
606
607        match ty {
608            PrimitiveTy::U8 => {
609                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
610                    LenMap::new(len, PrimitiveValue::U8),
611                    reader,
612                    dst,
613                )
614            }
615            PrimitiveTy::U16 => {
616                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
617                    LenMap::new(len, PrimitiveValue::U16),
618                    reader,
619                    dst,
620                )
621            }
622            PrimitiveTy::U32 => {
623                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
624                    LenMap::new(len, PrimitiveValue::U32),
625                    reader,
626                    dst,
627                )
628            }
629            PrimitiveTy::U64 => {
630                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
631                    LenMap::new(len, PrimitiveValue::U64),
632                    reader,
633                    dst,
634                )
635            }
636            PrimitiveTy::I8 => {
637                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
638                    LenMap::new(len, PrimitiveValue::I8),
639                    reader,
640                    dst,
641                )
642            }
643            PrimitiveTy::I16 => {
644                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
645                    LenMap::new(len, PrimitiveValue::I16),
646                    reader,
647                    dst,
648                )
649            }
650            PrimitiveTy::I32 => {
651                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
652                    LenMap::new(len, PrimitiveValue::I32),
653                    reader,
654                    dst,
655                )
656            }
657            PrimitiveTy::I64 => {
658                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
659                    LenMap::new(len, PrimitiveValue::I64),
660                    reader,
661                    dst,
662                )
663            }
664            PrimitiveTy::F32 => {
665                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
666                    LenMap::new(len, PrimitiveValue::F32),
667                    reader,
668                    dst,
669                )
670            }
671            PrimitiveTy::F64 => {
672                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
673                    LenMap::new(len, PrimitiveValue::F64),
674                    reader,
675                    dst,
676                )
677            }
678            PrimitiveTy::Bool => {
679                <Vec<PrimitiveValue> as SchemaReadContext<DefaultConfig, _>>::read_with_context(
680                    LenMap::new(len, PrimitiveValue::Bool),
681                    reader,
682                    dst,
683                )
684            }
685        }
686    }
687}