Created
February 2, 2016 09:40
-
-
Save bblanchon/85ce09dccf8e31395a05 to your computer and use it in GitHub Desktop.
How to use quasardb in a C# program with the BinaryFormatter
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
using Quasardb; | |
using System.Runtime.Serialization.Formatters.Binary; | |
using System.IO; | |
using System; | |
namespace QuasardbDemoWithBinaryFormatter | |
{ | |
class Program | |
{ | |
[Serializable] | |
class MoveInfo | |
{ | |
public string Name { get; set; } | |
public int Year { get; set; } | |
}; | |
class Serializer | |
{ | |
public Serializer() | |
{ | |
_binaryFormatter = new BinaryFormatter(); | |
} | |
public byte[] Serialize<T>(T data) | |
{ | |
var memoryStream = new MemoryStream(); | |
_binaryFormatter.Serialize(memoryStream, data); | |
return memoryStream.ToArray(); | |
} | |
public T Deserialize<T>(byte[] data) | |
{ | |
var memoryStream = new MemoryStream(data); | |
return (T)_binaryFormatter.Deserialize(memoryStream); | |
} | |
private BinaryFormatter _binaryFormatter; | |
} | |
static void Main(string[] args) | |
{ | |
var serializer = new Serializer(); | |
var qdb = new QdbCluster("qdb://127.0.0.1:2836"); | |
qdb.Blob("movie001").Put( | |
serializer.Serialize(new MoveInfo | |
{ | |
Name = "Life Of Brian", | |
Year = 1980 | |
})); | |
var movie = serializer.Deserialize<MoveInfo>( | |
qdb.Blob("movie001").GetAndRemove()); | |
Console.WriteLine("Name = {0}", movie.Name); | |
Console.WriteLine("Yeay = {0}", movie.Year); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment