NetBinSerializer 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NetBinSerializer --version 1.0.0                
NuGet\Install-Package NetBinSerializer -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetBinSerializer" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetBinSerializer --version 1.0.0                
#r "nuget: NetBinSerializer, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetBinSerializer as a Cake Addin
#addin nuget:?package=NetBinSerializer&version=1.0.0

// Install NetBinSerializer as a Cake Tool
#tool nuget:?package=NetBinSerializer&version=1.0.0                

NetBinSerializer

C# types serialization library

Features:

  • minimum result bytes array size (without compressing)
  • program and version independence (but it's unsafe (without classes fields coincidence control))
  • base for serialization methods auto builders
  • opportunity to save serialization/deserialization type methods and use it
  • using reflection only for type serialization methods building

Limitations

  • serialization classes and structures extension isn't allowed. I.e. if class Cat : Animal will be passed with animal type, it will be serialized as an Animal
  • NetBinSerializer can't normal serialize/deserialize types, which use system pointers/descriptors and other resources
  • you should know, which fields are in serialized class/structure

Classes

NetBinSerialization library has two serialization classes
SerializeStream - low level serialization object to serialize base types
Serializer - high level serialization static class with serialization methods caching, picking and building for difficult types

Interfaces:
ISerializable - interface with writeToStream and readToStream methods. If a class or structure implements this interface, serialization and deserialization will be complete by these methods call (deserialization works without constructor call!).
ISerializationMethodsBuilder - interface for high level serialize/deserialize custom methods builder class (implement getSerializationMethods for type serialization methods build)
As methods builder you can use SMAB library.

SerializationMethodsBase - object, that provides methods serialize(SerializeStream stream, object obj) and object deserialize(SerializeStream stream). Serializer class contains cached Dictionary of <Type, ISerializationMethods>.

SerializeStream

Stream for objects serialization/deserialization

Create
  • for serialization create SerializeStream by new SerializeStream()
  • for deserialization create SerializeStream by new SerializeStream(byte[] bytes)
Write/read

Supported main types: Int64, Int32, Int16, SByte, UInt64, UInt32, UInt16, Byte, Float, Double, String, bytes array, Serializable

  • to write base type in bytes use void Write+[var_type]([var_type]) or void Write([var_type]) overloaded method
  • to read base type in bytes use [var_type] Read+[var_type]()
  • you can write objects by void WriteUnknown(object), but it's no reason to use this method. You should always know serializable/deserializable object's type

Also SerializeStream can work with other Arrays and Collections types, but it's better to use Serializer.serialize and Serializer.deserialize methods for difficult types Write and read other types methods:

  • void WriteArray(Array) / Array ReadArray(Type) with generic analogs
  • void WriteCollectionObject(object) / object ReadCollectionObject(Type)
  • void WriteObject(object) / object ReadObject() for difficultObject's (by using BinaryFormatter)

Serializer

High level serialization class, with supports caching, serialize/deserialize methods save, custom methods builders It's better to use this for difficult types, which aren't SerializeStream main types (also it's better for arrays and collections)

Cache
  • bool IsCached(Type) returns true if type's serialization methods are in cache
  • bool GetCached(Type, out ISerializationMethods methods) returns true and methods = serialization methods container if type's serialization methods are in cache else false
  • bool Cache(SerializationMethods.SerializeMethod, SerializationMethods.DeserializeMethod, Type) adds serialize and deserialize methods in cache, returns false, if methods for type are already in cache.
  • bool Cache(this ISerializationMethods, Type) cache function for methods in ISerializationMethods shell
Prebuild serialization methods
  • bool BuildAndCacheIntegrated(Type) (builds and caches type serialization methods with integrated SimpleSerializationMethodsBuilder (only for arrays and collections)) returns true if success
  • bool BuildAndCache(Type) builds and caches type serialization methods with custom serializationMethodsBuilder
Serialization/deserialization
  • SerializeSafe/DeserializeSafe and generics analogs returns true, if obejct was successfully serialized/deserialized
  • Serialize/Deserialize if serialization/deserialization fail occured, thrwos SerializationException Also Serializer methods has this SerializeStream arg, and because you can write stream.serialize(myObject, typeof(MyObject))
SerializationContext

SerializationContext is optimization class, that solves some references problem (inclusive references cycles in the serialize tree) and approves null values

Example

Example code for low and hight levels serialization/deserialization

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NetBinSerializer:

Package Downloads
SerializeMethodsAutoBuilder

C# library for auto build serialize and deserialize to byte array methods for given type (based on NetBinSerializer).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 534 7/23/2021
1.0.1 438 5/16/2021
1.0.0 305 5/13/2021