Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An efficient custom binary serializer running by the .NET standards

License

NotificationsYou must be signed in to change notification settings

grammophone/Grammophone.Serialization

Repository files navigation

This .NET Standard 2.0 libraryprovides theFastBinaryFormatter class, anIFormatterimplementation as a replacement for the standard BinaryFormatter for serialization purposes. It has the following features:

  1. It has a higher upper limit for the number of objects being serialized. The standard BinaryFormatterhas a limit of ~13.2 million objects. The FastBinaryFormatter limits 2^31 reference-type instances and poses no limits to value-type instances.
  2. It runs faster and is less memory-demanding, especially during deserialization.
  3. Serialization streams typically have smaller size compared to the ones produced by BinaryFormatter and they are not compatible.
  4. Serialization streams are portable between 32 bit and 64 bit applications.
  5. Relies on the standards. As a consequence, existing serializable classes, like those in the .NET base class library, need no change. Specifically, it supports:

The significant performance gain comes at the cost of not supporting a very specific scenario:

During deserialization, if a registeredISerializationSurrogate returnsin methodSetObjectData a (non-null) different objectthan the one supplied to populate, then the data suppliedin theSerializationInfo must not recursively causea deserialization cycle up to the new object.A cycle is allowed though if it is established outside the deserialized objects.In particular, cycles formed by associations created by other surrogates are allowed.

The same restriction applies toIObjectReference implementations.

Note that support for returning a different non-null object in methodSetObjectDatahas effect in version .NET 2.0 and later. The return value was previously ignored.

This scenario is highly unlikely to be found in practice. However, it is detected during deserialization and an exception is thrown upon occurrence.

The library has no dependencies.

##Example usageUsingFastBinaryFormatter is same as built-in .NET serialization formatters.

Album[]serializedObject=BuildAlbumArray();// Example object graph.varformatter=newFastBinaryFormatter();// If required, define surragate selectors.varsurrogateSelector=newSurrogateSelector();surrogateSelector.AddSurrogate(typeof(Genre),newStreamingContext(),newGenreSerializationSurrogate());formatter.SurrogateSelector.ChainSelector(surrogateSelector);using(varstream=newMemoryStream()){// Serialize.formatter.Serialize(stream,serializedObject);stream.Seek(0,SeekOrigin.Begin);// Deserialize.vardeserializedObject=(Album[])formatter.Deserialize(stream);}

About

An efficient custom binary serializer running by the .NET standards

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp