From e76b54e697ce8da391ba1cd24676bbbf0ccb4c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Tue, 12 May 2020 12:24:50 +0200 Subject: [PATCH] aquatic_ws: twenty byte serde: improve comment --- aquatic_ws/src/lib/protocol/serde_helpers.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aquatic_ws/src/lib/protocol/serde_helpers.rs b/aquatic_ws/src/lib/protocol/serde_helpers.rs index 6a4f7a2..1f5471f 100644 --- a/aquatic_ws/src/lib/protocol/serde_helpers.rs +++ b/aquatic_ws/src/lib/protocol/serde_helpers.rs @@ -30,8 +30,12 @@ impl<'de> Visitor<'de> for TwentyByteVisitor { // var infoHash = 'abcd..'; // 40 hexadecimals // Buffer.from(infoHash, 'hex').toString('binary'); // ``` - // which seemingly produces a UTF16 string with each char having only - // the "low byte" set. Here, we extract it by casting it to an u8. + // As I understand it: + // - the code above produces a UTF16 string of 20 chars, each having + // only the "low byte" set (e.g., numeric value ranges from 0-255) + // - serde_json decodes this to string of 20 chars (tested), each in + // the aforementioned range (tested), so the bytes can be extracted + // by casting each char to u8. let mut arr = [0u8; 20]; let mut char_iter = value.chars();