HackMD
    • Sharing Link copied
    • /edit
    • View mode
      • Edit mode
      • View mode
      • Book mode
      • Slide mode
      Edit mode View mode Book mode Slide mode
    • Note Permission
    • Read
      • Only me
      • Signed-in users
      • Everyone
      Only me Signed-in users Everyone
    • Write
      • Only me
      • Signed-in users
      • Everyone
      Only me Signed-in users Everyone
    • More (Comment, Invitee)
    • Publishing
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
    • Options
    • Versions and GitHub Sync
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Google Drive Export to Google Drive
    • Gist
    • Import
    • Google Drive Import from Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
Menu Sharing Help
Menu
Options
Versions and GitHub Sync Transfer ownership Delete this note
Export
Google Drive Export to Google Drive Gist
Import
Google Drive Import from Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML
Back
Sharing
Sharing Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
More (Comment, Invitee)
Publishing
More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   owned this note    owned this note      
Published Linked with GitHub
Like BookmarkBookmarked
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# P2P Message Serialization ## Why not RLP? See https://github.com/ethereum/wiki/wiki/Wishlist#rlp ## Requirements - Deterministic field ordering. The same data should always be mapped to the same hash. ## Candidates | Candidate | Supported Languages | Deterministic | Pros | Cons | | ------------ | ------------------- | ------------- | ---- | ------ | | [Protobuf](https://developers.google.com/protocol-buffers/) | C++, Java, Python, Go, C#, Objective C, JavaScript and Rust| No [1] | | The deterministic serialization is NOT canonical across languages. Fields may be in different order which poses hashing problems.| | [CBOR](http://cbor.io/) | | No [2] | | | | [Cap’n Proto](https://capnproto.org/) | Serialization + RPC: C++, Erlang, Go, Javascript, OCaml, Python, Rust. Serialization only: C, C#, D, Go, java, Javascript, Lua, Nim, Ruby, Scala | Supported [3] | Schema support | | | [FlatBuffers](https://google.github.io/flatbuffers/) | C++, C#, C, Go, Java, JavaScript, TypeScript, PHP, and Python | No [4] | Schema support |Non-deterministic | | [SimpleSerialize](https://github.com/ethereum/eth2.0-specs/blob/master/specs/simple-serialize.md#implementations) | Python, Rust, Nim, Javascript | Always [5] | Simple | Need more tests and impl work | [MessagePack](https://msgpack.org/index.html) | C/C++, Java, Python, Rust, Go, JavaScript, Nim and dozens other languages | Supported [6] | | No schema support | |Thrift| C++,C#,Go,Cocoa,D,Delphi,Erlang,Haskell,Java,OCaml,Perl,PHP,Python,Ruby,Smalltalk| Supported [7] | Schema support | | [Avro](https://avro.apache.org/docs/current/) | Java, C, C++, C# | [Only maps and arrays are non-deterministic](https://stackoverflow.com/questions/28129664/why-isnt-the-avrocoder-deterministic#28131766); there is an [attempt at a deterministic version](https://bitbucket.org/jlewi/dataflow/src/3fc7ae6d353fd8457d757eac72322ec2f768a6e5/dataflow/src/main/java/dataflow/AvroDeterministicCoder.java?at=master) | Uses JSON for schemas; dynamic typing, Untagged data (more compact, faster de/serialization) | Depends on schemas, extra support may be lacking / need development for some languages | ## Custom serialization suggestions - Add a magic number - Add major.minor versioning - Add an "offset" field that tells the offset at which raw data starts. - Schema as JSON - Raw data (numbers always stored in specific endianness) Inspiration from [Numpy file format](https://github.com/numpy/numpy/blob/master/numpy/lib/format.py). ## Further reading - https://en.wikipedia.org/wiki/Comparison_of_data_serialization_formats - etc.: https://duckduckgo.com/?q=comparision+of+data+serialization+formats&t=ffab&ia=web ## References 1. Protobuf Github Issue - "Protobuf serialization is not canonical": https://github.com/google/protobuf/issues/3417 2. CBOR spec - "no requirement that all data formats be uniquely encoded": https://tools.ietf.org/html/rfc7049 3. Cap'n Proto docs - "it is possible to write code which canonicalizes a ... message" - https://capnproto.org/encoding.html#canonicalization 4. FlatBuffers docs - has "flexibility" for ordering: https://google.github.io/flatbuffers/flatbuffers_internals.html 5. SimpleS - Vitalik designed it for this purpose. No known reference but it seems obvious. 6. MessagePack spec - supports "deterministic" serialized data in some cases: https://github.com/msgpack/msgpack/blob/master/spec.md 7. Thrift specification https://thrift.apache.org/static/files/thrift-20070401.pdf

Import from clipboard

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lost their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.


Upgrade

All
  • All
  • Team
No template.

Create a template


Upgrade

Delete template

Do you really want to delete this template?

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Sign in via SAML

or

Sign in via GitHub

Help

  • English
  • 中文
  • 日本語

Documents

Tutorials

Book Mode Tutorial

Slide Example

YAML Metadata

Resources

Releases

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions

Versions and GitHub Sync

Sign in to link this note to GitHub Learn more
This note is not linked with GitHub Learn more
 
Add badge Pull Push GitHub Link Settings
Upgrade now

Version named by    

More Less
  • Edit
  • Delete

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub

      Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

       Sign in to GitHub

      HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully