-
Notifications
You must be signed in to change notification settings - Fork 1.1k
*: Add Serialize and Deserialize to PeerId gossipsub MessageId and kad Key #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1941a88
add Serialize and Deserialize to PeerId and MessageId
laptou e1b3b96
add serde imports
laptou ab56c2b
go back to use-serde
laptou 6969a78
remove newline
laptou cc612ea
manually enable serde derive
laptou ba00323
use alias
laptou 4ae3d75
add custom serialize / deserialize + tests
laptou e6fc59c
remove serde default feature
laptou 2a387ae
update changelogs
laptou 42d9fe2
Merge branch 'master' into use-serde
laptou 7840b70
Merge remote-tracking branch 'upstream/master' into use-serde
laptou 67645f9
implement Serialize, Deserialize for kad::store::record::Key
laptou 6e30381
rustfmt + changelog
laptou f80ea71
implement visit_str instead of visit_borrowed_str
laptou 52a620f
Merge branch 'master' into use-serde
laptou 4f9bad1
Update core/src/peer_id.rs
laptou 85ef4d9
Merge branch 'master' into use-serde
laptou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#![cfg(feature = "serde")] | ||
|
||
use std::str::FromStr; | ||
|
||
use libp2p_core::PeerId; | ||
|
||
extern crate _serde as serde; | ||
|
||
#[test] | ||
pub fn serialize_peer_id_json() { | ||
let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); | ||
let json = serde_json::to_string(&peer_id).unwrap(); | ||
assert_eq!( | ||
json, | ||
r#""12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC""# | ||
) | ||
} | ||
|
||
#[test] | ||
pub fn serialize_peer_id_msgpack() { | ||
let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); | ||
let buf = rmp_serde::to_vec(&peer_id).unwrap(); | ||
assert_eq!( | ||
&buf[..], | ||
&[ | ||
0xc4, 38, // msgpack buffer header | ||
0x00, 0x24, 0x08, 0x01, 0x12, 0x20, 0xe7, 0x37, 0x0c, 0x66, 0xef, 0xec, 0x80, 0x00, | ||
0xd5, 0x87, 0xfc, 0x41, 0x65, 0x92, 0x8e, 0xe0, 0x75, 0x5f, 0x94, 0x86, 0xcb, 0x5c, | ||
0xf0, 0xf7, 0x80, 0xd8, 0xe0, 0x6c, 0x98, 0xce, 0x7d, 0xa9 | ||
] | ||
); | ||
} | ||
|
||
#[test] | ||
pub fn deserialize_peer_id_json() { | ||
let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); | ||
let json = r#""12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC""#; | ||
assert_eq!(peer_id, serde_json::from_str(json).unwrap()) | ||
} | ||
|
||
#[test] | ||
pub fn deserialize_peer_id_msgpack() { | ||
let peer_id = PeerId::from_str("12D3KooWRNw2pJC9748Fmq4WNV27HoSTcX3r37132FLkQMrbKAiC").unwrap(); | ||
let buf = &[ | ||
0xc4, 38, // msgpack buffer header | ||
0x00, 0x24, 0x08, 0x01, 0x12, 0x20, 0xe7, 0x37, 0x0c, 0x66, 0xef, 0xec, 0x80, 0x00, 0xd5, | ||
0x87, 0xfc, 0x41, 0x65, 0x92, 0x8e, 0xe0, 0x75, 0x5f, 0x94, 0x86, 0xcb, 0x5c, 0xf0, 0xf7, | ||
0x80, 0xd8, 0xe0, 0x6c, 0x98, 0xce, 0x7d, 0xa9, | ||
]; | ||
|
||
assert_eq!(peer_id, rmp_serde::from_read(&mut &buf[..]).unwrap()); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.