Welcome to mirror list, hosted at ThFree Co, Russian Federation.

7.0-preview7_System.Runtime.InteropServices.Marshalling.md « Microsoft.NETCore.App « preview7 « api-diff « preview « 7.0 « release-notes - github.com/dotnet/core.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c30903352c1dbdf2c712c6cb72d86483e8fb4185 (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# System.Runtime.InteropServices.Marshalling

``` diff
 namespace System.Runtime.InteropServices.Marshalling {
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(string), CustomTypeMarshallerKind.Value, BufferSize=256, Features=CustomTypeMarshallerFeatures.CallerAllocatedBuffer | CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct AnsiStringMarshaller {
+    [CLSCompliantAttribute(false)]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.Default, typeof(AnsiStringMarshaller))]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(AnsiStringMarshaller.ManagedToUnmanagedIn))]
+    public static class AnsiStringMarshaller {
-        [NullableContextAttribute((byte)2)]
-        public AnsiStringMarshaller(string? str);
-        public AnsiStringMarshaller([NullableAttribute((byte)2)] string? str, Span<byte> buffer);
+        [return: NullableAttribute((byte)2)]
+        public unsafe static string? ConvertToManaged(byte* unmanaged);
+        public unsafe static byte* ConvertToUnmanaged([NullableAttribute((byte)2)] string? managed);
+        public unsafe static void Free(byte* unmanaged);
-        public void FreeNative();
-        public unsafe void FromNativeValue(byte* value);
-        [NullableContextAttribute((byte)2)]
-        public string? ToManaged();
-        public unsafe byte* ToNativeValue();
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute((byte)2)] string? managed, Span<byte> buffer);
+            public unsafe byte* ToUnmanaged();
+        }
     }
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(CustomTypeMarshallerAttribute.GenericPlaceholder[]), CustomTypeMarshallerKind.LinearCollection, BufferSize=512, Features=CustomTypeMarshallerFeatures.CallerAllocatedBuffer | CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct ArrayMarshaller<T> {
-        public ArrayMarshaller(int sizeOfNativeElement);
-        public ArrayMarshaller([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? array, int sizeOfNativeElement);
-        public ArrayMarshaller([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? array, Span<byte> buffer, int sizeOfNativeElement);
-        public void FreeNative();
-        public unsafe void FromNativeValue(byte* value);
-        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
-        public Span<T> GetManagedValuesDestination(int length);
-        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
-        public ReadOnlySpan<T> GetManagedValuesSource();
-        public Span<byte> GetNativeValuesDestination();
-        public ReadOnlySpan<byte> GetNativeValuesSource(int length);
-        public ref byte GetPinnableReference();
-        [return: NullableAttribute(new byte[]{ (byte)2, (byte)1})]
-        public T[]? ToManaged();
-        public unsafe byte* ToNativeValue();
-    }
+    [CLSCompliantAttribute(false)]
+    [ContiguousCollectionMarshallerAttribute]
+    [CustomMarshallerAttribute(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.Default, typeof(ArrayMarshaller<,>))]
+    [CustomMarshallerAttribute(typeof(CustomMarshallerAttribute.GenericPlaceholder[]), MarshalMode.ManagedToUnmanagedIn, typeof(ArrayMarshaller<,>.ManagedToUnmanagedIn))]
+    public static class ArrayMarshaller<T, TUnmanagedElement> where TUnmanagedElement : struct {
+        [return: NullableAttribute(new byte[]{ (byte)2, (byte)1})]
+        public unsafe static T[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static TUnmanagedElement* AllocateContainerForUnmanagedElements([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? managed, out int numElements);
+        public unsafe static void Free(TUnmanagedElement* unmanaged);
+        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+        public static Span<T> GetManagedValuesDestination([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? managed);
+        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+        public static ReadOnlySpan<T> GetManagedValuesSource([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? managed);
+        public unsafe static Span<TUnmanagedElement> GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(TUnmanagedElement* unmanagedValue, int numElements);
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? array, Span<TUnmanagedElement> buffer);
+            [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+            public ReadOnlySpan<T> GetManagedValuesSource();
+            public ref TUnmanagedElement GetPinnableReference();
+            [NullableContextAttribute((byte)1)]
+            public static ref T GetPinnableReference([NullableAttribute(new byte[]{ (byte)2, (byte)1})] T[]? array);
+            public Span<TUnmanagedElement> GetUnmanagedValuesDestination();
+            public unsafe TUnmanagedElement* ToUnmanaged();
+        }
+    }
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(string), CustomTypeMarshallerKind.Value, BufferSize=256, Features=CustomTypeMarshallerFeatures.CallerAllocatedBuffer | CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct BStrStringMarshaller {
+    [CLSCompliantAttribute(false)]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.Default, typeof(BStrStringMarshaller))]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(BStrStringMarshaller.ManagedToUnmanagedIn))]
+    public static class BStrStringMarshaller {
-        [NullableContextAttribute((byte)2)]
-        public BStrStringMarshaller(string? str);
-        public BStrStringMarshaller([NullableAttribute((byte)2)] string? str, Span<ushort> buffer);
+        [return: NullableAttribute((byte)2)]
+        public unsafe static string? ConvertToManaged(ushort* unmanaged);
+        public unsafe static ushort* ConvertToUnmanaged([NullableAttribute((byte)2)] string? managed);
+        public unsafe static void Free(ushort* unmanaged);
-        public void FreeNative();
-        public unsafe void FromNativeValue(void* value);
-        [NullableContextAttribute((byte)2)]
-        public string? ToManaged();
-        public unsafe void* ToNativeValue();
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute((byte)2)] string? managed, Span<byte> buffer);
+            public unsafe ushort* ToUnmanaged();
+        }
     }
+    [AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Struct)]
+    public sealed class ContiguousCollectionMarshallerAttribute : Attribute {
+        public ContiguousCollectionMarshallerAttribute();
+    }
+    [AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple=true)]
+    [NullableAttribute((byte)0)]
+    [NullableContextAttribute((byte)1)]
+    public sealed class CustomMarshallerAttribute : Attribute {
+        public CustomMarshallerAttribute(Type managedType, MarshalMode marshalMode, Type marshallerType);
+        public Type ManagedType { get; }
+        public Type MarshallerType { get; }
+        public MarshalMode MarshalMode { get; }
+        [NullableContextAttribute((byte)0)]
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
+        public struct GenericPlaceholder
+    }
-    [AttributeUsageAttribute(AttributeTargets.Struct)]
-    [NullableAttribute((byte)0)]
-    [NullableContextAttribute((byte)1)]
-    public sealed class CustomTypeMarshallerAttribute : Attribute {
-        public CustomTypeMarshallerAttribute(Type managedType, CustomTypeMarshallerKind marshallerKind = CustomTypeMarshallerKind.Value);
-        public int BufferSize { get; set; }
-        public CustomTypeMarshallerDirection Direction { get; set; }
-        public CustomTypeMarshallerFeatures Features { get; set; }
-        public Type ManagedType { get; }
-        public CustomTypeMarshallerKind MarshallerKind { get; }
-        [NullableContextAttribute((byte)0)]
-        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-        public struct GenericPlaceholder
-    }
-    [FlagsAttribute]
-    public enum CustomTypeMarshallerDirection {
-        In = 1,
-        [EditorBrowsableAttribute(EditorBrowsableState.Never)]
-        None = 0,
-        Out = 2,
-        Ref = 3,
-    }
-    [FlagsAttribute]
-    public enum CustomTypeMarshallerFeatures {
-        CallerAllocatedBuffer = 2,
-        None = 0,
-        TwoStageMarshalling = 4,
-        UnmanagedResources = 1,
-    }
-    public enum CustomTypeMarshallerKind {
-        LinearCollection = 1,
-        Value = 0,
-    }
+    public enum MarshalMode {
+        Default = 0,
+        ElementIn = 7,
+        ElementOut = 9,
+        ElementRef = 8,
+        ManagedToUnmanagedIn = 1,
+        ManagedToUnmanagedOut = 3,
+        ManagedToUnmanagedRef = 2,
+        UnmanagedToManagedIn = 4,
+        UnmanagedToManagedOut = 6,
+        UnmanagedToManagedRef = 5,
+    }
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(CustomTypeMarshallerAttribute.GenericPlaceholder*[]), CustomTypeMarshallerKind.LinearCollection, BufferSize=512, Features=CustomTypeMarshallerFeatures.CallerAllocatedBuffer | CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct PointerArrayMarshaller<T> where T : struct {
-        public PointerArrayMarshaller(int sizeOfNativeElement);
-        public PointerArrayMarshaller([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? array, int sizeOfNativeElement);
-        public PointerArrayMarshaller([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? array, Span<byte> buffer, int sizeOfNativeElement);
-        public void FreeNative();
-        public unsafe void FromNativeValue(byte* value);
-        public Span<IntPtr> GetManagedValuesDestination(int length);
-        public ReadOnlySpan<IntPtr> GetManagedValuesSource();
-        public Span<byte> GetNativeValuesDestination();
-        public ReadOnlySpan<byte> GetNativeValuesSource(int length);
-        public ref byte GetPinnableReference();
-        [return: NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})]
-        public T*[]? ToManaged();
-        public unsafe byte* ToNativeValue();
-    }
+    [CLSCompliantAttribute(false)]
+    [ContiguousCollectionMarshallerAttribute]
+    [CustomMarshallerAttribute(typeof(CustomMarshallerAttribute.GenericPlaceholder*[]), MarshalMode.Default, typeof(PointerArrayMarshaller<,>))]
+    [CustomMarshallerAttribute(typeof(CustomMarshallerAttribute.GenericPlaceholder*[]), MarshalMode.ManagedToUnmanagedIn, typeof(PointerArrayMarshaller<,>.ManagedToUnmanagedIn))]
+    public static class PointerArrayMarshaller<T, TUnmanagedElement> where T : struct where TUnmanagedElement : struct {
+        [return: NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})]
+        public unsafe static T*[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static TUnmanagedElement* AllocateContainerForUnmanagedElements([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? managed, out int numElements);
+        public unsafe static void Free(TUnmanagedElement* unmanaged);
+        public static Span<IntPtr> GetManagedValuesDestination([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? managed);
+        public static ReadOnlySpan<IntPtr> GetManagedValuesSource([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? managed);
+        public unsafe static Span<TUnmanagedElement> GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(TUnmanagedElement* unmanagedValue, int numElements);
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? array, Span<TUnmanagedElement> buffer);
+            public ReadOnlySpan<IntPtr> GetManagedValuesSource();
+            public ref TUnmanagedElement GetPinnableReference();
+            public static ref byte GetPinnableReference([NullableAttribute(new byte[]{ (byte)2, (byte)0, (byte)0})] T*[]? array);
+            public Span<TUnmanagedElement> GetUnmanagedValuesDestination();
+            public unsafe TUnmanagedElement* ToUnmanaged();
+        }
+    }
+    [CLSCompliantAttribute(false)]
+    [ContiguousCollectionMarshallerAttribute]
+    [CustomMarshallerAttribute(typeof(ReadOnlySpan<>), MarshalMode.ManagedToUnmanagedIn, typeof(ReadOnlySpanMarshaller<,>.ManagedToUnmanagedIn))]
+    [CustomMarshallerAttribute(typeof(ReadOnlySpan<>), MarshalMode.UnmanagedToManagedOut, typeof(ReadOnlySpanMarshaller<,>.UnmanagedToManagedOut))]
+    public static class ReadOnlySpanMarshaller<T, TUnmanagedElement> where TUnmanagedElement : struct {
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute(new byte[]{ (byte)0, (byte)1})] ReadOnlySpan<T> managed, Span<TUnmanagedElement> buffer);
+            [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+            public ReadOnlySpan<T> GetManagedValuesSource();
+            public ref TUnmanagedElement GetPinnableReference();
+            [NullableContextAttribute((byte)1)]
+            public static ref T GetPinnableReference([NullableAttribute(new byte[]{ (byte)0, (byte)1})] ReadOnlySpan<T> managed);
+            public Span<TUnmanagedElement> GetUnmanagedValuesDestination();
+            public unsafe TUnmanagedElement* ToUnmanaged();
+        }
+        public static class UnmanagedToManagedOut {
+            public unsafe static TUnmanagedElement* AllocateContainerForUnmanagedElements([NullableAttribute(new byte[]{ (byte)0, (byte)1})] ReadOnlySpan<T> managed, out int numElements);
+            [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+            public static ReadOnlySpan<T> GetManagedValuesSource([NullableAttribute(new byte[]{ (byte)0, (byte)1})] ReadOnlySpan<T> managed);
+            public unsafe static Span<TUnmanagedElement> GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements);
+        }
+    }
+    [CLSCompliantAttribute(false)]
+    [ContiguousCollectionMarshallerAttribute]
+    [CustomMarshallerAttribute(typeof(Span<>), MarshalMode.Default, typeof(SpanMarshaller<,>))]
+    [CustomMarshallerAttribute(typeof(Span<>), MarshalMode.ManagedToUnmanagedIn, typeof(SpanMarshaller<,>.ManagedToUnmanagedIn))]
+    public static class SpanMarshaller<T, TUnmanagedElement> where TUnmanagedElement : struct {
+        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+        public unsafe static Span<T> AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static TUnmanagedElement* AllocateContainerForUnmanagedElements([NullableAttribute(new byte[]{ (byte)0, (byte)1})] Span<T> managed, out int numElements);
+        public unsafe static void Free(TUnmanagedElement* unmanaged);
+        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+        public static Span<T> GetManagedValuesDestination([NullableAttribute(new byte[]{ (byte)0, (byte)1})] Span<T> managed);
+        [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+        public static ReadOnlySpan<T> GetManagedValuesSource([NullableAttribute(new byte[]{ (byte)0, (byte)1})] Span<T> managed);
+        public unsafe static Span<TUnmanagedElement> GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements);
+        public unsafe static ReadOnlySpan<TUnmanagedElement> GetUnmanagedValuesSource(TUnmanagedElement* unmanaged, int numElements);
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute(new byte[]{ (byte)0, (byte)1})] Span<T> managed, Span<TUnmanagedElement> buffer);
+            [return: NullableAttribute(new byte[]{ (byte)0, (byte)1})]
+            public ReadOnlySpan<T> GetManagedValuesSource();
+            public ref TUnmanagedElement GetPinnableReference();
+            [NullableContextAttribute((byte)1)]
+            public static ref T GetPinnableReference([NullableAttribute(new byte[]{ (byte)0, (byte)1})] Span<T> managed);
+            public Span<TUnmanagedElement> GetUnmanagedValuesDestination();
+            public unsafe TUnmanagedElement* ToUnmanaged();
+        }
+    }
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(string), CustomTypeMarshallerKind.Value, Features=CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct Utf16StringMarshaller {
+    [CLSCompliantAttribute(false)]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.Default, typeof(Utf16StringMarshaller))]
+    public static class Utf16StringMarshaller {
-        [NullableContextAttribute((byte)2)]
-        public Utf16StringMarshaller(string? str);
+        [return: NullableAttribute((byte)2)]
+        public unsafe static string? ConvertToManaged(ushort* unmanaged);
+        public unsafe static ushort* ConvertToUnmanaged([NullableAttribute((byte)2)] string? managed);
+        public unsafe static void Free(ushort* unmanaged);
-        public void FreeNative();
-        public unsafe void FromNativeValue(void* value);
+        [NullableContextAttribute((byte)2)]
+        public static ref readonly char GetPinnableReference(string? str);
-        [NullableContextAttribute((byte)2)]
-        public string? ToManaged();
-        public unsafe void* ToNativeValue();
     }
-    [CLSCompliantAttribute(false)]
-    [CustomTypeMarshallerAttribute(typeof(string), CustomTypeMarshallerKind.Value, BufferSize=256, Features=CustomTypeMarshallerFeatures.CallerAllocatedBuffer | CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)]
-    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
-    public ref struct Utf8StringMarshaller {
+    [CLSCompliantAttribute(false)]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.Default, typeof(Utf8StringMarshaller))]
+    [CustomMarshallerAttribute(typeof(string), MarshalMode.ManagedToUnmanagedIn, typeof(Utf8StringMarshaller.ManagedToUnmanagedIn))]
+    public static class Utf8StringMarshaller {
-        [NullableContextAttribute((byte)2)]
-        public Utf8StringMarshaller(string? str);
-        public Utf8StringMarshaller([NullableAttribute((byte)2)] string? str, Span<byte> buffer);
+        [return: NullableAttribute((byte)2)]
+        public unsafe static string? ConvertToManaged(byte* unmanaged);
+        public unsafe static byte* ConvertToUnmanaged([NullableAttribute((byte)2)] string? managed);
+        public unsafe static void Free(byte* unmanaged);
-        public void FreeNative();
-        public unsafe void FromNativeValue(byte* value);
-        [NullableContextAttribute((byte)2)]
-        public string? ToManaged();
-        public unsafe byte* ToNativeValue();
+        [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, Size=1)]
+        public ref struct ManagedToUnmanagedIn {
+            public static int BufferSize { get; }
+            public void Free();
+            public void FromManaged([NullableAttribute((byte)2)] string? managed, Span<byte> buffer);
+            public unsafe byte* ToUnmanaged();
+        }
     }
 }
```