Git Product home page Git Product logo

binarystore's Introduction

BinaryStore

NET binary serializer optimized for random reads/writes.
Database replacement for telemetry/sensor data or logs.

  • Best works for lists of fixed length objects
  • Instant reads and writes for any position in list
  • Individual records corruption does not affect others
  • 5-10x faster writes vs NewtonsoftJson
  • 2-5x faster reads vs NewtonsoftJson

NuGet

coming soon

How come?

Target object must be of fixed binary length (like we know int is 4 bytes) Given fixed length, we can Seek stream position to read/write any record index. Serialization is as fast as converting value to byte array and back.

Examples

public record Person
{
    public int Id { get; set; } // 4 bytes
    public DateTime Birthday { get; set; } // 8 bytes

    [BinaryStoreRecordLength(30)] // limit attribute for strings, arrays atc
    public string FirstName { get; set; }

    [BinaryStoreRecordLength(30)]
    public string LastName { get; set; }
}

Create store and append records

BinaryStore<Person> binaryStore = new BinaryStore<Person>(stream);

binaryStore.Append(new Person()
{
    Id = 1,
    FirstName = "FirstName 1",
    LastName = "LastName 1",
    Birthday = new DateTime(2001, 1, 1)
});

binaryStore.Append(new Person()
{
    Id = 2,
    FirstName = "FirstName 2",
    LastName = "LastName 2",
    Birthday = new DateTime(2002, 2, 2)
});

Read store contents:

Console.WriteLine("Records in store: " + binaryStore.GetRecordsCount());

for (int i = 0; i < binaryStore.GetRecordsCount(); i++)
{
    Console.WriteLine(i + " - " + binaryStore.Read(i));
}

External Lock

private static object LockObject = new object();

//...

BinaryStore<Person> binaryStore = new BinaryStore<Person>(stream, LockObject);

Options

BinaryStore<Person> binaryStore = new BinaryStore<Person>(stream, builder =>
{
    builder.BinaryAttributePropertiesOnly = true; // serialize only properties with [BinaryStoreRecord] attribute
    builder.SeekToBeginningAtStartup = true; // goto stream 0 at stratup 
    builder.Serializers.Add(new BinaryStoreByteArraySerializer()); // add your own type serializers
});

binarystore's People

Contributors

adoconnection avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.