https://github.com/adoconnection/binarystore
NET binary serializer for flat objects of fixed length, optimized for random reads and writes
https://github.com/adoconnection/binarystore
Last synced: 10 months ago
JSON representation
NET binary serializer for flat objects of fixed length, optimized for random reads and writes
- Host: GitHub
- URL: https://github.com/adoconnection/binarystore
- Owner: adoconnection
- License: mit
- Created: 2024-04-22T06:59:20.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-12T21:44:29.000Z (about 2 years ago)
- Last Synced: 2025-03-17T13:19:38.297Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# 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
```cs
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
```cs
BinaryStore binaryStore = new BinaryStore(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:
```cs
Console.WriteLine("Records in store: " + binaryStore.GetRecordsCount());
for (int i = 0; i < binaryStore.GetRecordsCount(); i++)
{
Console.WriteLine(i + " - " + binaryStore.Read(i));
}
```
## External Lock
```cs
private static object LockObject = new object();
//...
BinaryStore binaryStore = new BinaryStore(stream, LockObject);
```
## Options
```cs
BinaryStore binaryStore = new BinaryStore(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
});
```