1
use crate::{
2
    binary::read::{ReadBinary, ReadCtxt, ReadFrom},
3
    error::ParseError,
4
};
5

            
6
pub const MAX_LEN: usize = 0x4000;
7
pub const MAX_OPS: isize = 0x4000;
8

            
9
/// End of text.
10
///
11
/// This class should not appear in the class array.
12
pub const CLASS_CODE_EOT: u16 = 0;
13

            
14
/// Out of bounds.
15
///
16
/// All glyph indexes that are less than firstGlyph, or greater than or equal to firstGlyph plus
17
/// nGlyphs will automatically be assigned class code 1. Class code 1 may also appear in the class
18
/// array.
19
pub const CLASS_CODE_OOB: u16 = 1;
20

            
21
/// Deleted glyph.
22
///
23
/// Sometimes contextual processing removes a glyph from the glyph array by changing its glyph
24
/// index to the deleted glyph index, 0xFFFF. This glyph code is automatically assigned class
25
/// "deleted," which should not appear in the class array.
26
pub const CLASS_CODE_DELETED: u16 = 2;
27
pub const DELETED_GLYPH: u16 = 0xFFFF;
28

            
29
#[derive(Debug)]
30
pub struct VecTable<T>(pub Vec<T>);
31

            
32
impl<T> ReadBinary for VecTable<T>
33
where
34
    T: ReadFrom,
35
{
36
    type HostType<'a> = Self;
37

            
38
    fn read(ctxt: &mut ReadCtxt<'_>) -> Result<Self, ParseError> {
39
        let mut elements = Vec::new();
40

            
41
        while let Ok(element) = ctxt.read::<T>() {
42
            elements.push(element)
43
        }
44

            
45
        Ok(VecTable::<T>(elements))
46
    }
47
}