本文整理汇总了C#中BEncodedString类的典型用法代码示例。如果您正苦于以下问题:C# BEncodedString类的具体用法?C# BEncodedString怎么用?C# BEncodedString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BEncodedString类属于命名空间,在下文中一共展示了BEncodedString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnnouncePeer
public AnnouncePeer(NodeId id, NodeId infoHash, BEncodedNumber port, BEncodedString token)
: base(id, QueryName, responseCreator)
{
Parameters.Add(InfoHashKey, infoHash.BencodedString());
Parameters.Add(PortKey, port);
Parameters.Add(TokenKey, token);
}
示例2: Message
protected Message(BEncodedString messageType)
{
properties.Add(TransactionIdKey, null);
properties.Add(MessageTypeKey, messageType);
if (UseVersionKey)
properties.Add(VersionKey, DhtVersion);
}
示例3: CheckContent
private void CheckContent(BEncodedDictionary dict, BEncodedString key, BEncodedNumber value)
{
CheckContent(dict, key);
if (!dict[key].Equals(value))
throw new TorrentException(
string.Format("Invalid FastResume data. The value of '{0}' was '{1}' instead of '{2}'", key,
dict[key], value));
}
示例4: QueryMessage
protected QueryMessage(NodeId id, BEncodedString queryName, BEncodedDictionary queryArguments, ResponseCreator responseCreator)
: base(QueryType)
{
Properties.Add(QueryNameKey, queryName);
Properties.Add(QueryArgumentsKey, queryArguments);
Parameters.Add(IdKey, id.BencodedString());
ResponseCreator = responseCreator;
}
示例5: NextId
public static BEncodedString NextId()
{
lock (Current)
{
var result = new BEncodedString((byte[]) Current.Clone());
if (Current[0]++ == 255)
Current[1]++;
return result;
}
}
示例6: CreateTorrent
private static BEncodedDictionary CreateTorrent(int pieceLength)
{
var infoDict = new BEncodedDictionary();
infoDict[new BEncodedString("piece length")] = new BEncodedNumber(pieceLength);
infoDict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*15]);
infoDict[new BEncodedString("length")] = new BEncodedNumber(15*256*1024 - 1);
infoDict[new BEncodedString("name")] = new BEncodedString("test.files");
var dict = new BEncodedDictionary();
dict[new BEncodedString("info")] = infoDict;
var announceTier = new BEncodedList();
announceTier.Add(new BEncodedString("custom://transfers1/announce"));
announceTier.Add(new BEncodedString("custom://transfers2/announce"));
announceTier.Add(new BEncodedString("http://transfers3/announce"));
var announceList = new BEncodedList();
announceList.Add(announceTier);
dict[new BEncodedString("announce-list")] = announceList;
return dict;
}
示例7: Save
public void Save(IList<ResumeItem> resumeItems)
{
foreach (var keypair in this._originalDictionary)
{
if (keypair.Value is BEncodedDictionary)
{
var dic = (BEncodedDictionary)keypair.Value;
var item = resumeItems.FirstOrDefault(c => c.TorrentName == keypair.Key.Text);
if (item != null)
{
if (dic.ContainsKey("label"))
{
dic["label"] = new BEncodedString(item.Label);
}
else
{
dic.Add("label", new BEncodedString(item.Label));
}
}
}
}
File.WriteAllBytes(this._resumePath, this._originalDictionary.Encode());
}
示例8: benStringEncodingBuffered
public void benStringEncodingBuffered()
{
byte[] data = System.Text.Encoding.UTF8.GetBytes("22:this is my test string");
BEncodedString benString = new BEncodedString("this is my test string");
byte[] result = new byte[benString.LengthInBytes()];
benString.Encode(result, 0);
Assert.IsTrue(Toolbox.ByteMatch(data, result));
}
示例9: benStringEncoding2
public void benStringEncoding2()
{
byte[] data = System.Text.Encoding.UTF8.GetBytes("0:");
BEncodedString benString = new BEncodedString("");
Assert.IsTrue(Toolbox.ByteMatch(data, benString.Encode()));
}
示例10: GetPeersResponse
public GetPeersResponse(NodeId id, BEncodedValue transactionId, BEncodedString token)
: base(id, transactionId)
{
Parameters.Add(TokenKey, token);
}
示例11: AddFiles
private void AddFiles(BEncodedDictionary dict, TorrentFile[] files)
{
long totalSize = piecelength - 1;
var bFiles = new BEncodedList();
for (var i = 0; i < files.Length; i++)
{
var path = new BEncodedList();
foreach (var s in files[i].Path.Split('/'))
path.Add((BEncodedString) s);
var d = new BEncodedDictionary();
d["path"] = path;
d["length"] = (BEncodedNumber) files[i].Length;
bFiles.Add(d);
totalSize += files[i].Length;
}
dict[new BEncodedString("files")] = bFiles;
dict[new BEncodedString("name")] = new BEncodedString("test.files");
dict[new BEncodedString("piece length")] = new BEncodedNumber(piecelength);
dict[new BEncodedString("pieces")] = new BEncodedString(new byte[20*(totalSize/piecelength)]);
}
示例12: SetCustomSecure
public void SetCustomSecure(BEncodedString key, BEncodedValue value)
{
CheckCanEditSecure();
Check.Key(key);
Check.Value(value);
InfoDict[key] = value;
}
示例13: GetDictionary
protected BEncodedDictionary GetDictionary(BEncodedDictionary dictionary, BEncodedString key)
{
// // Required? Probably.
// if (dictionary == InfoDict)
// CheckCanEditSecure ();
BEncodedValue value;
if (dictionary.TryGetValue(key, out value))
return (BEncodedDictionary) value;
return null;
}
示例14: Get
static BEncodedValue Get(BEncodedDictionary dictionary, BEncodedString key)
{
return dictionary.ContainsKey(key) ? dictionary[key] : null;
}
示例15: AddCustom
/// <summary>
/// Adds a custom value to the main bencoded dictionary
/// </summary>
public void AddCustom(BEncodedString key, BEncodedValue value)
{
dict.Add(key, value);
}