1use std::cmp::Ordering;
2use std::collections::*;
3
4mod attributes;
5mod bindings;
6mod blob;
7mod codes;
8mod column;
9mod file;
10mod filter;
11mod reader;
12mod row;
13mod table;
14mod tables;
15mod r#type;
16mod type_name;
17
18pub use attributes::*;
19pub use bindings::*;
20pub use blob::*;
21pub use codes::*;
22use column::*;
23pub use file::*;
24use filter::*;
25pub use r#type::*;
26pub use reader::*;
27pub use row::*;
28use table::*;
29pub use tables::*;
30pub use type_name::*;
31
32#[repr(C)]
33#[derive(Default)]
34pub 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
45pub 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.
50pub 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)]
77pub 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
94pub struct MethodDefSig {
95 pub call_flags: MethodCallAttributes,
96 pub return_type: Type,
97 pub params: Vec<Type>,
98}
99
100impl 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)]
107pub enum TypeKind {
108 Interface,
109 Class,
110 Enum,
111 Struct,
112 Delegate,
113}
114