public void EncodeDictionary() { Hashtable dict = new Hashtable(); Hashtable inner = new Hashtable(); dict["list"] = ListOf("spam", "eggs"); inner["key"] = 42L; dict["inner"] = inner; Assert.AreEqual(Encode("d3:keyi42ee"), BEncoder.Encode(inner)); Assert.AreEqual(Encode("d5:innerd3:keyi42ee4:listl4:spam4:eggsee"), BEncoder.Encode(dict)); }
public static ByteString CreateTestResponseString() { Hashtable response = new Hashtable(); response["interval"] = 10; response["tracker id"] = "some tracker id"; response["complete"] = 1; response["incomplete"] = 2; response["peers"] = new ByteString(new byte[] { 127, 0, 0, 1, 0x1a, 0xe1, 207, 142, 131, 248, 0x1a, 0xe2, 105, 100, 107, 120, 0x1a, 0xe3 }); ByteString encodedResponseBody = new ByteString(BEncoder.Encode(response)); return(new ByteString(string.Format("HTTP/1.1 OK\r\n\r\n{0}", encodedResponseBody.ToString()))); }
public void EncodeByteString() { Assert.AreEqual(Encode("4:spam"), BEncoder.Encode(new ByteString("spam"))); }
public void EncodeList() { Assert.AreEqual(Encode("l4:spami42ee"), BEncoder.Encode(ListOf("spam", 42L))); }
public void EncodeInteger() { Assert.AreEqual(Encode("i42e"), BEncoder.Encode(42L)); }