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.6.tar.gz
.
File metadata
- Download URL: msgpack-lz4block-0.2.6.tar.gz
- Upload date:
- Size: 4.8 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 | 7cd26460ce45bdffa8ee1e660469e08cb8e1f7cd250311458d10260b62df178c |
|
MD5 | 77b0a2ad99457f7e8703d9f25cc9e828 |
|
BLAKE2b-256 | 545ba37239bc67965d84c8ec629678b4e0e6306d53b527c540cd81191b68c4e4 |
File details
Details for the file msgpack_lz4block-0.2.6-py3-none-any.whl
.
File metadata
- Download URL: msgpack_lz4block-0.2.6-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 | ae89491dc8e73267ecf3d4f6732719577b389dda99da6048e66fdf04173b75b0 |
|
MD5 | a2655b14d16f6f0454d8275f4791d45e |
|
BLAKE2b-256 | e5b26a0a0ea7d8e4d7bb9c7cf157013fb08623ce13945e32fc66ef4ea75d787b |