Git Product home page Git Product logo

grobuf's Introduction

GroBuf

NuGet Status Build status

GroBuf is a fast binary serializer for .NET.

Example

Imagine a simple class hierarchy:

public class Car
{
    public Guid? Id { get; set; }
    public string Manufacturer { get; set; }
    public CarKind Kind { get; set; }
    public Wheel[] Wheels { get; set; }
}
public class Wheel
{
    public double Radius { get; set; }
    public double Width { get; set; }
    public double Weight { get; set; }
}
public enum CarKind : byte
{
    Sedan,
    Hatchback,
    Limousine,
    Van
}

Creating a serializer

In order to obtain maximum speed it is strongly recommended to use a single instance of the serializer as it dynamicly generates code for serialization/deserialization methods. Instances of the serializer are considered to be thread-safe.

var serializer = new Serializer(new PropertiesExtractor(), options : GroBufOptions.WriteEmptyObjects);

Here we create serializer in order to read/write all public properties. By default GroBuf skips objects which are empty (an object is considered empty if it is an array with zero length or if all its members are empty). The GroBufOptions.WriteEmptyObjects options says GroBuf to write all data as is.

Serializing/Deserializing

GroBuf serializes objects to binary format and returns byte[], deserializes from byte[]:

var car = new Car
              {
                  Id = Guid.NewGuid(),
                  Manufacturer = "zzz",
                  Kind = CarKind.Limousine,
                  Wheels = new[] { new Wheel {Radius = 19.1, Width = 5.2, Weight = 16.9} }
              };
byte[] data = serializer.Serialize(car);
var zcar = serializer.Deserialize<Car>(data);

Selecting members to serialize

It is possible to create a serializer with custom data members selection. These are predefined extractors:

  • PropertiesExtractor - selects all public properties
  • FieldsExtractor - selects all public fields
  • AllPropertiesExtractor - selects both public and private properties
  • AllFieldsExtractor - selects both public and private fields
  • DataMembersByAttributeExtractor - selects all members marked with DataMember attribute

Notes on types

Supports:

  • custom classes or structs
  • primitive types
  • single dimension arrays
  • List<>, HashSet<>, Hashtable, Dictionary<,>
  • Lazy<> (it will not be deserialized untill Value is actually demanded)

Serialized types names are not used and therefore the types can be safely renamed without any loss of data.

All primitive types are convertible into ecch other. For example, if a data contract member had type int and has been changed to long than no old data will be lost.

Notes on members

The members's names are important for GroBuf because it stores hash codes of all serialized members and uses them during deserialization. But it is possible to tell GroBuf what hash code is to be used for a particular member using GroboMember attribute. If a member's name changes (and there is no GroboMember attribute at it) or a member has been deleted, old data still may be deserialized but the data of that particular member will be skipped and lost. If a member has been added than after deserializing old data, the value of this member will be set to its default value.

Notes on enums

Enums are stored not as ints but as hash codes for their string representation. Thus, one can safely change the value of enum, but change fo a name will result in loss of data (soon it will be possibile to specify the hash code of a enum member manually).

Performance

GroBuf is faster than a well-known serializer ProtoBuf:

  • about 2-2.5 times on average on serialization
  • about 4-5 times on average on deserialization

Here you can see an example of benchmarking in a realistic scenario:

BenchmarkDotNet-Dev=v0.9.6.0+
OS=Microsoft Windows NT 6.1.7601 Service Pack 1
Processor=Intel(R) Core(TM) i7-2600K CPU 3.40GHz, ProcessorCount=8
Frequency=3312861 ticks, Resolution=301.8539 ns, Timer=TSC
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
JitModules=clrjit-v4.6.1076.0

Type=ProtoBufvsGroBufRunner  Mode=Throughput  

              Method | Platform |       Jit | Runtime |      Median |    StdDev |
-------------------- |--------- |---------- |-------- |------------ |---------- |
     GroBufSerialize |     Host |      Host |    Mono |  79.0364 us | 0.6419 us |
   GroBufDeserialize |     Host |      Host |    Mono |  17.6128 us | 0.1588 us |
   ProtoBufSerialize |     Host |      Host |    Mono | 184.1507 us | 1.7764 us |
 ProtoBufDeserialize |     Host |      Host |    Mono |  72.3540 us | 2.2473 us |
     GroBufSerialize |      X64 | LegacyJit |    Host |  52.2340 us | 2.1481 us |
   GroBufDeserialize |      X64 | LegacyJit |    Host |   8.9056 us | 0.5137 us |
   ProtoBufSerialize |      X64 | LegacyJit |    Host | 136.6818 us | 5.9596 us |
 ProtoBufDeserialize |      X64 | LegacyJit |    Host |  38.0563 us | 1.5057 us |
     GroBufSerialize |      X64 |    RyuJit |    Host |  49.3948 us | 1.5682 us |
   GroBufDeserialize |      X64 |    RyuJit |    Host |   9.4304 us | 0.3034 us |
   ProtoBufSerialize |      X64 |    RyuJit |    Host | 136.9129 us | 5.1180 us |
 ProtoBufDeserialize |      X64 |    RyuJit |    Host |  37.7057 us | 0.5454 us |
     GroBufSerialize |      X86 | LegacyJit |    Host |  60.7610 us | 0.5057 us |
   GroBufDeserialize |      X86 | LegacyJit |    Host |  12.2245 us | 0.1467 us |
   ProtoBufSerialize |      X86 | LegacyJit |    Host | 156.2833 us | 3.5322 us |
 ProtoBufDeserialize |      X86 | LegacyJit |    Host |  41.5833 us | 0.5682 us |

The disadvantages are:

  • because of simpler format the size of data produced by GroBuf is 1.5-2 times larger than ProtoBuf's. But it is planned to be optimized in the future
  • lack of ProtoBuf's extensions

Release Notes

See CHANGELOG.

grobuf's People

Contributors

aldobrynin avatar andrewkostousov avatar anton92nd avatar beevee avatar dgorlov avatar fakefeik avatar fedorfo avatar homuroll avatar mpivko avatar skyterx avatar sonicgd avatar tihonove avatar troublenadiagirl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grobuf's Issues

Issue with serialize/deserialize Hashtable which has Value the same as Key

The GroBuf misses values if the value is the same as a key. So if key == "testval" and value == "testval", so after serialization/deserialization your hashtable["testval"] will be null.

Steps to reproduce (just pseudo-code):

  1. Create simple Hashtable ht = new Hashtable();
  2. hashtable.Add("testval", "testval")
    3, serializer.Serialize(hashtable) and then serializer.Deserialize(byte[]....)
  3. check that deserialized hashtable["testval"] == null

Inheritance?

Hi,

Does GroBuf supports inheritance ?

    public class DataToSerialize
    {
        public Animal[] Animals { get; set; }
    }

    public abstract class Animal
    {
        public string Id { get; set; }
    }

    public class Dog : Animal
    {
        public string Name { get; set; }
    }

How to improve the first serialization

GroBuf is a quite nice serialization tool which is much faster than protobuf. In my test case, one serialization takes only around 20us. But for every types(primitive type and custom type), the first time run takes about 100ms. I found it is caused by BuildWriter which is dynamically create method in the first time.

Is it possible to speed up that part? For eg, maybe we could create methods for known type in build time and so can reduce 100ms in runtime?

Hash Collision Issue When Serializing a DataSet

I am receiving the following error when I either try to directory serialize a DataSet or attempt to serialize an object which contains a DataSet.

Hash code collision: members 'MarshalByValueComponent.Site' and 'DataSet.Site' have the same hash code = 11520371743981427527

Here are relevant portions of the StackTrace.

   at GroBuf.GroBufHelpers.CalcHashesAndCheck(IEnumerable`1 dataMembers)
   at GroBuf.Writers.ClassWriterBuilder.WriteNotEmpty(WriterMethodBuilderContext context)
   at GroBuf.Writers.WriterBuilderBase.BuildWriter(WriterTypeBuilderContext writerTypeBuilderContext)
   at GroBuf.Writers.WriterTypeBuilderContext.GetWriter(Type type, Boolean isRoot, Boolean ignoreCustomSerialization)
   at GroBuf.Writers.WriterMethodBuilderContext.CallWriter(GroboIL il, Type type)
   at GroBuf.Writers.WriterMethodBuilderContext.CallWriter(Type type)
   at GroBuf.Writers.ClassWriterBuilder.WriteNotEmpty(WriterMethodBuilderContext context)
   at GroBuf.Writers.WriterBuilderBase.BuildWriter(WriterTypeBuilderContext writerTypeBuilderContext)
   at GroBuf.Writers.WriterTypeBuilderContext.GetWriter(Type type, Boolean isRoot, Boolean ignoreCustomSerialization)
   at GroBuf.Writers.WriterTypeBuilder.BuildWriter(Type type, Boolean ignoreCustomSerialization)
   at GroBuf.GroBufWriter.GetWriter(Type type, Boolean ignoreCustomSerialization)
   at GroBuf.GroBufWriter.BuildWriter[T](Boolean ignoreCustomSerialization)
   at GroBuf.GroBufWriter.GetWriterAndSizeCounter[T](Boolean ignoreCustomSerialization)
   at GroBuf.GroBufWriter.Write[T](Boolean ignoreCustomSerialization, T obj)
   at GroBuf.GroBufWriter.Write[T](T obj)
   at GroBuf.Serializer.Serialize[T](T obj)
   at xxxx.yyyy.zzz(List`1 aaaa) in <<some file>>.cs:line 74

_exceptionMethod = {UInt64[] CalcHashesAndCheck(System.Collections.Generic.IEnumerable1[GroBuf.DataMembersExtracters.IDataMember])}
`
I am not sure why a dataset would be causing problems. It probably makes no difference but these datasets were populated from .csv, .xls and .xlsx files. All of them are failing. The hash collision occurs on every attempt to serialize a DataSet.

Incompatibility with latest mono (and CoreFx)

Hi,
I came across an issue when serializing "Dictionary" class with GroBuf in Mono (which seems to actually use Dictionary.cs from CoreFx). As fasr as I could tell, some private fields underwent minor name changes e.g. "count" became "_count", "entries" became "_entries" etc... in Dictionary.cs

This basically renders GroBuf unable to serialize Dictionaries for latest mono.
I'm using mono 5.14.0.177, with .net 4.5 in my project.
Thanks,
Emil

Bug with null serialization/deserialization

I have a variable of reference type with value of null.
I serialize it and get byte[] {0}, then deserialize and get not null value.
Example:

class Serialization_Test
{
    class MyClass
    {
        public int Value { get; set; }
    }

    [Test]
    public void Test()
    {
        var serializer = new Serializer(new PropertiesExtractor());
        var bytes = serializer.Serialize<MyClass>(null);
        var myClass = serializer.Deserialize<MyClass>(bytes);
        Assert.IsNull(myClass);
    }
}

fails with

Expected: null
  But was:  <Serialization_Test+MyClass>

DataCorruptedException when deserializing object with DateTimeOffset property to base class.

Code that throws the exception:

[DataContract]
class B : A
{
	[DataMember]
	public DateTimeOffset DateTimeOffset { get; set; }
}

[DataContract]
class A
{
	[DataMember]
	public Guid Guid { get; set; }
}

var b = new B {DateTimeOffset = DateTimeOffset.Now, Guid = Guid.Empty};
var bs = serializer.Serialize(b);
var ad = serializer.Deserialize<A>(bs);

GroBuf's part of StackTrace:

in Read_A_bea5fb9a-e5a8-458d-b989-07e1f3f6a910(IntPtr , Int32& , A& , ReaderContext )
in GroBuf.GroBufReader.Read[T](IntPtr data, Int32& index, Int32 length, T& result) 
in c:\BuildAgent\work\4b2afcefcf307fed\GroBuf\GroBuf\GroBufReader.cs:строка 99
in GroBuf.GroBufReader.Read[T](Byte[] data, T& result) 
in c:\BuildAgent\work\4b2afcefcf307fed\GroBuf\GroBuf\GroBufReader.cs:строка 46
in GroBuf.GroBufReader.Read[T](Byte[] data) 
in c:\BuildAgent\work\4b2afcefcf307fed\GroBuf\GroBuf\GroBufReader.cs:строка 76

Exception - GroBuf.DataCorruptedException {"Unknown type code: 142"} .

ValueTuple is not supported as dictionary key when using AllPropertiesExtractor

The following code:

var serializer = new Serializer(new AllPropertiesExtractor());
var dict = new Dictionary<(string, string), string>
    {
        {("k11", "k12"), "v1"},
        {("k21", "k22"), "v2"}
    };
var bytes = serializer.Serialize(dict);
serializer.Deserialize<Dictionary<(string, string), string>>(bytes);

fails with:

System.ArgumentException : An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Read_Dictionary`2_7baa8df0-d792-4e03-bc5a-1291b06478b5(IntPtr , Int32& , Dictionary`2& , ReaderContext )
   at 7884d4f6-1cd8-4766-9648-ca5616cb25c2(IntPtr , Int32& , Dictionary`2& , ReaderContext )
   at GroBuf.GroBufReader.Read[T](IntPtr data, Int32& index, Int32 length, T& result) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 98
   at GroBuf.GroBufReader.Read[T](Byte[] data, T& result) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 45
   at GroBuf.GroBufReader.Read[T](Byte[] data) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\GroBufReader.cs:line 75
   at GroBuf.Serializer.Deserialize[T](Byte[] data) in C:\projects\open-source\skbkontur\GroBuf\GroBuf\Serializer.cs:line 50

serializer = new Serializer(new AllFieldsExtractor()) works as expected though.

Object serialization does not respect runtime types

GroBuf only respect primitive types, object[] and Hashtable when serializing a property of the object type, but does not respect, for example, Dictionary<TKey, TValue>.

[Test]
public void TestDictionaryInObject()
{
    var a = new A {S = "zzz", Dict = new Dictionary<string, string> {["key"] = "value"}};
    var data = serializer.Serialize(a);

    var deserializedA = serializer.Deserialize<A>(data);
    Assert.AreEqual("zzz", deserializedA.S);
    Assert.NotNull(deserializedA.Dict);
    Assert.That(deserializedA.Dict, Is.TypeOf<Dictionary<string, string>>());
    Assert.AreEqual("value", ((Dictionary<string, string>)deserializedA.Dict)["key"]);
}

public class A
{
    public object S { get; set; }
    public object Dict { get; set; }
}

This test fails on Assert.NotNull operation.

Exception trying to serialize LinearGradientBrush

When I try to serialize a LinearGradientBrush the GroBuf throw an exception: "nable to cast object of type 'System.Windows.Media.LinearGradientBrush' to type 'MS.Utility.FrugalObjectList`1[System.Windows.Freezable+FreezableContextPair]'."
I am using this code:

Serializer _serializer = new Serializer(new AllPropertiesExtractor(), options: GroBufOptions.WriteEmptyObjects);
LinearGradientBrush linGrBrush = new LinearGradientBrush();
linGrBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.5));
linGrBrush.GradientStops.Add(new GradientStop(Colors.Blue, 1));

byte[] bytes = _serializer.Serialize(linGrBrush);

The Exception
image

Seems like the object being serialized has been changed during serialization

Hi,
I'm using GroBuf Version=1.4.4.0 installed via nuget. Running the my app on Linux with Mono 5.16.0.179. I run Ubuntu 18.04 on a 128GB machine.

When I run serialization on an object of size ~1GB everything goes smoothly. However when serializing larger objects of the same type (e.g. 8GB) I get the following error:
"System.InvalidOperationException: Seems like the object being serialized has been changed during serialization".
Please advise how to proceed.

Wrong deserialization for dictionaries with Nullable<>-values

I wrote simple unit test which check values after deserialization and I got exception on checking value with key [2]:

var incoming = new Dictionary<int, int?>
    {
        [0] = null,
        [1] = 123,
        [2] = null,
    };
var serializer = new GroBuf.Serializer(
    new GroBuf.DataMembersExtracters.AllPropertiesExtractor(),
    new GroBuf.DefaultGroBufCustomSerializerCollection(),
    GroBuf.GroBufOptions.MergeOnRead | GroBuf.GroBufOptions.WriteEmptyObjects);
var raw = serializer.Serialize(incoming);
var outgoing = serializer.Deserialize<Dictionary<int, int?>>(raw);
outgoing[0].Should().Be(null);
outgoing[1].Should().Be(123);
outgoing[2].Should().Be(null); // Expected <null>, but found 123.

When I use nullable-values by default such as "string" then deserialization work correct.

Ability to serialize DataTables and Datasets

As the title says, currently im using a custom class

public class Info
{
public string str{ get; set; }
public List Stuff { get; set; }
}

I can insert things like Strings and Integers into Stuff, however if i try to serialize a DataTable it just returns null when I deserialize, and the size of the byte array makes me think its not even serializing it.

System.TypeInitializationException: The type initializer for 'GroBuf.GroBufHelpers' threw an exception

Hi, Great job!!
The performace of Grobuf is insane.... in my case its 2 times faster than Protobuf!

However, today, I am seeing this problem:

FYI, I am using Xamarin (which is based on Mono). It works on some devices and some don't. Not sure why though....
Particularly it is failing in Pixel 4, Pixel 5 and Xiaomi Redmi.

Here is the exception:
This happens when I try to serialize (I can't deserialize if I can't serialize)

System.TypeInitializationException: The type initializer for 'GroBuf.GroBufHelpers' threw an exception. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
  at (wrapper stelemref) System.Object.virt_stelemref_class_small_idepth(intptr,object)
  at GroBuf.GroBufHelpers.BuildLeafTypes () [0x000f1] in C:\projects\grobuf\GroBuf\GroBufHelpers.cs:167 
  at GroBuf.GroBufHelpers..cctor () [0x00032] in C:\projects\grobuf\GroBuf\GroBufHelpers.cs:21 
   --- End of inner exception stack trace ---
  at GroBuf.Writers.WriterCollection.GetWriterBuilderInternal (System.Type type, System.Boolean ignoreCustomSerialization) [0x002b3] in C:\projects\grobuf\GroBuf\Writers\WriterCollection.cs:76 
  at GroBuf.Writers.WriterCollection.GetWriterBuilder (System.Type type, System.Boolean ignoreCustomSerialization) [0x0004e] in C:\projects\grobuf\GroBuf\Writers\WriterCollection.cs:28 
  at GroBuf.Writers.WriterConstantsBuilderContext.BuildConstants (System.Type type, System.Boolean isRoot, System.Boolean ignoreCustomSerialization) [0x00024] in C:\projects\grobuf\GroBuf\Writers\WriterConstantsBuilderContext.cs:39 
  at GroBuf.Writers.WriterTypeBuilder.BuildWriter (System.Type type, System.Boolean ignoreCustomSerialization) [0x00080] in C:\projects\grobuf\GroBuf\Writers\WriterTypeBuilder.cs:26 
  at GroBuf.GroBufWriter.GetWriter (System.Type type, System.Boolean ignoreCustomSerialization) [0x0004f] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:246 
  at GroBuf.GroBufWriter.BuildWriter[T] (System.Boolean ignoreCustomSerialization) [0x0000b] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:257 
  at GroBuf.GroBufWriter.GetWriterAndSizeCounter[T] (System.Boolean ignoreCustomSerialization) [0x0004f] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:227 
  at GroBuf.GroBufWriter.Write[T] (System.Boolean ignoreCustomSerialization, T obj) [0x00000] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:72 
  at GroBuf.GroBufWriter.Write[T] (T obj) [0x00000] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:67 
  at GroBuf.Serializer.Serialize[T] (T obj) [0x00000] in C:\projects\grobuf\GroBuf\Serializer.cs:45 
  at ContactManager.Core.Extensions+CMSerializer.Serialize[T] (T obj) [0x0002f] in /Users/azrinsani/src/ContactManager/ContactManager.Core/CMCoreExt.cs:250 
  at ContactManager.Core.Extensions.SerializeToFile[T] (T obj, System.String fn) [0x00002] in /Users/azrinsani/src/ContactManager/ContactManager.Core/CMCoreExt.cs:260 
  at GroBuf.Writers.WriterCollection.GetWriterBuilderInternal (System.Type type, System.Boolean ignoreCustomSerialization) [0x002b3] in C:\projects\grobuf\GroBuf\Writers\WriterCollection.cs:76 
  at GroBuf.Writers.WriterCollection.GetWriterBuilder (System.Type type, System.Boolean ignoreCustomSerialization) [0x0004e] in C:\projects\grobuf\GroBuf\Writers\WriterCollection.cs:28 
  at GroBuf.Writers.WriterConstantsBuilderContext.BuildConstants (System.Type type, System.Boolean isRoot, System.Boolean ignoreCustomSerialization) [0x00024] in C:\projects\grobuf\GroBuf\Writers\WriterConstantsBuilderContext.cs:39 
  at GroBuf.Writers.WriterTypeBuilder.BuildWriter (System.Type type, System.Boolean ignoreCustomSerialization) [0x00080] in C:\projects\grobuf\GroBuf\Writers\WriterTypeBuilder.cs:26 
  at GroBuf.GroBufWriter.GetWriter (System.Type type, System.Boolean ignoreCustomSerialization) [0x0004f] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:246 
  at GroBuf.GroBufWriter.BuildWriter[T] (System.Boolean ignoreCustomSerialization) [0x0000b] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:257 
  at GroBuf.GroBufWriter.GetWriterAndSizeCounter[T] (System.Boolean ignoreCustomSerialization) [0x0004f] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:227 
  at GroBuf.GroBufWriter.Write[T] (System.Boolean ignoreCustomSerialization, T obj) [0x00000] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:72 
  at GroBuf.GroBufWriter.Write[T] (T obj) [0x00000] in C:\projects\grobuf\GroBuf\GroBufWriter.cs:67 
  at GroBuf.Serializer.Serialize[T] (T obj) [0x00000] in C:\projects\grobuf\GroBuf\Serializer.cs:45 
  at ContactManager.Core.Extensions+CMSerializer.Serialize[T] (T obj) [0x0002f] in /Users/azrinsani/src/ContactManager/ContactManager.Core/CMCoreExt.cs:250 
  at ContactManager.Core.Extensions.SerializeToFile[T] (T obj, System.String fn) [0x00002] in /Users/azrinsani/src/ContactManager/ContactManager.Core/CMCoreExt.cs:260 

Upon further investigation, I am seeing the following array is set to negative. This is what's triggering the exception.

Screen Shot 2022-01-13 at 4 31 42 pm

GroBuf doesn`t support .Net Core 3.0

Following code throws GroBuf.DataCorruptedException: Unexpected end of data exception.

        var dictToSerialize = new Dictionary<string, int>()
        {
            {"1",1},
            {"2",2},
            {"42",42}
        };
        
        var serializer=new Serializer(new AllPropertiesExtractor(), options: GroBufOptions.WriteEmptyObjects);
        var bytes = serializer.Serialize(dictToSerialize);

        var deserializedDict = serializer.Deserialize<Dictionary<string, int>>(bytes);

Application uses .Net Core 3.0 preview 7, so error seems like some compatibility trouble.
Thanks!

Memory leak when more instatnces created

Hello,
I'd like to use GroBuf serializer as one of the "sinks" in our remoting client-server communication because of its high performance compare to standard BinaryFormatter. We have a single call type of communication (new instance of server-side class for each client call) so there are a lot of instances of serializer created. The Serializer class doesn't implement IDisposable interface and cause memory leak.

Is there any way, how to destroy the serializer? Is it possible to implement IDisposable interface? Use static instance of the serializer is not possible for us because of the perfomance degrade.

Thank you a lot V.

CollectionDataContract and IDictionary

Hi,
I'm looking for a fast and reliable binary serializer for replacement of datacontractserializer in wcf. GroBuf seems a good alternative for this mission. But I couldn't serialize CollectionDataContract and the types derived from IDictionary or IEnumerable. It serializes only DataContract, List and Dictionary types. For example, It couldn't serialize ConcurrentDictionary or a type drived from Dictionary or IDictionary. Here is my test script:

using System.Collections.Concurrent;
using System.Runtime.Serialization;

[DataContract]
public class Asd
{
    [DataMember]
    public string Member { get; set; }
    public string NotMember { get; set; }
    [DataMember]
    public ExchangeRates Rates { get; set; }
    [DataMember]
    public List<ExchangeRate> RateList { get; set; }
    [DataMember]
    public ConcurrentDictionary<string, ExchangeRate> RateDic { get; set; }
    [DataMember]
    public ExchangeRateCustomList RateCustomList { get; set; }
}

[DataContract]
public class ExchangeRate
{
    [DataMember]
    public double Price { get; set; }
}

[CollectionDataContract(
        Name = "ExchangeRates",
        ItemName = "ExchangeRate",
        KeyName = "Currency",
        ValueName = "Rate")]
public class ExchangeRates : ConcurrentDictionary<string, ExchangeRate>
{
    
}

[CollectionDataContract(
        Name = "ExchangeRateList",
        ItemName = "ExchangeRate",
        ValueName = "Rate")]
public class ExchangeRateCustomList: List<ExchangeRate>
{
    
}

var asd = new Asd
{
    Member = "Member",
    NotMember = "NotMember",
    Rates = new ExchangeRates
    {
        ["TRY"] = new ExchangeRate
        {
            Price = 1.4d
        }
    },
    RateList = new List<ExchangeRate>
    {
        new ExchangeRate{
            Price = 1.4444213d
        }
    },
    RateDic = new ConcurrentDictionary<string, ExchangeRate>
    {
        ["TRY"] = new ExchangeRate
        {
            Price = 1.4d
        }
    },
    RateCustomList = new ExchangeRateCustomList
    {
        new ExchangeRate{
            Price = 1.4444213d
        }
    }
};


var s = new GroBuf.Serializer(new GroBuf.DataMembersExtracters.DataMembersByAttributeExtractor(true));
var r = s.Serialize(asd);
r.Dump();
s.Deserialize<Asd>(r).Dump();

Nuget package Mono.Reflection 1.1.0 is not netstandard2.0-compatible

When building GroBuf against netstandard2.0 the following warning is issued:

Warning NU1701:  Package 'Mono.Reflection 1.1.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

Mono.Reflection package is used only to get backing field of a property to support C# 6 read-only auto-properties. We need to find more portable way to do this and get rid of this annoying build warning.

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.