You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems you can not deserialize a tuple struct like this struct Node(String, i64) from a nested list in encoded format. There are already two tests for this behavior.
#[test]fndeserialization(){// todo: you cannot deserialize to the same struct used in serialization.// It does not work with a tuple struct `struct Node(String, i64)`// instead of a tuple `(String, i64)`.#[allow(dead_code)]#[derive(PartialEq,Debug,Serialize,Deserialize)]structTorrent{info:Info,#[serde(default)]nodes:Option<Vec<(String,i64)>>,}#[allow(dead_code)]#[derive(PartialEq,Debug,Serialize,Deserialize)]structInfo{#[serde(default)]publength:Option<i64>,#[serde(default)]pubname:String,#[serde(rename = "piece length")]pubpiece_length:i64,#[serde(default)]pubpieces:ByteBuf,}#[derive(PartialEq,Debug,Serialize,Deserialize)]structNode(String,i64);// cspell:disable-next-linelet b = "d4:infod6:lengthi8e4:name11:minimal.txt12:piece lengthi1e6:pieces1:pe5:nodesll15:188.163.121.224i56711eel14:162.250.131.26i13386eeee";let r:Torrent = from_str(b).unwrap();assert_eq!(
r,
Torrent{
info: Info{
name: "minimal.txt".to_string(),
pieces: ByteBuf::from(vec![b'p']),
piece_length: 1,
length: Some(8),
},
nodes: Some(vec![("188.163.121.224".to_string(), 56711),
("162.250.131.26".to_string(), 13386),
]),
});}
nodes: Option<Vec<Node>>, where Node is struct Node(String, i64)
nodes: Option<Vec<(String, i64)>>,
produce the same bencoded, but you can only deserialize the second one. The first one gives you only one item in the parent list (one node).
I am still determining if that's a bug. As bencoded format is ordered, there should be no problem assigning the values to the tuple struct fields (0 and 1). The first value should be assigned to the first element in the tuple.
Anyway, ti seems the problem is not even in this package but when the series values are mapped to the final struct (not sure).
The text was updated successfully, but these errors were encountered:
It seems you can not deserialize a tuple struct like this
struct Node(String, i64)
from a nested list in encoded format. There are already two tests for this behavior.Although you can serialize them:
Both options:
nodes: Option<Vec<Node>>,
whereNode
isstruct Node(String, i64)
nodes: Option<Vec<(String, i64)>>,
produce the same bencoded, but you can only deserialize the second one. The first one gives you only one item in the parent list (one node).
I am still determining if that's a bug. As bencoded format is ordered, there should be no problem assigning the values to the tuple struct fields (0 and 1). The first value should be assigned to the first element in the tuple.
Anyway, ti seems the problem is not even in this package but when the series values are mapped to the final struct (not sure).
The text was updated successfully, but these errors were encountered: