-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow other serialisation formats #15
Comments
Fantastic idea! I like the idea of it just working, that's one of the core On Thursday, 11 February 2016, Drew Noakes [email protected] wrote:
|
I have an idea. How about an interface that defines methods for serializing/deserializing objects and implementations of that interface for different serialization formats (which should be in separate assemblies). example interface: public interface ISerializer
{
byte[] Serialize(object obj);
object Deserialize(byte[] data);
} I have used an interface like this myself in some things I have toyed with (usually just playing with different serialization libraries to see which ones I like). |
That seems very sensible to me. Are there any other semantics that need to be captured here? How do we On 4 April 2016 at 02:57, Brisingr Aerowing [email protected]
|
Using TrySerialize and TryDeserialize would work, as would documenting standard exceptions. Maybe a custom exception (i.e. SerializationFailureException) would work as well, and have the exception that caused the failure as it's inner exception. |
Whenever a program throws an exception, its quite a heavyweight operation. A program can only throw so many exceptions per second before it hits a limit. If we are deserializing at high speed, this really hurts performance. In addition, every time a program throws an exception that is caught, it pops up in the debugger, if debugging is switched on for the CLR. For this reason, it is advisable to avoid throwing exceptions except in absolutely dire circumstances, e.g. the program is about to die. On 5 April 2016 23:01:52 BST, Brisingr Aerowing [email protected] wrote:
|
OK, true. Then the Try* methods would likely be the best bet. A method to get information on the error that happened would probably be nice, but not required. |
I was thinking about this, and I came up with an idea. The interface would look like: public interface ISerializer
{
bool TrySerialize(object obj, out byte[] result);
bool TryDeserialize(byte[] data, out object result);
SomeType GetLastError();
} The |
I think your options are either to use One point, I would suggest not using Other options:
Not sure what's best here really. The overhead of exceptions due to receiving junk over a socket could be a problem in high perf cases. Maybe just have the |
True. The Sorry for the late reply. Internet issues (Damn Frontier...) and being very sick don't help. |
For example, I use Dasher which is a MsgPack serialiser for .NET that doesn't require any annotations on your types.
https://github.com/drewnoakes/dasher
https://www.nuget.org/packages/Dasher/
The text was updated successfully, but these errors were encountered: