Canonical serialization
See original GitHub issueThis was discussed here back in 2016 https://github.com/msgpack/msgpack/issues/215
Does pyserde have a repeatable serialization that could be fed to hashlib?
import hashlib
from datetime import datetime
from typing import Optional
from dataclasses import dataclass
from serde import serialize
from serde.msgpack import to_msgpack
@serialize
@dataclass
class Entry:
feed_url: str
id: str
updated: Optional[datetime] = None
e = []
for i in range(3):
entry = Entry('feed one', 'id', datetime(i+1, i+1, i+1))
e.append(entry)
for i in range(3):
for j in range(3):
print(hashlib.sha256(to_msgpack(e[j])).hexdigest())
seems repeatable. But I haven’t tested it across platforms.
Also see:
https://death.andgravity.com/stable-hashing where json was used https://github.com/yuan-xy/canoser-python where dataclasses could be used, but are not.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
diem/bcs: Rust implementation of the Binary Canonical ...
The BCS format guarantees canonical serialization, meaning that for any given data type, there is a one-to-one correspondance between in-memory values and valid ......
Read more >libra_canonical_serialization - Rust - Docs.rs
To address this, we propose Libra Canonical Serialization that defines a deterministic means for translating a message into bytes and back again.
Read more >Canonical serialization of object - Stack Overflow
My solution to this was to just serialize it (to say json) and then just hmac the serialized data.
Read more >Canonical Data Format (Buhler, Erl, Khattak) - Arcitura Patterns
A canonical and extensible serialization format is chosen to save data such that disparate clients are able to read and write data.
Read more >The main concern that the deterministic serialization isn't ...
The main concern that the deterministic serialization isn't canonical is due to the unknown fields. As string and message type share the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, Thanks for the feedback.
serde_skip
better.