question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canonical serialization

See original GitHub issue

This 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adsharmacommented, Jul 23, 2021

Yes, Thanks for the feedback.

1reaction
adsharmacommented, Jul 21, 2021
  • In my modeling of network messages, there is rarely a dict in the message. Even if there is, it could be modeled as two vectors.
  • Re: representing the number -20 in many different ways, we just need to use pyserde as a reference implementation and say, -20 is to be represented as EC. Works for me 😃
  • Yes, like serde_skip better.
  • JSON: msgpack is more compact and probably faster to parse.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found