Comments (3)
The reason why BinaryFormatter can serialize/deserialze the "object" is the same reason it is slow and produces big files.
Use generics like this it should be just fine:
byte[] ToBois(this T obj)
private static readonly BoisSerializer Serializer = new BoisSerializer();
public static byte[] ToBois<T>(this T obj) {
using (var ms = new MemoryStream()) {
Serializer.Serialize(obj, ms);
return ms.ToArray();
}
}
public static T FromBois<T>(this byte[] bytes) {
return Serializer.Deserialize<T>(new MemoryStream(bytes));
}
from bois.
Too bad. Unfortunately, I'm stuck with BinaryFormatter, then. Not only does Bois not work with a class cast as an object, but it won't serialize any child members of a generic class if they're stored as objects.
Does it really kill performance/output size to reflect an object's type?
from bois.
Yes it does kill performance/size. The performance come from planned deserialization. With dynamic objects can't do that.
You may find other binary serializers able to retain the object type in the process.
from bois.
Related Issues (20)
- Common Language Runtime detected an invalid program HOT 8
- Constructor on type 'SchemaSet' not found. HOT 6
- polymorphic objects HOT 1
- Another deserialization example? HOT 2
- Some object properties seralized with default constructor values instead of correct values HOT 3
- How does Salar Bois compare to Protobuf? HOT 1
- Request for supporting netstandard2.0 HOT 1
- Nullable Enums throw an error on deserialization HOT 1
- Adding a support (de/serialization) for others language HOT 1
- Variable output depending on the runtime version used HOT 4
- Note on Behaviour with .NET 6.0 HOT 7
- Deserialization error "Unable to read beyond the end of the stream" HOT 4
- Bois for serializing objects to store in SQLite blob? HOT 5
- Out of memory error when serializing a Dictionary with 16 million items HOT 2
- Use streams for BoisLz4Serializer
- Add support for .Net new buffer types, Span<T>, Memoery<T>, ArraySegement<T> and etc.
- error on Deserializing HOT 6
- Deseriealize problem when child object is null HOT 6
- Exception: "This operation is only valid on generic types." HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bois.