Created
September 18, 2016 04:06
-
-
Save manofstick/7821be3655f9df22cbe1d7c2d4381ad0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.IO | |
open System.Runtime.Serialization.Formatters.Binary | |
let filename = @"E:\binary"; | |
let data = [ | |
"This", 1 | |
"is", 2 | |
"just", 3 | |
"some", 4 | |
"data", 5 | |
"to", 6 | |
"serialize", 7 | |
] |> Map.ofList | |
let serialize () = | |
use stream = File.Create filename | |
let formatter = new BinaryFormatter () | |
Console.WriteLine "Serializing vector" | |
formatter.Serialize (stream, data) | |
let deserialize () = | |
use stream = File.OpenRead filename | |
let formatter = new BinaryFormatter () | |
Console.WriteLine "Deserializing vector" | |
match formatter.Deserialize stream with | |
| :? Map<string, int> as deserialized -> | |
if deserialized = data then | |
Console.WriteLine "deserialize good" | |
else | |
Console.WriteLine "deserialize bad" | |
| _ -> Console.WriteLine "deserialize very bad" | |
[<EntryPoint>] | |
let main argv = | |
//serialize () | |
deserialize () | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment