Skip to content

Instantly share code, notes, and snippets.

@allisterb
Created December 27, 2015 00:57
Show Gist options
  • Save allisterb/53ce0c0bd73c99ffdeec to your computer and use it in GitHub Desktop.
Save allisterb/53ce0c0bd73c99ffdeec to your computer and use it in GitHub Desktop.
ISerializer implementation of a BSON serializer for BPlusTree
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