A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/msgpack/msgpack-cli/issues/202 below:

IPackable/IUnpackable implementations ignored when no fields present · Issue #202 · msgpack/msgpack-cli · GitHub

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:

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 :)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4