Deserialize and decompress messages serialized by the C# lib "MessagePack-CSharp" using lz4block compression.
Project description
msgpack-lz4block
Python lib to 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:
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
Built Distribution
File details
Details for the file msgpack-lz4block-0.2.5.tar.gz
.
File metadata
- Download URL: msgpack-lz4block-0.2.5.tar.gz
- Upload date:
- Size: 4.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | dad9d3a69ff970fb6d9864d0ceb2fbcb7f1792b25cefaea6c8099ca731a427cd |
|
MD5 | 7e15a44d3e758acaef2e44cf1ecf942f |
|
BLAKE2b-256 | 7eb08052ef43cb432acd89db1cf72a4b3fc31781694c7c79f766899893a97583 |
File details
Details for the file msgpack_lz4block-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: msgpack_lz4block-0.2.5-py3-none-any.whl
- Upload date:
- Size: 5.1 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67f7bdc74683dd9ff6160f598e521a62cead7508a70681d1a6ff15edebc677bb |
|
MD5 | d2e55a3f76da385f3f69727a1763debb |
|
BLAKE2b-256 | fc5f11d92e695f0abcb598235eaa62f674ad12c3cb3f16a7645e53c2f736a448 |