davidfowl / BedrockFramework

High performance, low level networking APIs for building custom servers and clients.
MIT License
1.04k stars 152 forks source link

Out-of-Box BinarySerializer #135

Closed shaggygi closed 2 years ago

shaggygi commented 2 years ago

Would be a nice-to-have serializer like the following for a standard approach on converting data to/from objects.

https://github.com/jefffhaynes/BinarySerializer

KieranDevvs commented 2 years ago

What's wrong with protobuf? It has good VS tooling support, requires near zero effort to setup and it's language agnostic too. Just install the nuget package, write your proto schemas, and then VS will generate the stubs and message classes for you.

Usage is as simple as MyType.Parser.ParseFrom(byte[]...);, or new MyType().ToByteArray();

shaggygi commented 2 years ago

Thanks @KieranDevvs for the feedback and a good suggestion. However, it would be nice to have more flexibility on the encoding/decoding on the various object properties of different types (int, double, float, etc.) based on the protocol being used. For examples, BACnet doesn't have leading bytes in some scenarios for ints/uints. There also might be cases where you have multiple bool properties that make up certain bits in a byte(s) to be processed. The BinarySerializer mentioned above appears to have attributes (have not done a deep dive yet) where you can add to the properties to perform the needed conversions and order to do so.

BTW, I don't want to downplay the BinarySerializer project as it might be a good solution. Just was throwing this issue out to see if there was some related thinking/designing being added in Bedrock (or elsewhere within the core .NET libs) that would support (giving the warm/fuzzies a long-term solution 😄).

davidfowl commented 2 years ago

This project has no plans to implement a custom serializer. There are a bunch of good options including protobuf, message pack, Hagar , Bebop, Hyperion

shaggygi commented 2 years ago

Understood, was mainly curious on thoughts. Never heard of some of those mentioned I'll check out. Thx

jzabroski commented 2 years ago

@shaggygi There is also Microsoft Bond, which supports 3 different formats for serialization, including 3 separate protocols:

shaggygi commented 2 years ago

@jzabroski thank you for the info 👍