1 | use std::cmp::Ordering; |
2 | use std::collections::*; |
3 | |
4 | mod attributes; |
5 | mod bindings; |
6 | mod blob; |
7 | mod codes; |
8 | mod column; |
9 | mod file; |
10 | mod filter; |
11 | mod reader; |
12 | mod row; |
13 | mod table; |
14 | mod tables; |
15 | mod r#type; |
16 | mod type_name; |
17 | |
18 | pub use attributes::*; |
19 | pub use bindings::*; |
20 | pub use blob::*; |
21 | pub use codes::*; |
22 | use column::*; |
23 | pub use file::*; |
24 | use filter::*; |
25 | pub use r#type::*; |
26 | pub use reader::*; |
27 | pub use row::*; |
28 | use table::*; |
29 | pub use tables::*; |
30 | pub use type_name::*; |
31 | |
32 | #[repr (C)] |
33 | #[derive (Default)] |
34 | pub struct METADATA_HEADER { |
35 | pub signature: u32, |
36 | pub major_version: u16, |
37 | pub minor_version: u16, |
38 | pub reserved: u32, |
39 | pub length: u32, |
40 | pub version: [u8; 20], |
41 | pub flags: u16, |
42 | pub streams: u16, |
43 | } |
44 | |
45 | pub const METADATA_SIGNATURE: u32 = 0x424A_5342; |
46 | |
47 | /// A coded index (see codes.rs) is a table index that may refer to different tables. The size of the column in memory |
48 | /// must therefore be large enough to hold an index for a row in the largest possible table. This function determines |
49 | /// this size for the given winmd file. |
50 | pub fn coded_index_size(tables: &[usize]) -> usize { |
51 | fn small(row_count: usize, bits: u8) -> bool { |
52 | (row_count as u64) < (1u64 << (16 - bits)) |
53 | } |
54 | |
55 | fn bits_needed(value: usize) -> u8 { |
56 | let mut value = value - 1; |
57 | let mut bits: u8 = 1; |
58 | while { |
59 | value >>= 1; |
60 | value != 0 |
61 | } { |
62 | bits += 1; |
63 | } |
64 | bits |
65 | } |
66 | |
67 | let bits_needed = bits_needed(tables.len()); |
68 | |
69 | if tables.iter().all(|table| small(*table, bits_needed)) { |
70 | 2 |
71 | } else { |
72 | 4 |
73 | } |
74 | } |
75 | |
76 | #[derive (Debug)] |
77 | pub enum Value { |
78 | Bool(bool), |
79 | U8(u8), |
80 | I8(i8), |
81 | U16(u16), |
82 | I16(i16), |
83 | U32(u32), |
84 | I32(i32), |
85 | U64(u64), |
86 | I64(i64), |
87 | F32(f32), |
88 | F64(f64), |
89 | String(String), |
90 | TypeName(TypeName), |
91 | EnumDef(TypeDef, Box<Self>), |
92 | } |
93 | |
94 | pub struct MethodDefSig { |
95 | pub call_flags: MethodCallAttributes, |
96 | pub return_type: Type, |
97 | pub params: Vec<Type>, |
98 | } |
99 | |
100 | impl MethodDefSig { |
101 | pub fn size(&self) -> usize { |
102 | self.params.iter().fold(init:0, |sum: usize, param: &Type| sum + std::cmp::max(v1:4, v2:param.size())) |
103 | } |
104 | } |
105 | |
106 | #[derive (Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord)] |
107 | pub enum TypeKind { |
108 | Interface, |
109 | Class, |
110 | Enum, |
111 | Struct, |
112 | Delegate, |
113 | } |
114 | |