├── .gitignore
├── .vscode
├── launch.json
└── tasks.json
├── CODE_OF_CONDUCT.md
├── LICENSE
├── Microsoft.FrozenObjects.sln
├── README.md
├── SECURITY.md
├── nuget.config
├── samples
└── Basic
│ ├── FrozenObjectTest.csproj
│ ├── FrozenObjectTest.sln
│ ├── Program.cs
│ └── nuget.config
├── src
├── Deserializer.cs
├── Microsoft.FrozenObjects.csproj
├── Microsoft.FrozenObjects.nuspec
├── NativeMethods.cs
└── Serializer.cs
├── tests
├── ComplexTypes.cs
├── Microsoft.FrozenObjects.Tests.csproj
├── SupportCode
│ ├── DictionarySlim.cs
│ ├── HashHelpers.cs
│ ├── Marvin.OrdinalIgnoreCase.cs
│ ├── Marvin.cs
│ ├── ReadOnlyDictionarySlim.cs
│ └── Utf16Utility.cs
└── UnitTests.cs
└── tools
├── Library.cs
└── Microsoft.FrozenObjects.BuildTools.csproj
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
332 | Serializer/native/Microsoft.FrozenObjects.Serializer.Native.so
333 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/Tests/bin/Debug/netcoreapp3.0/Microsoft.FrozenObjects.Tests.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/Tests",
16 | // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
17 | "console": "internalConsole",
18 | "stopAtEntry": false
19 | },
20 | {
21 | "name": ".NET Core Attach",
22 | "type": "coreclr",
23 | "request": "attach",
24 | "processId": "${command:pickProcess}"
25 | }
26 | ]
27 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/Tests/Microsoft.FrozenObjects.Tests.csproj"
11 | ],
12 | "problemMatcher": "$tsc"
13 | },
14 | {
15 | "label": "publish",
16 | "command": "dotnet",
17 | "type": "process",
18 | "args": [
19 | "publish",
20 | "${workspaceFolder}/Tests/Microsoft.FrozenObjects.Tests.csproj"
21 | ],
22 | "problemMatcher": "$tsc"
23 | },
24 | {
25 | "label": "watch",
26 | "command": "dotnet",
27 | "type": "process",
28 | "args": [
29 | "watch",
30 | "run",
31 | "${workspaceFolder}/Tests/Microsoft.FrozenObjects.Tests.csproj"
32 | ],
33 | "problemMatcher": "$tsc"
34 | }
35 | ]
36 | }
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/Microsoft.FrozenObjects.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29025.244
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FrozenObjects", "src\Microsoft.FrozenObjects.csproj", "{26376C2E-D488-4D04-8332-B0CFC806B56B}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {09DE73E9-2A44-43FD-B869-1EFFE311E8BB} = {09DE73E9-2A44-43FD-B869-1EFFE311E8BB}
9 | EndProjectSection
10 | EndProject
11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FrozenObjects.BuildTools", "tools\Microsoft.FrozenObjects.BuildTools.csproj", "{09DE73E9-2A44-43FD-B869-1EFFE311E8BB}"
12 | EndProject
13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FrozenObjects.Tests", "tests\Microsoft.FrozenObjects.Tests.csproj", "{5C2D82E1-E77C-4938-9B9F-807E33666E34}"
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Release|Any CPU = Release|Any CPU
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {26376C2E-D488-4D04-8332-B0CFC806B56B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {26376C2E-D488-4D04-8332-B0CFC806B56B}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {26376C2E-D488-4D04-8332-B0CFC806B56B}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {26376C2E-D488-4D04-8332-B0CFC806B56B}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {09DE73E9-2A44-43FD-B869-1EFFE311E8BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {09DE73E9-2A44-43FD-B869-1EFFE311E8BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {09DE73E9-2A44-43FD-B869-1EFFE311E8BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {09DE73E9-2A44-43FD-B869-1EFFE311E8BB}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {5C2D82E1-E77C-4938-9B9F-807E33666E34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30 | {5C2D82E1-E77C-4938-9B9F-807E33666E34}.Debug|Any CPU.Build.0 = Debug|Any CPU
31 | {5C2D82E1-E77C-4938-9B9F-807E33666E34}.Release|Any CPU.ActiveCfg = Release|Any CPU
32 | {5C2D82E1-E77C-4938-9B9F-807E33666E34}.Release|Any CPU.Build.0 = Release|Any CPU
33 | EndGlobalSection
34 | GlobalSection(SolutionProperties) = preSolution
35 | HideSolutionNode = FALSE
36 | EndGlobalSection
37 | GlobalSection(ExtensibilityGlobals) = postSolution
38 | SolutionGuid = {C2C32CB7-4450-4293-B5F0-888F94FB999D}
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Frozen Objects
2 |
3 | [](https://dev.azure.com/ms/FrozenObjects/_build/latest?definitionId=175)
4 |
5 | Serialize an object graph to frozen objects
6 |
7 | # Contributing
8 |
9 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
10 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
11 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
12 |
13 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
14 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
15 | provided by the bot. You will only need to do this once across all repos using our CLA.
16 |
17 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
18 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
19 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
40 |
41 |
42 |
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/Basic/FrozenObjectTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp3.1
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/samples/Basic/FrozenObjectTest.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29102.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrozenObjectTest", "FrozenObjectTest.csproj", "{68D11345-A9A2-452B-86D2-9B5D89541677}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {68D11345-A9A2-452B-86D2-9B5D89541677}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {68D11345-A9A2-452B-86D2-9B5D89541677}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {68D11345-A9A2-452B-86D2-9B5D89541677}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {68D11345-A9A2-452B-86D2-9B5D89541677}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {CF58AF40-D83F-4A53-BE85-61217BEA6178}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/samples/Basic/Program.cs:
--------------------------------------------------------------------------------
1 | namespace FrozenObjectTest
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Reflection;
7 | using static Microsoft.FrozenObjects.Serializer;
8 |
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | const string dll = "foo.dll";
14 | const string bin = "foo.bin";
15 | const string @namespace = "MyNamespace";
16 | const string type = "MyType";
17 | const string method = "DeserializeMethodName";
18 |
19 | const string obj1 = "Hello World";
20 | SerializeObject(obj1, bin, dll, @namespace, type, method, new Version(1, 0, 0, 0));
21 |
22 | var obj2 = Assembly.Load(File.ReadAllBytes(dll)).GetTypes().Single(t => t.FullName == $"{@namespace}.{type}").GetMethod(method).Invoke(null, new object[] { bin });
23 |
24 | if (Equals(obj1, obj2))
25 | {
26 | Console.WriteLine("Hooray");
27 | }
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/samples/Basic/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/Deserializer.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) Microsoft Corporation. All rights reserved.
2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 |
4 | namespace Microsoft.FrozenObjects
5 | {
6 | using System;
7 | using System.IO;
8 | using System.Runtime.CompilerServices;
9 | using System.Runtime.InteropServices;
10 | using static NativeMethods;
11 |
12 | public static unsafe class Deserializer
13 | {
14 | public static object Deserialize(RuntimeTypeHandle[] runtimeTypeHandles, string blobPath)
15 | {
16 | var extraSpace = IntPtr.Size + IntPtr.Size; // 1 extra IntPtr for segmentHandle and the other for size of the allocation (needed on Linux)
17 | var length = 0L;
18 | byte* buffer;
19 |
20 | using (var fs = new FileStream(blobPath, FileMode.Open, FileAccess.Read))
21 | {
22 | length = fs.Length;
23 | var chunkSize = Math.Min(64 * 1024, (int)length); // 64KB is a reasonable size
24 |
25 | buffer = AllocateMemory(length + extraSpace) + extraSpace; // so that buffer points to the real start of the frozen segment.
26 |
27 | var span = new Span(buffer, chunkSize);
28 | var read = 0L;
29 | int chunk;
30 |
31 | while ((chunk = fs.Read(span)) > 0)
32 | {
33 | read += chunk;
34 |
35 | if (read == length)
36 | {
37 | break;
38 | }
39 |
40 | span = new Span(buffer + read, Math.Min(chunkSize, (int)(length - read)));
41 | }
42 | }
43 |
44 | var retVal = DeserializeInner(runtimeTypeHandles, buffer, length);
45 |
46 | // -InPtr.Size - IntPtr.Size is for size (we need it in Linux)
47 | Marshal.WriteIntPtr((IntPtr)buffer, 0 - IntPtr.Size - IntPtr.Size, (IntPtr)(length + extraSpace));
48 |
49 | // -IntPtr.Size is for segment handle
50 | Marshal.WriteIntPtr((IntPtr)buffer, 0 - IntPtr.Size, InternalHelpers.RegisterFrozenSegment((IntPtr)buffer, (IntPtr)length));
51 |
52 | return retVal;
53 | }
54 |
55 | public static void UnloadFrozenObject(object o)
56 | {
57 | var optr = Marshal.ReadIntPtr((IntPtr)Unsafe.AsPointer(ref o));
58 | var baseAddress = optr - IntPtr.Size - IntPtr.Size - IntPtr.Size; // 3 because optr is actually pointing to MT*
59 | var length = Marshal.ReadIntPtr(baseAddress);
60 | var segmentHandle = Marshal.ReadIntPtr(baseAddress, IntPtr.Size);
61 |
62 | InternalHelpers.UnregisterFrozenSegment(segmentHandle);
63 | FreeMemory(baseAddress, length);
64 | }
65 |
66 | [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
67 | private static object DeserializeInner(RuntimeTypeHandle[] runtimeTypeHandles, byte* buffer, long length)
68 | {
69 | byte* objectId = buffer + IntPtr.Size;
70 |
71 | while (objectId < buffer + length)
72 | {
73 | IntPtr typeHandle = IntPtr.Size == 8 ? runtimeTypeHandles[(int)*(long*)objectId].Value : runtimeTypeHandles[*(int*)objectId].Value;
74 | bool isArray = ((long)typeHandle & 0x2) == 0x2;
75 |
76 | var mt = (MethodTable*)typeHandle;
77 | if (isArray)
78 | {
79 | mt = IntPtr.Size == 8 ? (MethodTable*)*(long*)(typeHandle + 6) : (MethodTable*)*(int*)(typeHandle + 6); // TODO: Is this correct for 32-bit?
80 | }
81 |
82 | long objectSize = mt->BaseSize;
83 | var flags = mt->Flags;
84 | bool hasComponentSize = (flags & 0x80000000) == 0x80000000;
85 |
86 | if (hasComponentSize)
87 | {
88 | var numComponents = (long)*(int*)(objectId + IntPtr.Size);
89 | objectSize += numComponents * mt->ComponentSize;
90 | }
91 |
92 | bool containsPointerOrCollectible = (flags & 0x10000000) == 0x10000000 || (flags & 0x1000000) == 0x1000000;
93 | if (containsPointerOrCollectible)
94 | {
95 | var entries = *(int*)((byte*)mt - IntPtr.Size);
96 | if (entries < 0)
97 | {
98 | entries -= entries;
99 | }
100 |
101 | var slots = 1 + entries * 2;
102 |
103 | var gcdesc = new GCDesc(buffer, (byte*)mt - (slots * IntPtr.Size), slots * IntPtr.Size);
104 |
105 | if (IntPtr.Size == 8)
106 | {
107 | gcdesc.FixupObject64(objectId, objectSize);
108 | }
109 | else
110 | {
111 | gcdesc.FixupObject32(objectId, objectSize);
112 | }
113 | }
114 |
115 | if (IntPtr.Size == 8)
116 | {
117 | *(long*)objectId = (long)mt;
118 | }
119 | else
120 | {
121 | *(int*)objectId = (int)mt;
122 | }
123 |
124 | objectId += objectSize + Padding(objectSize, IntPtr.Size);
125 | }
126 |
127 | var tmp = buffer + IntPtr.Size;
128 | return Unsafe.Read