1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! Type marshalling for native code invocations and COM interop in .NET assemblies.
//!
//! This module provides constants, types, and logic for parsing and representing native type marshalling
//! as defined in ECMA-335 II.23.2.9 and extended by CoreCLR. It supports marshalling for P/Invoke, COM interop,
//! and other native interop scenarios.
//!
//! # Marshalling Overview
//!
//! .NET marshalling converts managed types to/from native types for interoperability:
//! - **P/Invoke**: Platform Invoke for calling unmanaged functions in DLLs
//! - **COM Interop**: Communication with Component Object Model interfaces
//! - **Windows Runtime**: Integration with WinRT APIs and types
//! - **Custom Marshalling**: User-defined type conversion logic
//!
//! # Supported Native Types
//!
//! The implementation supports all native types from ECMA-335 and CoreCLR:
//! - **Primitive Types**: Integers, floats, booleans, characters
//! - **String Types**: ANSI, Unicode, UTF-8 strings with various encodings
//! - **Array Types**: Fixed arrays, variable arrays, safe arrays
//! - **Pointer Types**: Raw pointers with optional type information
//! - **Interface Types**: COM interfaces (IUnknown, IDispatch, IInspectable)
//! - **Structured Types**: Native structs with packing and size information
//! - **Custom Types**: User-defined marshalling with custom marshalers
//!
//! # Marshalling Descriptors
//!
//! Marshalling information is encoded as binary descriptors containing:
//! 1. **Primary Type**: The main native type to marshal to/from
//! 2. **Parameters**: Size information, parameter indices, and type details
//! 3. **Additional Types**: Secondary types for complex marshalling scenarios
//! 4. **End Marker**: Termination indicator for descriptor boundaries
//!
//! # Thread Safety
//!
//! All types in this module are thread-safe:
//! - **Constants**: Immutable static values
//! - **Enums/Structs**: No internal mutability
//! - **Parsers**: Stateless after construction
//!
//! # Key Components
//!
//! - [`crate::metadata::marshalling::NATIVE_TYPE`] - Constants for all native types used in marshalling
//! - [`crate::metadata::marshalling::VARIANT_TYPE`] - COM variant type constants for safe arrays
//! - [`crate::metadata::marshalling::NativeType`] - Enumeration of all supported native type variants
//! - [`crate::metadata::marshalling::MarshallingInfo`] - Complete marshalling descriptor representation
//! - [`crate::metadata::marshalling::MarshallingParser`] - Parser for binary marshalling descriptors
//! - [`crate::metadata::marshalling::parse_marshalling_descriptor`] - Convenience function for parsing
//! - [`crate::metadata::marshalling::MarshallingEncoder`] - Encoder for binary marshalling descriptors
//! - [`crate::metadata::marshalling::encode_marshalling_descriptor`] - Convenience function for encoding
//!
//! # Examples
//!
//! ## Parsing Simple Types
//!
//! ```rust,no_run
//! use dotscope::metadata::marshalling::{parse_marshalling_descriptor, NativeType, NATIVE_TYPE};
//!
//! # fn main() -> dotscope::Result<()> {
//! // Parse a simple LPSTR marshalling descriptor
//! let descriptor_bytes = &[NATIVE_TYPE::LPSTR, 0x05]; // LPSTR with size param 5
//! let info = parse_marshalling_descriptor(descriptor_bytes)?;
//!
//! match info.primary_type {
//! NativeType::LPStr { size_param_index: Some(5) } => {
//! println!("LPSTR with size parameter index 5");
//! }
//! _ => unreachable!(),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Parsing Complex Arrays
//!
//! ```rust,no_run
//! use dotscope::metadata::marshalling::{MarshallingParser, NativeType, NATIVE_TYPE};
//!
//! # fn main() -> dotscope::Result<()> {
//! // Parse an array descriptor: Array<I4>[param=3, size=10]
//! let descriptor_bytes = &[
//! NATIVE_TYPE::ARRAY,
//! NATIVE_TYPE::I4,
//! 0x03, // Parameter index 3
//! 0x0A // Array size 10
//! ];
//!
//! let mut parser = MarshallingParser::new(descriptor_bytes);
//! let native_type = parser.parse_native_type()?;
//!
//! match native_type {
//! NativeType::Array { element_type, num_param, num_element } => {
//! println!("Array of {:?}, param: {:?}, size: {:?}",
//! element_type, num_param, num_element);
//! }
//! _ => unreachable!(),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Working with Custom Marshalers
//!
//! ```rust,no_run
//! use dotscope::metadata::marshalling::NativeType;
//!
//! # fn example(native_type: &NativeType) {
//! match native_type {
//! NativeType::CustomMarshaler { guid, native_type_name, cookie, type_reference } => {
//! println!("Custom marshaler: GUID={}, Type={}, Cookie={}, Ref={}",
//! guid, native_type_name, cookie, type_reference);
//! }
//! _ => { /* Handle other types */ }
//! }
//! # }
//! ```
//!
//! ## Encoding Marshalling Descriptors
//!
//! ```rust,no_run
//! use dotscope::metadata::marshalling::{encode_marshalling_descriptor, NativeType, MarshallingInfo};
//!
//! # fn main() -> dotscope::Result<()> {
//! // Create a marshalling descriptor
//! let info = MarshallingInfo {
//! primary_type: NativeType::LPStr { size_param_index: Some(5) },
//! additional_types: vec![],
//! };
//!
//! // Encode to binary format
//! let bytes = encode_marshalling_descriptor(&info)?;
//! // Result: [NATIVE_TYPE::LPSTR, 0x05]
//! # Ok(())
//! # }
//! ```
pub use *;
pub use *;
pub use *;