diff --git a/TODO.md b/TODO.md index a2f1020..62725f4 100644 --- a/TODO.md +++ b/TODO.md @@ -16,7 +16,6 @@ * move stuff to common crate with ws: what about Request/InMessage etc? * info hashes, peer ids: check that whole deserialization and url decoding works as it should. There are suspicously many `\u{fffd}` -* AnnounceRequest.compact: handle that it is optional ## aquatic_ws * tests diff --git a/aquatic_http/src/lib/protocol/mod.rs b/aquatic_http/src/lib/protocol/mod.rs index f9321b8..66f7252 100644 --- a/aquatic_http/src/lib/protocol/mod.rs +++ b/aquatic_http/src/lib/protocol/mod.rs @@ -74,15 +74,21 @@ pub struct AnnounceRequest { pub bytes_left: usize, #[serde(default)] pub event: AnnounceEvent, - /// FIXME: is optional, so should default to something, maybe `true` #[serde( - deserialize_with = "deserialize_bool_from_number" + deserialize_with = "deserialize_bool_from_number", + default = "AnnounceRequest::default_compact_value" )] pub compact: bool, /// Requested number of peers to return pub numwant: usize, } +impl AnnounceRequest { + fn default_compact_value() -> bool { + true + } +} + #[derive(Debug, Clone, Serialize)] pub struct AnnounceResponseSuccess {