Created
December 27, 2015 00:57
-
-
Save allisterb/53ce0c0bd73c99ffdeec to your computer and use it in GitHub Desktop.
ISerializer implementation of a BSON serializer for BPlusTree
This file contains 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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using CSharpTest.Net.Serialization; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Bson; | |
namespace Gist | |
{ | |
public class BsonSerializer<T> : ISerializer<T> | |
{ | |
JsonSerializer s = new JsonSerializer(); | |
public T ReadFrom(Stream stream) | |
{ | |
using (BsonReader reader = new BsonReader(stream)) | |
{ | |
reader.CloseInput = false; | |
return s.Deserialize<T>(reader); | |
} | |
} | |
public void WriteTo(T value, Stream stream) | |
{ | |
using (BsonWriter writer = new BsonWriter(stream)) | |
{ | |
writer.CloseOutput = false; | |
s.Serialize(writer, value); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment