Skip to content
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

IPackable/IUnpackable implementations ignored when no fields present #202

Closed
omaskery opened this issue Nov 24, 2016 · 3 comments
Closed
Labels
bug Detected as bug

Comments

@omaskery
Copy link

Hullo,

I am creating a networked application with this library for serialising my packet payloads. Some packets have no payload, which I represent for convenience as an empty dictionary (since all other payloads are encoded as a dictionary).

The problem is that this library does not allow you to serialise/deserialise classes with no fields:

With the class:

class SerializeMe {}

This line will throw an exception complaining about a lack of fields to serialise:

var serializer = MessagePackSerializer.Get<SerializeMe>(m_Serialisation);

Understanding that, whilst I would like for this to work, it may go against the libraries design decisions - I decided to implement IPackable and IUnpackable for SerializeMe:

class SerializeMe : IPackable, IUnpackable
{
    public void PackToMessage(Packer packer, PackingOptions options)
    {
        packer.PackMapHeader(0);
    }

    public void UnpackFromMessage(Unpacker unpacker)
    {
        long length;    
        unpacker.ReadMapHeader(out length); 
    }
}

The library still complains that I have no fields to serialise, even though it shouldn't care as I now provide a manual packable/unpackable interface? I feel like this is unintentional behaviour? Adding a dummy field to SerializeMe causes it to use the IPackable/IUnpackable interface.

I hope I've described the situation adequately, let me know if you need more information :)

@yfakariya
Copy link
Member

Thank you for reporting. It is not an expected behaviour. I agree that the interface methods should be called even the type does not have any members.

@yfakariya yfakariya added the bug Detected as bug label Nov 29, 2016
yfakariya added a commit that referenced this issue Feb 11, 2017
… be serialized. #202

This commit add
* Unit tests for new specs.
* Relaxes validation to allow types which implement I[Un][Async]Packable fully but have no members.
* Add additional validation to check such types implements pair of interfaces or not.
yfakariya added a commit that referenced this issue Feb 11, 2017
… be serialized. #202

This commit add
* Unit tests for new specs.
* Relaxes validation to allow types which implement I[Un][Async]Packable fully but have no members.
* Add additional validation to check such types implements pair of interfaces or not.
yfakariya added a commit that referenced this issue Feb 11, 2017
… be serialized. #202

This commit add
* Unit tests for new specs.
* Relaxes validation to allow types which implement I[Un][Async]Packable fully but have no members.
* Add additional validation to check such types implements pair of interfaces or not.
yfakariya added a commit that referenced this issue Feb 12, 2017
… be serialized. #202

This commit add
* Unit tests for new specs.
* Relaxes validation to allow types which implement I[Un][Async]Packable fully but have no members.
* Add additional validation to check such types implements pair of interfaces or not.
@yfakariya
Copy link
Member

Fixed in f34c23f

@omaskery
Copy link
Author

Hi, just to say thank you for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Detected as bug
Projects
None yet
Development

No branches or pull requests

2 participants