Giter VIP home page Giter VIP logo

Comments (3)

salarcode avatar salarcode commented on June 1, 2024

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.

ignusfast avatar ignusfast commented on June 1, 2024

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.

salarcode avatar salarcode commented on June 1, 2024

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)

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.