基本信息
源码名称:C#制作的 BT种子生成器 含完整源码下载
源码大小:0.02M
文件格式:.zip
开发语言:C#
更新时间:2013-10-21
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.Text;
namespace BenCode
{
interface IBenCode
{
byte[] ToByteArray();
}
abstract class BenByteString : IBenCode
{
abstract protected byte[] GetByteArray();
public byte[] ToByteArray()
{
List<byte> byteList = new List<byte>();
byte[] byteContent = GetByteArray();
string sizeHeader = string.Format("{0}:", byteContent.Length);
byteList.AddRange(Encoding.UTF8.GetBytes(sizeHeader));
byteList.AddRange(byteContent);
return byteList.ToArray();
}
}
class BenStringFormString : BenByteString, IComparable<BenStringFormString>
{
public BenStringFormString(string value)
{
m_value = value;
}
override protected byte[] GetByteArray()
{
return Encoding.UTF8.GetBytes(m_value);
}
public int CompareTo(BenStringFormString other)
{
return string.CompareOrdinal(m_value, other.m_value);
}
private string m_value;
}
class BenBinaryFormString : BenByteString
{
public BenBinaryFormString(byte[] binaryArray)
{
m_binaryArray = binaryArray;
}
override protected byte[] GetByteArray()
{
return m_binaryArray;
}
private byte[] m_binaryArray;
}
class BenInt : IBenCode
{
public BenInt(long value)
{
m_value = value;
}
public byte[] ToByteArray()
{
string resultInStringForm = string.Format("i{0}e", m_value);
return Encoding.UTF8.GetBytes(resultInStringForm);
}
private long m_value;
}
class BenList : IBenCode
{
public BenList()
{
m_items = new List<IBenCode>();
}
public void Add(IBenCode item)
{
m_items.Add(item);
}
public byte[] ToByteArray()
{
List<byte> byteList = new List<byte>();
byteList.AddRange(Encoding.UTF8.GetBytes("l"));
foreach (IBenCode item in m_items)
{
byteList.AddRange(item.ToByteArray());
}
byteList.AddRange(Encoding.UTF8.GetBytes("e"));
return byteList.ToArray();
}
private List<IBenCode> m_items;
}
class BenDictionary : IBenCode
{
public BenDictionary()
{
m_directionary = new SortedDictionary<BenStringFormString, IBenCode>();
}
public void Add(string key, IBenCode value)
{
BenStringFormString benKey = new BenStringFormString(key);
Add(benKey, value);
}
public void Add(BenStringFormString key, IBenCode value)
{
m_directionary.Add(key, value);
}
public byte[] ToByteArray()
{
List<byte> byteList = new List<byte>();
byteList.AddRange(Encoding.UTF8.GetBytes("d"));
foreach (KeyValuePair<BenStringFormString, IBenCode> entry in m_directionary)
{
byteList.AddRange(entry.Key.ToByteArray());
byteList.AddRange(entry.Value.ToByteArray());
}
byteList.AddRange(Encoding.UTF8.GetBytes("e"));
return byteList.ToArray();
}
private SortedDictionary<BenStringFormString, IBenCode> m_directionary;
}
}