Skip to main content

Deserialize and decompress messages serialized by the C# lib "MessagePack-CSharp" using lz4block compression.

Project description

python-msgpack-lz4block

Deserialize and decompress messages serialized by the C# lib "MessagePack-CSharp" using lz4block compression.

This project has been created to address this issue.

Installation

  • run the above command:
pip install msgpack-lz4block

Usage

The deserialize function allows to deserialize a c# object that has been MessagePackSerialized using Lz4BlockArray compression.

  • Begin by importing the msgpack_lz4block module :
>>> import msgpack_lz4block
  • Now, let’s deserialize a bytes array (that was generated using MessagePack + Lz4BlockArray) :
>>> msgpack_lz4block.deserialize(b'\x92\xd4b&\xc6\x00\x00\x00(\xf0\x17\x94 \xa8Perceval\x92\xaeOn en a gros !*\xa9de Galles')
[32, 'Perceval', ['On en a gros !', 42], 'de Galles']
  • We got the values... but we still miss the keys. The keys are not serialized in order to optimize the data usage. We can provide the key mapping as above, we get a beautiful key/value dict:
>>> key_map = ['Age', 'FirstName', ('MySubObj', ['Quote', 'MyInt']), 'LastName']
>>> msgpack_lz4block.deserialize(b'\x92\xd4b&\xc6\x00\x00\x00(\xf0\x17\x94 \xa8Perceval\x92\xaeOn en a gros !*\xa9de Galles', key_map=key_map)
{'Age': 32, 'FirstName': 'Perceval', 'MySubObj': {'Quote': 'On en a gros !', 'MyInt': 42}, 'LastName': 'de Galles'}
  • That's all, we successfully deserialized the data that was generated by the above c# code
using MessagePack;
using System.IO;

namespace msgpackWithLz4
{
    [MessagePackObject]
    public class MyClass
    {
        [Key(0)]
        public int Age { get; set; }
        [Key(1)]
        public string FirstName { get; set; }
        [Key(2)]
        public MySubClass MySubObj { get; set; }
        [Key(3)]
        public string LastName { get; set; }
    }

    [MessagePackObject]
    public class MySubClass
    {
        [Key(0)]
        public string Quote { get; set; }
        [Key(1)]
        public int MyInt { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var myObj = new MyClass
            {
                Age = 32,
                FirstName = "Perceval",
                LastName = "de Galles",
                MySubObj = new MySubClass
                {
                    Quote = "On en a gros !",
                    MyInt = 42
                },
            };
            var lz4Options = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray);
            byte[] bytes = MessagePackSerializer.Serialize(myObj, lz4Options);
            File.WriteAllBytes("output", bytes);
        }
    }
}

Dependencies:

This library depends on:

  • msgpack : to deserialize the msgpack structure
  • lz4 : to decompress the lz4 data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msgpack-lz4block-0.2.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

msgpack_lz4block-0.2.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file msgpack-lz4block-0.2.4.tar.gz.

File metadata

  • Download URL: msgpack-lz4block-0.2.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for msgpack-lz4block-0.2.4.tar.gz
Algorithm Hash digest
SHA256 deeb0540a5c18a34a3439c53adb3dc654796a273b8c3bbf824f0da6e70c98b81
MD5 bba5f8f9ddae55b8a3437b33c7045c99
BLAKE2b-256 52c15aa411c1edae48e335b40c564a54a5cbf6ffa3b29dc1f467e2fa00a86001

See more details on using hashes here.

File details

Details for the file msgpack_lz4block-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: msgpack_lz4block-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for msgpack_lz4block-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4f495ddb195f27f75aa40eebaa6f08c688c0a317822fb96a8589178b81ea0717
MD5 5c4c811382a167a2337e4653a024445f
BLAKE2b-256 4da8d7888c1b134656784538e724363170d7ee837888e688609ee9bf3bdae43f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page